--- Coro/Coro.pm 2007/09/19 21:39:15 1.128 +++ Coro/Coro.pm 2007/09/20 12:02:25 1.130 @@ -161,6 +161,8 @@ my $manager; $manager = new Coro sub { + $current->desc ("[coro manager]"); + while () { (shift @destroy)->_cancel while @destroy; @@ -230,19 +232,23 @@ =cut our $POOL_SIZE = 8; +our $MAX_POOL_RSS = 64 * 1024; our @pool; sub pool_handler { while () { + $current->{desc} = "[async_pool]"; + eval { my ($cb, @arg) = @{ delete $current->{_invoke} or return }; $cb->(@arg); }; warn $@ if $@; - last if @pool >= $POOL_SIZE; - push @pool, $current; + last if @pool >= $POOL_SIZE || $current->rss >= $MAX_POOL_RSS; + push @pool, $current; + $current->{desc} = "[async_pool idle]"; $current->save (Coro::State::SAVE_DEF); $current->prio (0); schedule; @@ -251,11 +257,7 @@ sub async_pool(&@) { # this is also inlined into the unlock_scheduler - my $coro = (pop @pool) || do { - my $coro = new Coro \&pool_handler; - $coro->{desc} = "async_pool"; - $coro - }; + my $coro = (pop @pool) || new Coro \&pool_handler;; $coro->{_invoke} = [@_]; $coro->ready; @@ -532,6 +534,7 @@ # return immediately and can be reused) and because we cannot cede # inside an event callback. our $unblock_scheduler = async { + $current->desc ("[unblock_sub scheduler]"); while () { while (my $cb = pop @unblock_queue) { # this is an inlined copy of async_pool