Over a million developers have joined DZone.

Weaver: Ill-Behaved Microservice Emulator

DZone's Guide to

Weaver: Ill-Behaved Microservice Emulator

The author explains the utility Weaver, his open-source, ill-behaved microservice emulator that's used for testing purposes.

· Performance Zone ·
Free Resource

SignalFx is the only real-time cloud monitoring platform for infrastructure, microservices, and applications. The platform collects metrics and traces across every component in your cloud environment, replacing traditional point tools with a single integrated solution that works across the stack.

Weaver is an open-source, ill-behaved microservice emulator for testing purposes. Microservices are very popular nowadays, and even if you don’t do microservices, you still might be developing some code that communicates with the outer world via HTTP.

There are plenty of opportunities where you might need to quickly set up an HTTP-based service, such as when you want to figure out how your service would integrate in a complex pipeline but you don’t want or cannot setup a testing pipeline; when you want to emulate a negative testing scenario; or when you want to prepare a mixture of correct services with a black sheep among them.

Why would you use Weaver and not implement and start your own testing service when it's so easy with so many libraries out there? Because Weaver allows you to easily configure a mixture of various behaviours by supplying various workers to process requests. For example, when you want to have 100 threads processing your requests, of which 99 would behave correctly and only one would cause a very long delay, or when you want a service that is capable of handling only a given number of requests per second, Weaver offers you a set of predefined behaviors (workers) that you can choose and mix as you want. You can also easily provide your own behaviors. Under the hood, it uses one of the available libraries, Vert.x.

The value added is in the fact that instead of dealing with the lower-level API of Vert.x (or any other library), you can just define the behavior that you need or easily develop your own worker. For example, a worker that emulates processing time looks like this:

  public void work(final RoutingContext context) throws Exception {

     try {
     } catch (InterruptedException e) {
        // nop


Weaver can be used as a standalone command line utility (you can download binaries directly on GitHub) or you can use it through its API as a Maven dependency. For the command line approach, you just provide a configuration file with lines in the following format:

<count>x <worker class>=[<attribute1>:<value1>, ..., <attributeN>:<valueN>]

When you want to emulate a service that takes five milliseconds to process a request running in 100 threads, you would create a configuration file (i.e., delay.cfg) like this...

100x DelayWorker=delay:5

...and simply start Weaver as follows:

$ bin/weaver.sh -c projects/delay.cfg

To see what workers are available, have a look on GitHub in the org.perfcake.examples.weaver.worker package. I originally created Weaver as a utility to be able to demonstrate and detect various flaws of microservices with the performance testing tool PerfCake. In the end, I realized that it can be used in many other cases since it is very flexible. Any pull requests are highly appreciated. I hope you enjoy Weaver and find it useful!

SignalFx is built on a massively scalable streaming architecture that applies advanced predictive analytics for real-time problem detection. With its NoSample™ distributed tracing capabilities, SignalFx reliably monitors all transactions across microservices, accurately identifying all anomalies. And through data-science-powered directed troubleshooting SignalFx guides the operator to find the root cause of issues in seconds.

performance ,weaver ,emulators ,microservices

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}