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.75 by root, Tue Oct 24 20:10:26 2006 UTC vs.
Revision 1.79 by root, Thu Oct 26 14:35:34 2006 UTC

134 aio_lstat aio_unlink aio_rmdir aio_readdir aio_scandir aio_symlink 134 aio_lstat aio_unlink aio_rmdir aio_readdir aio_scandir aio_symlink
135 aio_fsync aio_fdatasync aio_readahead aio_rename aio_link aio_move 135 aio_fsync aio_fdatasync aio_readahead aio_rename aio_link aio_move
136 aio_group aio_nop); 136 aio_group aio_nop);
137 our @EXPORT = (@AIO_REQ, qw(aioreq_pri aioreq_nice)); 137 our @EXPORT = (@AIO_REQ, qw(aioreq_pri aioreq_nice));
138 our @EXPORT_OK = qw(poll_fileno poll_cb poll_wait flush 138 our @EXPORT_OK = qw(poll_fileno poll_cb poll_wait flush
139 min_parallel max_parallel max_outstanding nreqs); 139 min_parallel max_parallel nreqs);
140 140
141 @IO::AIO::GRP::ISA = 'IO::AIO::REQ'; 141 @IO::AIO::GRP::ISA = 'IO::AIO::REQ';
142 142
143 require XSLoader; 143 require XSLoader;
144 XSLoader::load ("IO::AIO", $VERSION); 144 XSLoader::load ("IO::AIO", $VERSION);
426with the filenames. 426with the filenames.
427 427
428=item aio_scandir $path, $maxreq, $callback->($dirs, $nondirs) 428=item aio_scandir $path, $maxreq, $callback->($dirs, $nondirs)
429 429
430Scans a directory (similar to C<aio_readdir>) but additionally tries to 430Scans a directory (similar to C<aio_readdir>) but additionally tries to
431separate the entries of directory C<$path> into two sets of names, ones 431efficiently separate the entries of directory C<$path> into two sets of
432you can recurse into (directories or links to them), and ones you cannot 432names, directories you can recurse into (directories), and ones you cannot
433recurse into (everything else). 433recurse into (everything else, including symlinks to directories).
434 434
435C<aio_scandir> is a composite request that creates of many sub requests_ 435C<aio_scandir> is a composite request that creates of many sub requests_
436C<$maxreq> specifies the maximum number of outstanding aio requests that 436C<$maxreq> specifies the maximum number of outstanding aio requests that
437this function generates. If it is C<< <= 0 >>, then a suitable default 437this function generates. If it is C<< <= 0 >>, then a suitable default
438will be chosen (currently 6). 438will be chosen (currently 6).
682=item * They can also can also be added to other IO::AIO::GRP objects. 682=item * They can also can also be added to other IO::AIO::GRP objects.
683 683
684=item * You must not add requests to a group from within the group callback (or 684=item * You must not add requests to a group from within the group callback (or
685any later time). 685any later time).
686 686
687=item * This does not harmonise well with C<max_outstanding>, so best do
688not combine C<aio_group> with it. Groups and feeders are recommended for
689this kind of concurrency-limiting.
690
691=back 687=back
692 688
693Their lifetime, simplified, looks like this: when they are empty, they 689Their lifetime, simplified, looks like this: when they are empty, they
694will finish very quickly. If they contain only requests that are in the 690will finish very quickly. If they contain only requests that are in the
695C<done> state, they will also finish. Otherwise they will continue to 691C<done> state, they will also finish. Otherwise they will continue to
784 780
785Process all outstanding events on the result pipe. You have to call this 781Process all outstanding events on the result pipe. You have to call this
786regularly. Returns the number of events processed. Returns immediately 782regularly. Returns the number of events processed. Returns immediately
787when no events are outstanding. 783when no events are outstanding.
788 784
785If not all requests were processed for whatever reason, the filehandle
786will still be ready when C<poll_cb> returns.
787
789Example: Install an Event watcher that automatically calls 788Example: Install an Event watcher that automatically calls
790IO::AIO::poll_cb with high priority: 789IO::AIO::poll_cb with high priority:
791 790
792 Event->io (fd => IO::AIO::poll_fileno, 791 Event->io (fd => IO::AIO::poll_fileno,
793 poll => 'r', async => 1, 792 poll => 'r', async => 1,
794 cb => \&IO::AIO::poll_cb); 793 cb => \&IO::AIO::poll_cb);
794
795=item IO::AIO::poll_some $max_requests
796
797Similar to C<poll_cb>, but only processes up to C<$max_requests> requests
798at a time.
799
800Useful if you want to ensure some level of interactiveness when perl is
801not fast enough to process all requests in time.
802
803Example: Install an Event watcher that automatically calls
804IO::AIO::poll_some with low priority, to ensure that other parts of the
805program get the CPU sometimes even under high AIO load.
806
807 Event->io (fd => IO::AIO::poll_fileno,
808 poll => 'r', nice => 1,
809 cb => sub { IO::AIO::poll_some 256 });
795 810
796=item IO::AIO::poll_wait 811=item IO::AIO::poll_wait
797 812
798Wait till the result filehandle becomes ready for reading (simply does a 813Wait till the result filehandle becomes ready for reading (simply does a
799C<select> on the filehandle. This is useful if you want to synchronously wait 814C<select> on the filehandle. This is useful if you want to synchronously wait
859This module automatically runs C<max_parallel 0> at program end, to ensure 874This module automatically runs C<max_parallel 0> at program end, to ensure
860that all threads are killed and that there are no outstanding requests. 875that all threads are killed and that there are no outstanding requests.
861 876
862Under normal circumstances you don't need to call this function. 877Under normal circumstances you don't need to call this function.
863 878
864=item $oldnreqs = IO::AIO::max_outstanding $nreqs 879=item $oldmaxreqs = IO::AIO::max_outstanding $maxreqs
865 880
866[DEPRECATED] 881This is a very bad function to use in interactive programs because it
882blocks, and a bad way to reduce concurrency because it is inexact: Better
883use an C<aio_group> together with a feed callback.
867 884
868Sets the maximum number of outstanding requests to C<$nreqs>. If you 885Sets the maximum number of outstanding requests to C<$nreqs>. If you
869try to queue up more than this number of requests, the caller will block until 886to queue up more than this number of requests, the next call to the
870some requests have been handled. 887C<poll_cb> (and C<poll_some> and other functions calling C<poll_cb>)
888function will block until the limit is no longer exceeded.
871 889
872The default is very large, so normally there is no practical limit. If you 890The default value is very large, so there is no practical limit on the
873queue up many requests in a loop it often improves speed if you set 891number of outstanding requests.
874this to a relatively low number, such as C<100>.
875 892
876This function does not work well together with C<aio_group>'s, and their 893You can still queue as many requests as you want. Therefore,
877feeder interface is better suited to limiting concurrency, so do not use 894C<max_oustsanding> is mainly useful in simple scripts (with low values) or
878this function. 895as a stop gap to shield against fatal memory overflow (with large values).
879
880Under normal circumstances you don't need to call this function.
881 896
882=back 897=back
883 898
884=cut 899=cut
885 900

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines