Here's the scenario:
- typical web push/comet application where short messages must be pushed at the same time to 3000-4000 connected users;
- moving from 1 thread/connection model to a new implementation using Servlet 3.0 (
AsyncContext
) on Tomcat 7;
One thing I need help to understand is what's the best/safest aproach in implementing the 'notifier' mechanism.
The simplest way is the standard example: 1 thread waiting for a new message and then looping the AsyncContext
s list and calling aCtx.getResponse().getWriter().print(message)
for each.
Now, my concern is what happens when there are slow clients connected (and considering we may have 1000s this will always be the case). Could the notifier thread be blocked or waste too much time waiting on these slow clients and affecting everybody? This may be trivial but it's not clear for me if the 'write' is asynch or blocking or if the output buffers would compensate for this at least up to a point.
Or is it better to create for each connected client a Runnable
(that would do the aCtx.getResponse().getWriter().print(message)
) and submit it to an Executor
using a fixed thread pool? I'm not sure however if creating let's say 4000 Runnable
at a time (for each message) makes sense or what the performance would be.
And one last thing, does anyone have real/production experience using Tomcat 7 for this sort of app (asynch servlet)? Should i consider it 'production ready in this area? Thanks.