From 56fa5ed7e9e0aceb4504a5bb279fa626d55a5fc0 Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Thu, 31 Jan 2013 15:05:53 -0500 Subject: [PATCH] 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 --- src/perl/lib/OpenSRF/MultiSession.pm | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) 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; } -- 2.11.0