Skip Menu |

This queue is for tickets about the POE-Component-Server-HTTP CPAN distribution.

Report information
The Basics
Id: 46938
Status: open
Priority: 0/
Queue: POE-Component-Server-HTTP

People
Owner: Nobody in particular
Requestors: LEEDO [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Wishlist
Broken in: 0.09
Fixed in: (no value)



Subject: long running stream takes 100% CPU
I am using the streaming capabilities in this module and have run into an issue where it is causing 100% CPU usage. These streams are open indefinitely so it is a rather severe problem. It looks my StreamHandler is getting called close to 7500 times per second. I can't use sleep() either, because I have another POE component running as well. I can't seem to find any options for specifying any sort of delay for this. Hopefully I'm just missing something, but if not would it be possible add this option? Thanks
Here is a patch that adds a 'continue_delayed' method to the Response object. It takes an option argument for the number of seconds to delay before executing again. The default delay is 0.5 seconds.
diff -Nuar POE-Component-Server-HTTP-0.09/lib/POE/Component/Server/HTTP/Response.pm POE-Component-Server-HTTP-0.09-delay/lib/POE/Component/Server/HTTP/Response.pm --- POE-Component-Server-HTTP-0.09/lib/POE/Component/Server/HTTP/Response.pm 2006-05-23 15:10:35.000000000 -0500 +++ POE-Component-Server-HTTP-0.09-delay/lib/POE/Component/Server/HTTP/Response.pm 2009-07-09 11:13:33.000000000 -0500 @@ -44,6 +44,13 @@ 'execute' => $self->{connection}->{my_id}); } +sub continue_delayed { + my ($self, $delay) = @_; + $delay = 0.5 unless $delay; + $poe_kernel->post($self->{connection}->{session}, + 'execute_delayed' => $self->{connection}->{my_id}, $delay); +} + sub close { my $self = shift; $self->{streaming} = 0; diff -Nuar POE-Component-Server-HTTP-0.09/lib/POE/Component/Server/HTTP.pm POE-Component-Server-HTTP-0.09-delay/lib/POE/Component/Server/HTTP.pm --- POE-Component-Server-HTTP-0.09/lib/POE/Component/Server/HTTP.pm 2006-05-23 15:45:07.000000000 -0500 +++ POE-Component-Server-HTTP-0.09-delay/lib/POE/Component/Server/HTTP.pm 2009-07-09 11:14:00.000000000 -0500 @@ -93,6 +93,9 @@ accept => \&accept, input => \&input, execute => \&execute, + execute_delayed => sub { + $_[KERNEL]->delay_add('execute', $_[ARG1] || 0.5, $_[ARG0]); + }, error => \&error, shutdown => sub { my ($kernel, $session, $heap) = @_[KERNEL, SESSION, HEAP];