How to use a different named worker pool in same verticle?

151 Views Asked by At

I have one verticle in my service which takes in the http requests and uses executeBlocking to talk to MySQL db. I am using named worker pool to interact with DB. Now, for pushing the application metrics (using a lib. which is blocking) I want to use a different named worker pool. As I don't want the DB operations to be interrupted with metrics so I want to have a separate worker pool. I could use event bus and use a worker verticle to push the metrics but as that has overhead of transformation to the JsonObject, I want to use executeBlocking itself from the same verticle.

As mentioned here https://groups.google.com/d/msg/vertx/eSf3AQagGGU/9m8RizIJeNQJ , the worker pool used in both the cases is same. So, will making a new worker verticle really help me in decoupling the threads used for DB operation and the ones used to push metrics.

Can anyone help me with a better design choice or how can I use a different worker pool if I use the same verticle ?

1

There are 1 best solutions below

0
On

Try the following code (written in Kotlin, but you get the idea):

val workerExecutor1 = vertx.createSharedWorkerExecutor("executor1", 4)
val workerExecutor2 = vertx.createSharedWorkerExecutor("executor2", 4)

workerExecutor1.executeBlocking(...)  // execute your db code here
workerExecutor2.executeBlocking(...)  // execute your metrics code here

Don't forget to close the workerExecutor once it's not needed:

workerExecutor1.close()