… | |
… | |
16 | Instead, in this module a number of (non-posix) threads are started that |
16 | Instead, in this module a number of (non-posix) threads are started that |
17 | execute your read/writes and signal their completion. You don't need |
17 | execute your read/writes and signal their completion. You don't need |
18 | thread support in your libc or perl, and the threads created by this |
18 | thread support in your libc or perl, and the threads created by this |
19 | module will not be visible to the pthreads library. |
19 | module will not be visible to the pthreads library. |
20 | |
20 | |
|
|
21 | NOTICE: the threads created by this module will automatically be killed |
|
|
22 | when the thread calling min_parallel exits. Make sure you only ever call |
|
|
23 | min_parallel from the same thread that loaded this module. |
|
|
24 | |
21 | Although the module will work with threads, it is not reentrant, so use |
25 | Although the module will work with threads, it is not reentrant, so use |
22 | appropriate locking yourself. |
26 | appropriate locking yourself. |
23 | |
27 | |
24 | =over 4 |
28 | =over 4 |
25 | |
29 | |
… | |
… | |
28 | package Linux::AIO; |
32 | package Linux::AIO; |
29 | |
33 | |
30 | use base 'Exporter'; |
34 | use base 'Exporter'; |
31 | |
35 | |
32 | BEGIN { |
36 | BEGIN { |
33 | $VERSION = 1.1; |
37 | $VERSION = 1.6; |
34 | |
38 | |
35 | @EXPORT = qw(aio_read aio_write aio_open aio_close aio_stat aio_lstat); |
39 | @EXPORT = qw(aio_read aio_write aio_open aio_close aio_stat aio_lstat aio_unlink); |
36 | @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); |
37 | |
41 | |
38 | require XSLoader; |
42 | require XSLoader; |
39 | XSLoader::load Linux::AIO, $VERSION; |
43 | XSLoader::load Linux::AIO, $VERSION; |
40 | } |
44 | } |
… | |
… | |
43 | |
47 | |
44 | 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 |
45 | 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 |
46 | (the number of outstanding operations, however, is unlimited). |
50 | (the number of outstanding operations, however, is unlimited). |
47 | |
51 | |
48 | 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 |
49 | kernel versions will scale negatively with the number of threads (higher |
53 | kernel versions will scale negatively with the number of threads (higher |
50 | 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. |
51 | |
64 | |
52 | =item $fileno = Linux::AIO::poll_fileno |
65 | =item $fileno = Linux::AIO::poll_fileno |
53 | |
66 | |
54 | Return the I<request result pipe filehandle>. This filehandle must be |
67 | Return the I<request result pipe filehandle>. This filehandle must be |
55 | 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 |
… | |
… | |
66 | |
79 | |
67 | Event->io (fd => Linux::AIO::poll_fileno, |
80 | Event->io (fd => Linux::AIO::poll_fileno, |
68 | poll => 'r', async => 1, |
81 | poll => 'r', async => 1, |
69 | cb => \&Linux::AIO::poll_cb ); |
82 | cb => \&Linux::AIO::poll_cb ); |
70 | |
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). |
71 | |
89 | |
72 | =item Linux::AIO::nreqs |
90 | =item Linux::AIO::nreqs |
73 | |
91 | |
74 | Returns the number of requests currently outstanding. |
92 | Returns the number of requests currently outstanding. |
75 | |
93 | |
… | |
… | |
101 | |
119 | |
102 | Currently, the stats are always 64-bit-stats, i.e. instead of returning an |
120 | Currently, the stats are always 64-bit-stats, i.e. instead of returning an |
103 | error when stat'ing a large file, the results will be silently truncated |
121 | error when stat'ing a large file, the results will be silently truncated |
104 | unless perl itself is compiled with large file support. |
122 | unless perl itself is compiled with large file support. |
105 | |
123 | |
|
|
124 | =item aio_unlink $pathname, $callback |
|
|
125 | |
|
|
126 | Asynchronously unlink a file. |
|
|
127 | |
106 | =cut |
128 | =cut |
107 | |
129 | |
108 | min_parallel 1; |
130 | min_parallel 1; |
109 | |
131 | |
110 | END { |
132 | END { |
… | |
… | |
126 | |
148 | |
127 | L<Coro>. |
149 | L<Coro>. |
128 | |
150 | |
129 | =head1 AUTHOR |
151 | =head1 AUTHOR |
130 | |
152 | |
131 | Marc Lehmann <pcg@goof.com> |
153 | Marc Lehmann <schmorp@schmorp.de> |
132 | http://www.goof.com/pcg/marc/ |
154 | http://home.schmorp.de/ |
133 | |
155 | |
134 | =cut |
156 | =cut |
135 | |
157 | |