[asio-users] strands and long polling
Brought to you by:
chris_kohlhoff
From: JJ A. <jj....@gm...> - 2010-08-22 21:49:46
|
Hi all, We are using asio in a web application where server "push" is implemented using long-polling. We are using io_service::run on a pool of threads (as demonstrated in HTTP server example 3). As in the example we are associating a strand with each inbound connection which it services. We have recently run into an issue where when two requests arrive nearly simultaneously it is possible that one can tie up the other and cause it to block until the first one completes. We speculated that this may be due to the use of strands, removed them, and the problem was no longer reproducible. I subsequently noted that this issue was also previously discussed on this list here: http://comments.gmane.org/gmane.comp.lib.boost.asio.user/3945 Christopher suggests in this thread that the long-polling be moved off of the strand using io_service.post. While we can certainly do this, I was wondering whether it was even necessary to use strands in the first place since the implementation only has a single IO operation pending at a time (a series of calls to async_read_some followed by an async_write). See: http://www.boost.org/doc/libs/1_44_0/doc/html/boost_asio/example/http/server3/connection.cpp It seems like we'd be OK without the strand since another aysnc_read_some isn't posted until the previous one has completed. Perhaps the strand was included in the example by way of illustration but isn't strictly necessary? Of course, I may be missing the logic, purpose, and workings of strands, threads, and io services entirely :-) Would be curious as to what others think the right approach is here. Thanks, J.J. |