Reputation: 13
I want to benchmark my Restful API Server, so I send a ton of request to it to measure throughput and latency. I use Vert.x WebClient
to create a client.
First, I create BenchmarkVerticle
extends from AbstractVerticle
and create a WebClient
in start
method.
public class BenchmarkVerticle extends AbstractVerticle {
@Override
public void start(Future<Void> future) {
WebClient client = WebClient.create(vertx);
while (true) {
// warm up in 10s and benchmark in 20s by sending requests
client.post(Server.port, "localhost", "/api")
.send(ar -> {
// do something after receiving response
});
}
}
}
And then I deploy BenchmarkVerticle
in main
public static void main(String[] args) {
VertxOptions options = new VertxOptions();
options.setBlockedThreadCheckInterval(1000*60*60); // make BlockedThreadChecker not show
options.setWorkerPoolSize(40);
Vertx vertx = Vertx.vertx(options);
DeploymentOptions doptions = new DeploymentOptions()
.setWorker(true);
vertx.deployVerticle(new BenchmarkVerticle(), doptions);
}
I find that request are only sent when start
method finished. I think each request is put in a queue to execute after method start
complete. It affects to my benchmark result. I try using multithreading by setMultiThreaded(true)
in DeploymentOptions
object to make it send concurrently but it says:
java.lang.IllegalStateException: Cannot use HttpClient in a multi-threaded worker verticle
So how to make request send immediately in WebClient? NOTE: English is not my native language. I will expain more detailed if you feel hard to understand.
Upvotes: 1
Views: 737
Reputation: 3569
i'm not sure i understand the setup. BenchmarkVerticle
seems useless, unless it has more logic that you haven't revealed to in your post.
BenchmarkVerticle
is responsible for handing requests
WebClient
references from this classfuture.complete()
at the end of the body of start()
then...
in the class that has the main()
method
WebClient
heredeployVerticle
that allows your to supply a completionHandler:deployVerticle(String name, DeploymentOptions options, Handler> completionHandler)
the completion handler is called when your Verticle(s) are finally deployed. add your request + response handling inside this handler.
Upvotes: 1