ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/Linux-AIO/AIO.pm
Revision: 1.15
Committed: Thu May 6 12:16:48 2004 UTC (20 years ago) by root
Branch: MAIN
Changes since 1.14: +1 -1 lines
Log Message:
*** empty log message ***

File Contents

# User Rev Content
1 root 1.1 =head1 NAME
2    
3     Linux::AIO - linux-specific aio implemented using clone
4    
5     =head1 SYNOPSIS
6    
7     use Linux::AIO;
8    
9     =head1 DESCRIPTION
10    
11 root 1.14 This module implements asynchronous i/o using the means available to linux
12     - clone. It does not hook into the POSIX aio_* functions because linux
13     does not yet support these in the kernel (and even if, it would only allow
14     aio_read and write, not open and stat).
15    
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
18     thread support in your libc or perl, and the threads created by this
19     module will not be visible to the pthreads library.
20 root 1.3
21 root 1.1 =over 4
22    
23     =cut
24    
25     package Linux::AIO;
26    
27 root 1.2 use base 'Exporter';
28    
29 root 1.1 BEGIN {
30 root 1.15 $VERSION = 1.01;
31 root 1.1
32 root 1.10 @EXPORT = qw(aio_read aio_write aio_open aio_close aio_stat aio_lstat);
33 root 1.2 @EXPORT_OK = qw(poll_fileno poll_cb min_parallel max_parallel nreqs);
34    
35 root 1.1 require XSLoader;
36     XSLoader::load Linux::AIO, $VERSION;
37     }
38    
39 root 1.14 =item Linux::AIO::min_parallel $nthreads
40 root 1.1
41 root 1.14 Set the minimum number of AIO threads to C<$nthreads>. You I<have> to call
42     this function with a positive number at least once, otherwise no threads
43 root 1.3 will be started and you aio-operations will seem to hang.
44 root 1.1
45 root 1.14 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
47     parallelity => MUCH higher latency).
48    
49 root 1.2 =item $fileno = Linux::AIO::poll_fileno
50    
51 root 1.14 Return the I<request result pipe filehandle>. This filehandle must be
52     polled for reading by some mechanism outside this module (e.g. Event
53     or select, see below). If the pipe becomes readable you have to call
54     C<poll_cb> to check the results.
55 root 1.2
56     =item Linux::AIO::poll_cb
57    
58     Process all outstanding events on the result pipe. You have to call this
59 root 1.14 regularly. Returns the number of events processed. Returns immediately
60     when no events are outstanding.
61 root 1.2
62 root 1.3 You can use Event to multiplex, e.g.:
63    
64 root 1.14 Event->io (fd => Linux::AIO::poll_fileno,
65     poll => 'r', async => 1,
66     cb => \&Linux::AIO::poll_cb );
67 root 1.3
68    
69 root 1.2 =item Linux::AIO::nreqs
70    
71     Returns the number of requests currently outstanding.
72 root 1.4
73 root 1.14 =item aio_open $pathname, $flags, $mode, $callback
74 root 1.10
75     Asynchronously open or create a file and call the callback with the
76 root 1.14 filedescriptor (NOT a perl filehandle, sorry for that, but watch out, this
77     might change in the future).
78 root 1.10
79 root 1.14 =item aio_close $fh, $callback
80 root 1.10
81     Asynchronously close a file and call the callback with the result code.
82    
83 root 1.14 =item aio_read $fh,$offset,$length, $data,$dataoffset,$callback
84 root 1.9
85 root 1.14 =item aio_write $fh,$offset,$length, $data,$dataoffset,$callback
86 root 1.4
87     Reads or writes C<length> bytes from the specified C<fh> and C<offset>
88     into the scalar given by C<data> and offset C<dataoffset> and calls the
89 root 1.14 callback without the actual number of bytes read (or C<undef> on error).
90 root 1.4
91 root 1.14 =item aio_stat $fh_or_path, $callback
92 root 1.4
93 root 1.14 =item aio_lstat $fh, $callback
94 root 1.5
95 root 1.14 Works like perl's C<stat> or C<lstat> in void context. The callback will
96     be called after the stat and the results will be available using C<stat _>
97     or C<-s _> etc...
98 root 1.5
99 root 1.10 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
101     unless perl itself is compiled with large file support.
102 root 1.2
103 root 1.1 =cut
104 root 1.2
105     END {
106     max_parallel 0;
107     }
108 root 1.1
109     1;
110    
111     =back
112    
113     =head1 BUGS
114    
115 root 1.14 This module has been extensively tested in a large and very busy webserver
116     for many years now.
117 root 1.1
118 root 1.14 - aio_open gives a fd, but all other functions expect a perl filehandle.
119 root 1.6
120 root 1.1 =head1 SEE ALSO
121    
122     L<Coro>.
123    
124     =head1 AUTHOR
125    
126     Marc Lehmann <pcg@goof.com>
127     http://www.goof.com/pcg/marc/
128    
129     =cut
130