0

I am using vert.x as api gateway and each request has to go through multiple handlers Sample code snippet

router.route(BASE_PATH)
                .method(HttpMethod.POST)
                .handler(LoggerHandler.create(LoggerFormat.SHORT))
                .handler(BodyHandler.create())
                .blockingHandler(this::authRouter)
                .blockingHandler(this::reqValidationRouter)
                .handler(this::downStreamRouter)
                .blockingHandler(this::responseTransformRouter)

What happens to event loop threads when the control passes to blockingHandler? Do they continue to accept more requests? If yes, what happens when the blocking handler execution completes? Does this switching from eventLoop to blockingHandler (workerPool) and then back to eventLoop has any performance implications?

What is the ideal way to handle multiple handlers?

Thanks, Nitish Goyal

Nitish Goyal
  • 97
  • 10

1 Answers1

2

What happens to event loop threads when the control passes to blockingHandler? Do they continue to accept more requests?

Yes, the event loop will offload the blocking handler part to the worker pool and handle other events.

If yes, what happens when the blocking handler execution completes?

An event with the result is added to the event loop queue.

Does this switching from eventLoop to blockingHandler (workerPool) and then back to eventLoop has any performance implications?

Switching between threads is not free but the cost should be negligible in the overall latency for such a use case (api gateway).

What is the ideal way to handle multiple handlers?

Ideally you'd avoid blocking code in your Vert.x Web handlers.

tsegismont
  • 8,591
  • 1
  • 17
  • 27
  • Thanks a lot mate. In my use case above, authRouter is a third party service which I am calling inside blockingHandler. I can wrap this call using vert.x webclient? Or do you have some other recommendations? – Nitish Goyal Sep 03 '20 at 14:38
  • If you invoke the 3rd party service over HTTP then yes you could use the web client and make the blocking a standard route handler. – tsegismont Sep 04 '20 at 08:13