I want my vertx application to use multiple threads ( multiple event loops ) to take advantage of multiple cores and handles requests more optimally. Hence, I have deployed multiple instances of the server init verticle.
But it doesn't seem like it is using separate event loops to handle concurrent requests.
App.java
__________
package org.example;
import io.vertx.core.DeploymentOptions;
import io.vertx.core.Vertx;
import io.vertx.ext.web.Router;
public class App
{
public static void main(String[] args)
{
Vertx vertx = Vertx.vertx();
vertx.deployVerticle("org.example.ServerVertcle",new DeploymentOptions().setInstances(8));
}
}
ServerVertcle.java
____________________
package org.example;
import io.vertx.core.AbstractVerticle;
import io.vertx.ext.web.Router;
public class ServerVertcle extends AbstractVerticle {
public void start() {
Router router = Router.router(vertx);
router.route("/api").blockingHandler(ctx -> {
System.out.println("Started at : "+System.currentTimeMillis());
try {Thread.sleep(5000); } catch (Exception e) {e.printStackTrace();}
System.out.println("After timeout : "+System.currentTimeMillis());
ctx.end("Hello World");
});
vertx.createHttpServer().requestHandler(router).listen(8000).onSuccess(server -> {
System.out.println("Server Started in thread: "+Thread.currentThread().getName());
});
}
public void stop() {}
}
output:
Started at : 1667678335486
After timeout : 1667678340486
Started at : 1667678340496
After timeout : 1667678345496
Started at : 1667678345500
After timeout : 1667678350500
I have concurrently triggered 3 get requests to the /api endpoint and it seems that each request is handled sequentially and not concurrently. how can I change this behaviour to take advantage of the multi-reactor pattern ?