… | |
… | |
32 | package Linux::AIO; |
32 | package Linux::AIO; |
33 | |
33 | |
34 | use base 'Exporter'; |
34 | use base 'Exporter'; |
35 | |
35 | |
36 | BEGIN { |
36 | BEGIN { |
37 | $VERSION = 1.41; |
37 | $VERSION = 1.5; |
38 | |
38 | |
39 | @EXPORT = qw(aio_read aio_write aio_open aio_close aio_stat aio_lstat aio_unlink); |
39 | @EXPORT = qw(aio_read aio_write aio_open aio_close aio_stat aio_lstat aio_unlink); |
40 | @EXPORT_OK = qw(poll_fileno poll_cb min_parallel max_parallel nreqs); |
40 | @EXPORT_OK = qw(poll_fileno poll_cb min_parallel max_parallel nreqs); |
41 | |
41 | |
42 | require XSLoader; |
42 | require XSLoader; |
… | |
… | |
47 | |
47 | |
48 | Set the minimum number of AIO threads to C<$nthreads>. The default is |
48 | Set the minimum number of AIO threads to C<$nthreads>. The default is |
49 | C<1>, which means a single asynchronous operation can be done at one time |
49 | C<1>, which means a single asynchronous operation can be done at one time |
50 | (the number of outstanding operations, however, is unlimited). |
50 | (the number of outstanding operations, however, is unlimited). |
51 | |
51 | |
52 | It is recommended to keep the number of threads low, as many linux |
52 | It is recommended to keep the number of threads low, as some linux |
53 | kernel versions will scale negatively with the number of threads (higher |
53 | kernel versions will scale negatively with the number of threads (higher |
54 | parallelity => MUCH higher latency). |
54 | parallelity => MUCH higher latency). |
|
|
55 | |
|
|
56 | =item Linux::AIO::max_parallel $nthreads |
|
|
57 | |
|
|
58 | Sets the maximum number of AIO threads to C<$nthreads>. If more than |
|
|
59 | the specified number of threads are currently running, kill them. This |
|
|
60 | function blocks until the limit is reached. |
|
|
61 | |
|
|
62 | This module automatically runs C<max_parallel 0> at program end, to ensure |
|
|
63 | that all threads are killed and that there are no outstanding requests. |
55 | |
64 | |
56 | =item $fileno = Linux::AIO::poll_fileno |
65 | =item $fileno = Linux::AIO::poll_fileno |
57 | |
66 | |
58 | Return the I<request result pipe filehandle>. This filehandle must be |
67 | Return the I<request result pipe filehandle>. This filehandle must be |
59 | polled for reading by some mechanism outside this module (e.g. Event |
68 | polled for reading by some mechanism outside this module (e.g. Event |
… | |
… | |
69 | You can use Event to multiplex, e.g.: |
78 | You can use Event to multiplex, e.g.: |
70 | |
79 | |
71 | Event->io (fd => Linux::AIO::poll_fileno, |
80 | Event->io (fd => Linux::AIO::poll_fileno, |
72 | poll => 'r', async => 1, |
81 | poll => 'r', async => 1, |
73 | cb => \&Linux::AIO::poll_cb ); |
82 | cb => \&Linux::AIO::poll_cb ); |
|
|
83 | |
|
|
84 | =item Linux::AIO::poll_wait |
|
|
85 | |
|
|
86 | Wait till the result filehandle becomes ready for reading (simply does a |
|
|
87 | select on the filehandle. This is useful if you want to synchronously wait |
|
|
88 | for some requests to finish). |
74 | |
89 | |
75 | =item Linux::AIO::nreqs |
90 | =item Linux::AIO::nreqs |
76 | |
91 | |
77 | Returns the number of requests currently outstanding. |
92 | Returns the number of requests currently outstanding. |
78 | |
93 | |