Implement AsyncContext notification stream

Here's the script:

  • A typical application for web pushes / comets, where short messages should be simultaneously pressed on 3000-4000 connected users;
  • Transition from 1 stream / connection model to a new implementation using Servlet 3.0 ( AsyncContext ) on Tomcat 7;

One thing, I need help to understand what is the best / secure aproach in implementing the notifier mechanism.

The easiest way is a standard example: 1 thread waits for a new message, then AsyncContext through the AsyncContext list and calls aCtx.getResponse().getWriter().print(message) for each.

Now my concern is what happens when there are slow clients connected (and given that we can have 1000, this will always be so). Can the notification flow be blocked or spend too much time waiting for these slow clients and affecting everyone? This may be trivial, but for me it is not clear if the "write" is asynchronous or blocked, or if the output buffers compensate for this to at least one point.

Or is it better to create a Runnable for each connected client (which will do aCtx.getResponse().getWriter().print(message) ) and send it to Executor using a fixed thread pool? I'm not sure, however, if the creation allows you to say that 4000 Runnable at a time (for each message) makes sense or what will be the performance.

And the last one, who has real / production experience using Tomcat 7 for such an application (asynch servlet)? Should I take it that “production is ready in this area? Thanks.

+6
source share

Source: https://habr.com/ru/post/900827/


All Articles