… | |
… | |
230 | terminate }> once per second or so to slowly replenish the pool. |
230 | terminate }> once per second or so to slowly replenish the pool. |
231 | |
231 | |
232 | =cut |
232 | =cut |
233 | |
233 | |
234 | our $POOL_SIZE = 8; |
234 | our $POOL_SIZE = 8; |
|
|
235 | our $MAX_POOL_RSS = 64 * 1024; |
235 | our @pool; |
236 | our @pool; |
236 | |
237 | |
237 | sub pool_handler { |
238 | sub pool_handler { |
238 | while () { |
239 | while () { |
239 | $current->{desc} = "[async_pool]"; |
240 | $current->{desc} = "[async_pool]"; |
… | |
… | |
242 | my ($cb, @arg) = @{ delete $current->{_invoke} or return }; |
243 | my ($cb, @arg) = @{ delete $current->{_invoke} or return }; |
243 | $cb->(@arg); |
244 | $cb->(@arg); |
244 | }; |
245 | }; |
245 | warn $@ if $@; |
246 | warn $@ if $@; |
246 | |
247 | |
247 | last if @pool >= $POOL_SIZE; |
248 | last if @pool >= $POOL_SIZE || $current->rss >= $MAX_POOL_RSS; |
248 | |
249 | |
249 | push @pool, $current; |
250 | push @pool, $current; |
250 | $current->{desc} = "[async_pool idle]"; |
251 | $current->{desc} = "[async_pool idle]"; |
251 | $current->save (Coro::State::SAVE_DEF); |
252 | $current->save (Coro::State::SAVE_DEF); |
252 | $current->prio (0); |
253 | $current->prio (0); |