ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/AnyEvent-Fork-Pool/Pool.pm
(Generate patch)

Comparing AnyEvent-Fork-Pool/Pool.pm (file contents):
Revision 1.6 by root, Sun Apr 21 11:17:02 2013 UTC vs.
Revision 1.8 by root, Sun Apr 21 12:28:34 2013 UTC

1=head1 NAME 1=head1 NAME
2 2
3AnyEvent::Fork::Pool - simple process pool manager on top of AnyEvent::Fork 3AnyEvent::Fork::Pool - simple process pool manager on top of AnyEvent::Fork
4
5THE API IS NOT FINISHED, CONSIDER THIS AN ALPHA RELEASE
4 6
5=head1 SYNOPSIS 7=head1 SYNOPSIS
6 8
7 use AnyEvent; 9 use AnyEvent;
8 use AnyEvent::Fork::Pool; 10 use AnyEvent::Fork::Pool;
328 $proc->[0] 330 $proc->[0]
329 or --$nidle; 331 or --$nidle;
330 332
331 Array::Heap::splice_heap_idx @pool, $proc->[1] 333 Array::Heap::splice_heap_idx @pool, $proc->[1]
332 if defined $proc->[1]; 334 if defined $proc->[1];
335
336 @$proc = 0; # tell others to leave it be
333 }; 337 };
334 338
335 $want_start = sub { 339 $want_start = sub {
336 undef $stop_w; 340 undef $stop_w;
337 341
356 }; 360 };
357 361
358 $scheduler = sub { 362 $scheduler = sub {
359 if (@queue) { 363 if (@queue) {
360 while (@queue) { 364 while (@queue) {
365 @pool or $start_worker->();
366
361 my $proc = $pool[0]; 367 my $proc = $pool[0];
362 368
363 if ($proc->[0] < $load) { 369 if ($proc->[0] < $load) {
364 # found free worker, increase load 370 # found free worker, increase load
365 unless ($proc->[0]++) { 371 unless ($proc->[0]++) {
383 or $want_stop->(); 389 or $want_stop->();
384 390
385 Array::Heap::adjust_heap_idx @pool, $proc->[1] 391 Array::Heap::adjust_heap_idx @pool, $proc->[1]
386 if defined $proc->[1]; 392 if defined $proc->[1];
387 393
394 &$ocb;
395
388 $scheduler->(); 396 $scheduler->();
389
390 &$ocb;
391 }); 397 });
392 } else { 398 } else {
393 $want_start->() 399 $want_start->()
394 unless @pool >= $max; 400 unless @pool >= $max;
395 401
513having only one worker is best, for example, when you read or write big 519having only one worker is best, for example, when you read or write big
514files at maixmum speed, as a second worker will increase seek times. 520files at maixmum speed, as a second worker will increase seek times.
515 521
516=back 522=back
517 523
524=head1 EXCEPTIONS
525
526The same "policy" as with L<AnyEvent::Fork::RPC> applies - exceptins will
527not be caught, and exceptions in both worker and in callbacks causes
528undesirable or undefined behaviour.
529
518=head1 SEE ALSO 530=head1 SEE ALSO
519 531
520L<AnyEvent::Fork>, to create the processes in the first place. 532L<AnyEvent::Fork>, to create the processes in the first place.
521 533
522L<AnyEvent::Fork::RPC>, which implements the RPC protocol and API. 534L<AnyEvent::Fork::RPC>, which implements the RPC protocol and API.

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines