2

I am creating a simple micro service using vertx and when i start my server it only create one event thread when available is 12.

My code to start server is

public static void main(String[] args) {
    Vertx vertx = Vertx.vertx();
    int processorCounts = Runtime.getRuntime().availableProcessors();
    DeploymentOptions options = new DeploymentOptions().setInstances(processorCounts);
    vertx.deployVerticle( HttpRouter.class.getName(),options);
}

And my http router looks like this

@Override
public void start() throws Exception {
    super.start();
    Router router = Router.router(vertx);
    router.get("/").handler(event -> {
        event.response().end("Hello World");
    });
    vertx.createHttpServer().requestHandler(router::accept).listen(8001);
}
4
  • This might give you answers: stackoverflow.com/questions/40709931/… Commented Nov 14, 2018 at 20:27
  • @Quintium I have gone through documentation and i m familiar with concept that each verticle by default is on one event thread thats why i set number of instances for a verticle but only one verticle is handling all my requests. Commented Nov 15, 2018 at 5:13
  • It's looking like no different what I have done in tests myself. How you determine it? Looking current thread name in handler code? Commented Nov 16, 2018 at 17:45
  • @Quintium Actually verticles instances are launched but event thread is one so if any verticle block it then no more request is processed. So shall i use rxjava to create new threads or use blockingHandler ? Commented Nov 17, 2018 at 19:09

1 Answer 1

2
+50

What is your process for testing? I assume you opened a browser and hit refresh on the same page. Then yes, the same verticle instance will handle the requests. The reason is Vert.x load balances connections among verticles instances, not requests.

Open a different browser and you should see different event loop names.

Sign up to request clarification or add additional context in comments.

7 Comments

Actually i am getting more clearity on how verticles work. As per my understanding there is only one event thread and that load balances between all verticles because i sleeped thread in one of verticle and it stopped accepting any more request. Is my assumption correct?
NEVER block the event loop!
@LakshayJain No, your assumption is incorrect. There are different event loop threads (by default 2*number of cores). But each verticle is assigned a single event loop. So, when you deploy multiple verticle instances, each instance gets its own event loop. And Vert.x load balances HTTP connections between them.
@tsegismont: You are correct there is one thread blocked for each browser. So how can i resolve this so that each browser use multiple threads?
No thread is "blocked". Browsers use persistent HTTP connections so after you opened a tab the same verticle will handle requests from that page. Your users will use different browsers of course :)
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.