ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/Linux-AIO/README
Revision: 1.3
Committed: Sat Jul 9 04:11:30 2005 UTC (19 years, 4 months ago) by root
Branch: MAIN
Changes since 1.2: +7 -6 lines
Log Message:
*** empty log message ***

File Contents

# User Rev Content
1 root 1.1 NAME
2     Linux::AIO - linux-specific aio implemented using clone
3    
4     SYNOPSIS
5     use Linux::AIO;
6    
7     DESCRIPTION
8 root 1.3 This module implements asynchronous I/O using the means available to
9     Linux - clone. It does not hook into the POSIX aio_* functions because
10     Linux does not yet support these in the kernel (even as of 2.6.12, only
11     O_DIRECT files are supported) and even if, it would only allow aio_read
12     and write, not open, stat and so on.
13 root 1.1
14     Instead, in this module a number of (non-posix) threads are started that
15     execute your read/writes and signal their completion. You don't need
16     thread support in your libc or perl, and the threads created by this
17     module will not be visible to the pthreads library.
18    
19     NOTICE: the threads created by this module will automatically be killed
20     when the thread calling min_parallel exits. Make sure you only ever call
21     min_parallel from the same thread that loaded this module.
22    
23 root 1.3 Although the module will work with in the presence of other threads, it
24     is not reentrant, so use appropriate locking yourself.
25 root 1.1
26     Linux::AIO::min_parallel $nthreads
27     Set the minimum number of AIO threads to $nthreads. The default is
28     1, which means a single asynchronous operation can be done at one
29     time (the number of outstanding operations, however, is unlimited).
30    
31 root 1.2 It is recommended to keep the number of threads low, as some linux
32 root 1.1 kernel versions will scale negatively with the number of threads
33     (higher parallelity => MUCH higher latency).
34    
35 root 1.2 Linux::AIO::max_parallel $nthreads
36     Sets the maximum number of AIO threads to $nthreads. If more than
37     the specified number of threads are currently running, kill them.
38     This function blocks until the limit is reached.
39    
40     This module automatically runs "max_parallel 0" at program end, to
41     ensure that all threads are killed and that there are no outstanding
42     requests.
43    
44 root 1.1 $fileno = Linux::AIO::poll_fileno
45     Return the *request result pipe filehandle*. This filehandle must be
46     polled for reading by some mechanism outside this module (e.g. Event
47     or select, see below). If the pipe becomes readable you have to call
48     "poll_cb" to check the results.
49    
50     Linux::AIO::poll_cb
51     Process all outstanding events on the result pipe. You have to call
52     this regularly. Returns the number of events processed. Returns
53     immediately when no events are outstanding.
54    
55     You can use Event to multiplex, e.g.:
56    
57     Event->io (fd => Linux::AIO::poll_fileno,
58     poll => 'r', async => 1,
59     cb => \&Linux::AIO::poll_cb );
60    
61 root 1.2 Linux::AIO::poll_wait
62     Wait till the result filehandle becomes ready for reading (simply
63     does a select on the filehandle. This is useful if you want to
64     synchronously wait for some requests to finish).
65    
66 root 1.1 Linux::AIO::nreqs
67     Returns the number of requests currently outstanding.
68    
69     aio_open $pathname, $flags, $mode, $callback
70     Asynchronously open or create a file and call the callback with the
71     filedescriptor (NOT a perl filehandle, sorry for that, but watch
72     out, this might change in the future).
73    
74     aio_close $fh, $callback
75     Asynchronously close a file and call the callback with the result
76     code.
77    
78     aio_read $fh,$offset,$length, $data,$dataoffset,$callback
79     aio_write $fh,$offset,$length, $data,$dataoffset,$callback
80     Reads or writes "length" bytes from the specified "fh" and "offset"
81     into the scalar given by "data" and offset "dataoffset" and calls
82     the callback without the actual number of bytes read (or "undef" on
83     error).
84    
85     aio_stat $fh_or_path, $callback
86     aio_lstat $fh, $callback
87     Works like perl's "stat" or "lstat" in void context. The callback
88     will be called after the stat and the results will be available
89     using "stat _" or "-s _" etc...
90    
91     Currently, the stats are always 64-bit-stats, i.e. instead of
92     returning an error when stat'ing a large file, the results will be
93     silently truncated unless perl itself is compiled with large file
94     support.
95    
96     aio_unlink $pathname, $callback
97     Asynchronously unlink a file.
98    
99     BUGS
100     This module has been extensively tested in a large and very busy
101     webserver for many years now.
102    
103     - aio_open gives a fd, but all other functions expect a perl filehandle.
104    
105     SEE ALSO
106     Coro.
107    
108     AUTHOR
109     Marc Lehmann <schmorp@schmorp.de>
110     http://home.schmorp.de/
111