--- IO-AIO/AIO.pm 2006/10/24 02:25:16 1.67 +++ IO-AIO/AIO.pm 2006/10/24 03:40:38 1.70 @@ -20,6 +20,7 @@ # version 2+ has request and group objects use IO::AIO 2; + aioreq_pri 4; # give next request a very high priority my $req = aio_unlink "/tmp/file", sub { }; $req->cancel; # cancel request if still in queue @@ -61,10 +62,10 @@ and they would only support aio_read and aio_write, so the remaining functionality would have to be implemented using threads anyway. -Although the module will work with in the presence of other threads, it is -currently not reentrant, so use appropriate locking yourself, always call -C from within the same thread, or never call C (or other -C functions) recursively. +Although the module will work with in the presence of other threads, +it is currently not reentrant in any way, so use appropriate locking +yourself, always call C from within the same thread, or never +call C (or other C functions) recursively. =cut @@ -82,7 +83,7 @@ aio_lstat aio_unlink aio_rmdir aio_readdir aio_scandir aio_symlink aio_fsync aio_fdatasync aio_readahead aio_rename aio_link aio_move aio_group aio_nop); - our @EXPORT = (@AIO_REQ, qw(aioreq_pri)); + our @EXPORT = (@AIO_REQ, qw(aioreq_pri aioreq_nice)); our @EXPORT_OK = qw(poll_fileno poll_cb poll_wait flush min_parallel max_parallel max_outstanding nreqs); @@ -125,6 +126,34 @@ =over 4 +=item aioreq_pri $pri + +Sets the priority for the next aio request. The default priority +is C<0>, the minimum and maximum priorities are C<-4> and C<4>, +respectively. Requests with higher priority will be serviced first. + +The priority will be reset to C<0> after each call to one of the C +functions. + +Example: open a file with low priority, then read something from it with +higher priority so the read request is serviced before other low priority +open requests (potentially spamming the cache): + + aioreq_pri -3; + aio_open ..., sub { + return unless $_[0]; + + aioreq_pri -2; + aio_read $_[0], ..., sub { + ... + }; + }; + +=item aioreq_nice $pri_adjust + +Similar to C, but subtracts the given value from the current +priority, so effects are cumulative. + =item aio_open $pathname, $flags, $mode, $callback->($fh) Asynchronously open or create a file and call the callback with a newly @@ -683,12 +712,12 @@ To avoid this, and allow incremental generation of requests, you can instead a group and set a feeder on it that generates those requests. The -feed callback will be called whenever there are few enough (see C, +feed callback will be called whenever there are few enough (see C, below) requests active in the group itself and is expected to queue more requests. -The feed can queue as many requests as it likes (i.e. C does not -impose any limits). +The feed callback can queue as many requests as it likes (i.e. C does +not impose any limits). If the feed does not queue more requests when called, it will be automatically removed from the group. @@ -700,7 +729,7 @@ # stat all files in @files, but only ever use four aio requests concurrently: my $grp = aio_group sub { print "finished\n" }; - feed_limit $grp 4; + limit $grp 4; feed $grp sub { my $file = pop @files or return; @@ -708,7 +737,7 @@ add $grp aio_stat $file, sub { ... }; }; -=item feed_limit $grp $num +=item limit $grp $num Sets the feeder limit for the group: The feeder will be called whenever the group contains less than this many requests. @@ -888,7 +917,7 @@ =head1 SEE ALSO -L, L (obsolete). +L. =head1 AUTHOR