Can I set a capacity on the Vert.x HTTP request queue?

十年热恋 提交于 2019-12-06 03:05:26

AFAIK there's no built-in way to accomplish this. However, this type of back pressure should still be achievable by normal means. The approach you take is this:

  • When an HTTP requests is received, immediately forward the request via a message to a separate request handling verticle on the event bus and increment an outstanding request counter.

  • Perform request handling logic in that verticle and respond to the event bus message once complete.

  • Once the HTTP server verticle receives a response from the request handler verticle, decrement the request counter and send the appropriate response.

  • Add a request counter check to your HTTP server handler to check the outstanding request count and respond with an appropriate error if the queue grows too large.

This is a common pattern in Vert.x that essentially just separates request handling logic from the HTTP request handler. Forwarding the request on the event bus as a JsonObject ensures that requests are quickly queued in the event bus. You an use that queue to calculate the number of outstanding requests as I've shown.

Note also that you can scale your HTTP server across multiple verticle instances in order to handle more requests. In this case you can either use static variables or shared data to share a semaphore across the instances.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!