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.87 by root, Sun Oct 29 00:52:02 2006 UTC vs.
Revision 1.90 by root, Mon Oct 30 23:30:00 2006 UTC

61etc.), but can also be used to easily do operations in parallel that are 61etc.), but can also be used to easily do operations in parallel that are
62normally done sequentially, e.g. stat'ing many files, which is much faster 62normally done sequentially, e.g. stat'ing many files, which is much faster
63on a RAID volume or over NFS when you do a number of stat operations 63on a RAID volume or over NFS when you do a number of stat operations
64concurrently. 64concurrently.
65 65
66While this works on all types of file descriptors (for example sockets), 66While most of this works on all types of file descriptors (for example
67using these functions on file descriptors that support nonblocking 67sockets), using these functions on file descriptors that support
68operation (again, sockets, pipes etc.) is very inefficient. Use an event 68nonblocking operation (again, sockets, pipes etc.) is very inefficient or
69might not work (aio_read fails on sockets/pipes/fifos). Use an event loop
69loop for that (such as the L<Event|Event> module): IO::AIO will naturally 70for that (such as the L<Event|Event> module): IO::AIO will naturally fit
70fit into such an event loop itself. 71into such an event loop itself.
71 72
72In this version, a number of threads are started that execute your 73In this version, a number of threads are started that execute your
73requests and signal their completion. You don't need thread support 74requests and signal their completion. You don't need thread support
74in perl, and the threads created by this module will not be visible 75in perl, and the threads created by this module will not be visible
75to perl. In the future, this module might make use of the native aio 76to perl. In the future, this module might make use of the native aio
176Request has reached the end of its lifetime and holds no resources anymore 177Request has reached the end of its lifetime and holds no resources anymore
177(except possibly for the Perl object, but its connection to the actual 178(except possibly for the Perl object, but its connection to the actual
178aio request is severed and calling its methods will either do nothing or 179aio request is severed and calling its methods will either do nothing or
179result in a runtime error). 180result in a runtime error).
180 181
182=back
183
181=cut 184=cut
182 185
183package IO::AIO; 186package IO::AIO;
184 187
185no warnings; 188no warnings;
190BEGIN { 193BEGIN {
191 our $VERSION = '2.1'; 194 our $VERSION = '2.1';
192 195
193 our @AIO_REQ = qw(aio_sendfile aio_read aio_write aio_open aio_close aio_stat 196 our @AIO_REQ = qw(aio_sendfile aio_read aio_write aio_open aio_close aio_stat
194 aio_lstat aio_unlink aio_rmdir aio_readdir aio_scandir aio_symlink 197 aio_lstat aio_unlink aio_rmdir aio_readdir aio_scandir aio_symlink
195 aio_fsync aio_fdatasync aio_readahead aio_rename aio_link aio_move 198 aio_readlink aio_fsync aio_fdatasync aio_readahead aio_rename aio_link
196 aio_copy aio_group aio_nop aio_mknod); 199 aio_move aio_copy aio_group aio_nop aio_mknod);
197 our @EXPORT = (@AIO_REQ, qw(aioreq_pri aioreq_nice)); 200 our @EXPORT = (@AIO_REQ, qw(aioreq_pri aioreq_nice));
198 our @EXPORT_OK = qw(poll_fileno poll_cb poll_wait flush 201 our @EXPORT_OK = qw(poll_fileno poll_cb poll_wait flush
199 min_parallel max_parallel max_idle 202 min_parallel max_parallel max_idle
200 nreqs nready npending nthreads 203 nreqs nready npending nthreads
201 max_poll_time max_poll_reqs); 204 max_poll_time max_poll_reqs);
414 417
415=item aio_symlink $srcpath, $dstpath, $callback->($status) 418=item aio_symlink $srcpath, $dstpath, $callback->($status)
416 419
417Asynchronously create a new symbolic link to the existing object at C<$srcpath> at 420Asynchronously create a new symbolic link to the existing object at C<$srcpath> at
418the path C<$dstpath> and call the callback with the result code. 421the path C<$dstpath> and call the callback with the result code.
422
423=item aio_readlink $path, $callback->($link)
424
425Asynchronously read the symlink specified by C<$path> and pass it to
426the callback. If an error occurs, nothing or undef gets passed to the
427callback.
419 428
420=item aio_rename $srcpath, $dstpath, $callback->($status) 429=item aio_rename $srcpath, $dstpath, $callback->($status)
421 430
422Asynchronously rename the object at C<$srcpath> to C<$dstpath>, just as 431Asynchronously rename the object at C<$srcpath> to C<$dstpath>, just as
423rename(2) and call the callback with the result code. 432rename(2) and call the callback with the result code.
937that are being processed by C<IO::AIO::poll_cb> in one call, respectively 946that are being processed by C<IO::AIO::poll_cb> in one call, respectively
938the maximum amount of time (default C<0>, meaning infinity) spent in 947the maximum amount of time (default C<0>, meaning infinity) spent in
939C<IO::AIO::poll_cb> to process requests (more correctly the mininum amount 948C<IO::AIO::poll_cb> to process requests (more correctly the mininum amount
940of time C<poll_cb> is allowed to use). 949of time C<poll_cb> is allowed to use).
941 950
951Setting C<max_poll_time> to a non-zero value creates an overhead of one
952syscall per request processed, which is not normally a problem unless your
953callbacks are really really fast or your OS is really really slow (I am
954not mentioning Solaris here). Using C<max_poll_reqs> incurs no overhead.
955
942Setting these is useful if you want to ensure some level of 956Setting these is useful if you want to ensure some level of
943interactiveness when perl is not fast enough to process all requests in 957interactiveness when perl is not fast enough to process all requests in
944time. 958time.
945 959
946For interactive programs, values such as C<0.01> to C<0.1> should be fine. 960For interactive programs, values such as C<0.01> to C<0.1> should be fine.
947 961
948Example: Install an Event watcher that automatically calls 962Example: Install an Event watcher that automatically calls
949IO::AIO::poll_some with low priority, to ensure that other parts of the 963IO::AIO::poll_cb with low priority, to ensure that other parts of the
950program get the CPU sometimes even under high AIO load. 964program get the CPU sometimes even under high AIO load.
951 965
952 # try not to spend much more than 0.1s in poll_cb 966 # try not to spend much more than 0.1s in poll_cb
953 IO::AIO::max_poll_time 0.1; 967 IO::AIO::max_poll_time 0.1;
954 968

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines