From: Bill Erickson Date: Thu, 31 Jan 2013 20:05:53 +0000 (-0500) Subject: Block on recv instead of loop/polling in MultiSession X-Git-Tag: osrf_rel_2_2_0-alpha~10 X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=56fa5ed7e9e0aceb4504a5bb279fa626d55a5fc0;p=OpenSRF.git Block on recv instead of loop/polling in MultiSession When the time comes to wait for responses to arrive, block on the XMPP socket (which uses select() under the covers) until data arrives, instead of looping furiously and calling receive in non-blocking mode. Before this change, waiting on responses resulted in long-running CPU spikes. Signed-off-by: Bill Erickson Signed-off-by: Lebbeous Fogle-Weekley --- diff --git a/src/perl/lib/OpenSRF/MultiSession.pm b/src/perl/lib/OpenSRF/MultiSession.pm index dd0579c..e196027 100644 --- a/src/perl/lib/OpenSRF/MultiSession.pm +++ b/src/perl/lib/OpenSRF/MultiSession.pm @@ -215,17 +215,21 @@ sub request { sub session_wait { my $self = shift; my $all = shift; + my $xmpp = OpenSRF::Transport::PeerHandle->retrieve; my $count; if ($all) { $count = $self->running; while ($self->running) { + # block on the xmpp socket until data arrives + $xmpp->process(-1); $self->session_reap; } return $count; } else { while(($count = $self->session_reap) == 0 && $self->running) { - usleep 100; + # block on the xmpp socket until data arrives + $xmpp->process(-1); } return $count; }