ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/IO-AIO/AIO.pm
(Generate patch)

Comparing IO-AIO/AIO.pm (file contents):
Revision 1.63 by root, Mon Oct 23 00:34:36 2006 UTC vs.
Revision 1.65 by root, Mon Oct 23 14:49:51 2006 UTC

540This is a special request - it does nothing in itself and is only used for 540This is a special request - it does nothing in itself and is only used for
541side effects, such as when you want to add a dummy request to a group so 541side effects, such as when you want to add a dummy request to a group so
542that finishing the requests in the group depends on executing the given 542that finishing the requests in the group depends on executing the given
543code. 543code.
544 544
545While this request does nothing, it still goes through the execution
546phase and still requires a worker thread. Thus, the callback will not
547be executed immediately but only after other requests in the queue have
548entered their execution phase. This can be used to measure request
549latency.
550
545=item IO::AIO::aio_sleep $fractional_seconds, $callback->() *NOT EXPORTED* 551=item IO::AIO::aio_sleep $fractional_seconds, $callback->() *NOT EXPORTED*
546 552
547Mainly used for debugging and benchmarking, this aio request puts one of 553Mainly used for debugging and benchmarking, this aio request puts one of
548the request workers to sleep for the given time. 554the request workers to sleep for the given time.
549 555
567callback) and B<done> (request has reached the end of its lifetime and 573callback) and B<done> (request has reached the end of its lifetime and
568holds no resources anymore). 574holds no resources anymore).
569 575
570=over 4 576=over 4
571 577
572=item $req->cancel 578=item cancel $req
573 579
574Cancels the request, if possible. Has the effect of skipping execution 580Cancels the request, if possible. Has the effect of skipping execution
575when entering the B<execute> state and skipping calling the callback when 581when entering the B<execute> state and skipping calling the callback when
576entering the the B<result> state, but will leave the request otherwise 582entering the the B<result> state, but will leave the request otherwise
577untouched. That means that requests that currently execute will not be 583untouched. That means that requests that currently execute will not be
578stopped and resources held by the request will not be freed prematurely. 584stopped and resources held by the request will not be freed prematurely.
579 585
586=item cb $req $callback->(...)
587
588Replace (or simply set) the callback registered to the request.
589
580=back 590=back
581 591
582=head2 IO::AIO::GRP CLASS 592=head2 IO::AIO::GRP CLASS
583 593
584This class is a subclass of L<IO::AIO::REQ>, so all its methods apply to 594This class is a subclass of L<IO::AIO::REQ>, so all its methods apply to
641group. And only when all those requests have finished will the the group 651group. And only when all those requests have finished will the the group
642itself finish. 652itself finish.
643 653
644=over 4 654=over 4
645 655
656=item add $grp ...
657
646=item $grp->add (...) 658=item $grp->add (...)
647
648=item add $grp ...
649 659
650Add one or more requests to the group. Any type of L<IO::AIO::REQ> can 660Add one or more requests to the group. Any type of L<IO::AIO::REQ> can
651be added, including other groups, as long as you do not create circular 661be added, including other groups, as long as you do not create circular
652dependencies. 662dependencies.
653 663
656=item $grp->result (...) 666=item $grp->result (...)
657 667
658Set the result value(s) that will be passed to the group callback when all 668Set the result value(s) that will be passed to the group callback when all
659subrequests have finished. By default, no argument will be passed. 669subrequests have finished. By default, no argument will be passed.
660 670
661=item $grp->set_feeder ($callback->($grp)) 671=item feed $grp $callback->($grp)
662 672
663[VERY EXPERIMENTAL] 673[VERY EXPERIMENTAL]
664 674
665Sets a feeder/generator on this group: every group can have an attached 675Sets a feeder/generator on this group: every group can have an attached
666generator that generates requests if idle. The idea behind this is that, 676generator that generates requests if idle. The idea behind this is that,
669example, C<aio_scandir> might generate hundreds of thousands C<aio_stat> 679example, C<aio_scandir> might generate hundreds of thousands C<aio_stat>
670requests, delaying any later requests for a long time. 680requests, delaying any later requests for a long time.
671 681
672To avoid this, and allow incremental generation of requests, you can 682To avoid this, and allow incremental generation of requests, you can
673instead a group and set a feeder on it that generates those requests. The 683instead a group and set a feeder on it that generates those requests. The
674feeder will be called whenever there are few enough (see C<feeder_limit>, 684feed callback will be called whenever there are few enough (see C<feed_limit>,
675below) requests active in the group itself and is expected to queue more 685below) requests active in the group itself and is expected to queue more
676requests. 686requests.
677 687
678The feeder can queue as many requests as it likes (i.e. C<add> does not 688The feed can queue as many requests as it likes (i.e. C<add> does not
679impose any limits). 689impose any limits).
680 690
681If the feeder does not queue more requests when called, it will be 691If the feed does not queue more requests when called, it will be
682automatically removed from the group. 692automatically removed from the group.
683 693
684If the feeder limit is C<0>, it will be set to C<2> automatically. 694If the feed limit is C<0>, it will be set to C<2> automatically.
685 695
686Example: 696Example:
687 697
688 # stat all files in @files, but only ever use four aio requests concurrently: 698 # stat all files in @files, but only ever use four aio requests concurrently:
689 699
690 my $grp = aio_group sub { print "finished\n" }; 700 my $grp = aio_group sub { print "finished\n" };
691 $grp->feeder_limit (4); 701 feed_limit $grp 4;
692 $grp->set_feeder (sub { 702 feed $grp sub {
693 my $file = pop @files 703 my $file = pop @files
694 or return; 704 or return;
695 705
696 add $grp aio_stat $file, sub { ... }; 706 add $grp aio_stat $file, sub { ... };
697 }); 707 };
698 708
699=item $grp->feeder_limit ($num) 709=item feed_limit $grp $num
700 710
701Sets the feeder limit for the group: The feeder will be called whenever 711Sets the feeder limit for the group: The feeder will be called whenever
702the group contains less than this many requests. 712the group contains less than this many requests.
703 713
704Setting the limit to C<0> will pause the feeding process. 714Setting the limit to C<0> will pause the feeding process.

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines