… | |
… | |
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 | |
|
|
25 | Although the module will work with threads, it is not reentrant, so use |
|
|
26 | appropriate locking yourself. |
|
|
27 | |
21 | =over 4 |
28 | =over 4 |
22 | |
29 | |
23 | =cut |
30 | =cut |
24 | |
31 | |
25 | package Linux::AIO; |
32 | package Linux::AIO; |
26 | |
33 | |
27 | use base 'Exporter'; |
34 | use base 'Exporter'; |
28 | |
35 | |
29 | BEGIN { |
36 | BEGIN { |
30 | $VERSION = 1.01; |
37 | $VERSION = 1.2; |
31 | |
38 | |
32 | @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); |
33 | @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); |
34 | |
41 | |
35 | require XSLoader; |
42 | require XSLoader; |
36 | XSLoader::load Linux::AIO, $VERSION; |
43 | XSLoader::load Linux::AIO, $VERSION; |
37 | } |
44 | } |
38 | |
45 | |
39 | =item Linux::AIO::min_parallel $nthreads |
46 | =item Linux::AIO::min_parallel $nthreads |
40 | |
47 | |
41 | Set the minimum number of AIO threads to C<$nthreads>. You I<have> to call |
48 | Set the minimum number of AIO threads to C<$nthreads>. The default is |
42 | this function with a positive number at least once, otherwise no threads |
49 | C<1>, which means a single asynchronous operation can be done at one time |
43 | will be started and you aio-operations will seem to hang. |
50 | (the number of outstanding operations, however, is unlimited). |
44 | |
51 | |
45 | 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 many linux |
46 | kernel versions will scale negatively with the number of threads (higher |
53 | kernel versions will scale negatively with the number of threads (higher |
47 | parallelity => MUCH higher latency). |
54 | parallelity => MUCH higher latency). |
48 | |
55 | |
… | |
… | |
98 | |
105 | |
99 | Currently, the stats are always 64-bit-stats, i.e. instead of returning an |
106 | Currently, the stats are always 64-bit-stats, i.e. instead of returning an |
100 | error when stat'ing a large file, the results will be silently truncated |
107 | error when stat'ing a large file, the results will be silently truncated |
101 | unless perl itself is compiled with large file support. |
108 | unless perl itself is compiled with large file support. |
102 | |
109 | |
|
|
110 | =item aio_unlink $pathname, $callback |
|
|
111 | |
|
|
112 | Asynchronously unlink a file. |
|
|
113 | |
103 | =cut |
114 | =cut |
|
|
115 | |
|
|
116 | min_parallel 1; |
104 | |
117 | |
105 | END { |
118 | END { |
106 | max_parallel 0; |
119 | max_parallel 0; |
107 | } |
120 | } |
108 | |
121 | |