Subject: | recv loop needs to break out after some number of iterations |
If data is arriving fast enough the recv loop will starve the rest of
POE (the exact definition of "fast enough" depends on your environment).
As a result input events stack up in POE event queue.
Being stuck in the recv loop POE will seldom get a timeslice for
anything other than reading data. POEs event queue will grow until the
app runs out of memory (or the data rate slows).
Periodically breaking out of the loop (even if there may be additional
data) allows pending input events to be serviced.
The basic change is:
my $cnt = 25;
while( $addr = recv(...) ) {
...
$poe_kernel->yield( ... input_event ...);
last unless --$cnt > 0;
}
There is nothing special about 25. It is just a number that works well
for me. Something bigger than 1 is generally a good thing for high data
rates since this will save on unneeded calls to select (call it select
loop unrolling ;-).