Search code examples
javascalaasynchronousvert.xevent-loop

Vert.x IO Blocking operation performance


I'm trying to run a blocking code, like Thread.sleep(100) to simulate a heavy database, with a Vert.x 1000 Worker pool size.

val options = DeploymentOptions().setWorker(true).setWorkerPoolSize(1000);
vertx.deployVerticle(new DataBase, options)

vertx.eventBus().consumer("anAddress").handler((message: Message[String]) => {
  Thread.sleep(100)
  val lines = "teste do joca"
  message.reply(lines)
})

But looking at a Jmeter http test, I got only 10.1/sec Throughput.

How could I increase this performance without breaking the eventloop?

Thanks to advance!


Solution

  • Worker verticles handle events on worker threads but a single instance can only handle one event at a given point in time. So you shall deploy as many instances as worker threads if you want to leverage all of them:

    val options = DeploymentOptions()
      .setWorker(true)
      .setInstances(1000)
      .setWorkerPoolSize(1000);
    vertx.deployVerticle(() -> new DataBase(), options);
    

    Note that deploy here takes a Supplier instead of single verticle instance.