Commit f37d137a authored by Nicholas Bamber's avatar Nicholas Bamber

[svn-upgrade] new version libio-aio-perl (3.93)

parent 1cc17a19
......@@ -170,7 +170,7 @@ use common::sense;
use base 'Exporter';
BEGIN {
our $VERSION = '3.9';
our $VERSION = '3.93';
our @AIO_REQ = qw(aio_sendfile aio_read aio_write aio_open aio_close
aio_stat aio_lstat aio_unlink aio_rmdir aio_readdir aio_readdirx
......@@ -438,32 +438,40 @@ Tries to copy C<$length> bytes from C<$in_fh> to C<$out_fh>. It starts
reading at byte offset C<$in_offset>, and starts writing at the current
file offset of C<$out_fh>. Because of that, it is not safe to issue more
than one C<aio_sendfile> per C<$out_fh>, as they will interfere with each
other.
other. The same C<$in_fh> works fine though, as this function does not
move or use the file offset of C<$in_fh>.
Please note that C<aio_sendfile> can read more bytes from C<$in_fh> than
are written, and there is no way to find out how many bytes have been read
from C<aio_sendfile> alone, as C<aio_sendfile> only provides the number of
bytes written to C<$out_fh>. Only if the result value equals C<$length>
one can assume that C<$length> bytes have been read.
are written, and there is no way to find out how many more bytes have been
read from C<aio_sendfile> alone, as C<aio_sendfile> only provides the
number of bytes written to C<$out_fh>. Only if the result value equals
C<$length> one can assume that C<$length> bytes have been read.
Unlike with other C<aio_> functions, it makes a lot of sense to use
C<aio_sendfile> on non-blocking sockets, as long as one end (typically
the C<$in_fh>) is a file - the file I/O will then be asynchronous, while
the socket I/O will be non-blocking. Note, however, that you can run into
a trap where C<aio_sendfile> reads some data with readahead, then fails
to write all data, and when the socket is ready the next time, the data
in the cache is already lost, forcing C<aio_sendfile> to again hit the
disk. Explicit C<aio_read> + C<aio_write> let's you control resource usage
much better.
the socket I/O will be non-blocking. Note, however, that you can run
into a trap where C<aio_sendfile> reads some data with readahead, then
fails to write all data, and when the socket is ready the next time, the
data in the cache is already lost, forcing C<aio_sendfile> to again hit
the disk. Explicit C<aio_read> + C<aio_write> let's you better control
resource usage.
This call tries to make use of a native C<sendfile> syscall to provide
zero-copy operation. For this to work, C<$out_fh> should refer to a
socket, and C<$in_fh> should refer to an mmap'able file.
This call tries to make use of a native C<sendfile>-like syscall to
provide zero-copy operation. For this to work, C<$out_fh> should refer to
a socket, and C<$in_fh> should refer to an mmap'able file.
If a native sendfile cannot be found or it fails with C<ENOSYS>,
C<ENOTSUP>, C<EOPNOTSUPP>, C<EAFNOSUPPORT>, C<EPROTOTYPE> or C<ENOTSOCK>,
it will be emulated, so you can call C<aio_sendfile> on any type of
filehandle regardless of the limitations of the operating system.
C<EINVAL>, C<ENOTSUP>, C<EOPNOTSUPP>, C<EAFNOSUPPORT>, C<EPROTOTYPE> or
C<ENOTSOCK>, it will be emulated, so you can call C<aio_sendfile> on any
type of filehandle regardless of the limitations of the operating system.
As native sendfile syscalls (as practically any non-POSIX interface hacked
together in a hurry to improve benchmark numbers) tend to be rather buggy
on many systems, this implementation tries to work around some known bugs
in Linux and FreeBSD kernels (probably others, too), but that might fail,
so you really really should check the return value of C<aio_sendfile> -
fewre bytes than expected might have been transferred.
=item aio_readahead $fh,$offset,$length, $callback->($retval)
......@@ -864,7 +872,7 @@ sub aio_move($$;$) {
add $grp aio_copy $src, $dst, sub {
$grp->result ($_[0]);
if (!$_[0]) {
unless ($_[0]) {
aioreq_pri $pri;
add $grp aio_unlink $src;
}
......@@ -1566,21 +1574,38 @@ allowed to exit. SEe C<IO::AIO::max_idle>.
=item IO::AIO::max_outstanding $maxreqs
Sets the maximum number of outstanding requests to C<$nreqs>. If
you do queue up more than this number of requests, the next call to
C<IO::AIO::poll_cb> (and other functions calling C<poll_cb>, such as
C<IO::AIO::flush> or C<IO::AIO::poll>) will block until the limit is no
longer exceeded.
In other words, this setting does not enforce a queue limit, but can be
used to make poll functions block if the limit is exceeded.
This is a very bad function to use in interactive programs because it
blocks, and a bad way to reduce concurrency because it is inexact: Better
use an C<aio_group> together with a feed callback.
Sets the maximum number of outstanding requests to C<$nreqs>. If you
do queue up more than this number of requests, the next call to the
C<poll_cb> (and C<poll_some> and other functions calling C<poll_cb>)
function will block until the limit is no longer exceeded.
It's main use is in scripts without an event loop - when you want to stat
a lot of files, you can write somehting like this:
The default value is very large, so there is no practical limit on the
number of outstanding requests.
IO::AIO::max_outstanding 32;
for my $path (...) {
aio_stat $path , ...;
IO::AIO::poll_cb;
}
You can still queue as many requests as you want. Therefore,
C<max_outstanding> is mainly useful in simple scripts (with low values) or
as a stop gap to shield against fatal memory overflow (with large values).
IO::AIO::flush;
The call to C<poll_cb> inside the loop will normally return instantly, but
as soon as more thna C<32> reqeusts are in-flight, it will block until
some requests have been handled. This keeps the loop from pushing a large
number of C<aio_stat> requests onto the queue.
The default value for C<max_outstanding> is very large, so there is no
practical limit on the number of outstanding requests.
=back
......@@ -1766,19 +1791,17 @@ some examples of how to do this:
=head2 FORK BEHAVIOUR
This module should do "the right thing" when the process using it forks:
Before the fork, IO::AIO enters a quiescent state where no requests
can be added in other threads and no results will be processed. After
the fork the parent simply leaves the quiescent state and continues
request/result processing, while the child frees the request/result queue
(so that the requests started before the fork will only be handled in the
parent). Threads will be started on demand until the limit set in the
parent process has been reached again.
In short: the parent will, after a short pause, continue as if fork had
not been called, while the child will act as if IO::AIO has not been used
yet.
Usage of pthreads in a program changes the semantics of fork
considerably. Specifically, only async-safe functions can be called after
fork. Perl doesn't know about this, so in general, you cannot call fork
with defined behaviour in perl. IO::AIO uses pthreads, so this applies,
but many other extensions and (for inexplicable reasons) perl itself often
is linked against pthreads, so this limitation applies.
Some operating systems have extensions that allow safe use of fork, and
this module should do "the right thing" on those, and tries on others. At
the time of this writing (2011) only GNU/Linux supports these extensions
to POSIX.
=head2 MEMORY USAGE
......
......@@ -7,6 +7,31 @@ TODO: splice/tee/vmsplice? (http://kerneltrap.org/node/6505 http://lwn.net/Artic
TODO: aio_fcntl, at least for file-locking
TODO: fallocate, if it wouldn't be so useless.
TODO: aio_mincore?
TODO: getxattr etc.?
TODO: MS_xxx, posix_fadvise, posix_madvise
TODO: realpath
3.93 Wed Jun 29 23:44:18 CEST 2011
- ECB.H WAS MISSING.
3.92 Wed Jun 29 14:45:41 CEST 2011
- ecb.h was missing.
3.91 Wed Jun 29 13:24:42 CEST 2011
- (libeio) work around a Linux (and likely FreeBSD and other
kernels) bug where sendfile would not transfer all the requested
bytes on large transfers, using a heuristic.
- buggy sendfile caused aio_move/copy to sometimes fail for big
files (fortunately it checks that the whole file has been
transferred...)
- use libecb for higher performance and higher portability.
- (libeio) disable sendfile on darwin, it's too broken.
- disable fork tests on !linux, as only linux supports mixing
pthread and fork in perl.
- document the fact that fork doesn't work anymore when using
this module, on anything !GNU/Linux.
- increase timeout in t/04_fork.t, as too many CPAN-tester setups
run on a 0.1MHz cpu. Or so.
3.9 Fri May 27 02:43:47 CEST 2011
- (libeio) fix memory corruption in aio_readdirx for the flags
......
......@@ -18,6 +18,7 @@ t/07_feeder.t
t/aio_test_common.pm
libeio/xthread.h
libeio/ecb.h
libeio/eio.h
libeio/eio.c
libeio/libeio.m4
......
......@@ -11,7 +11,7 @@
},
"generated_by" : "ExtUtils::MakeMaker::JSONMETA version 7.000",
"distribution_type" : "module",
"version" : "3.9",
"version" : "3.93",
"name" : "IO-AIO",
"author" : [],
"license" : "unknown",
......
......@@ -369,13 +369,15 @@ FUNCTIONS
reading at byte offset $in_offset, and starts writing at the current
file offset of $out_fh. Because of that, it is not safe to issue
more than one "aio_sendfile" per $out_fh, as they will interfere
with each other.
with each other. The same $in_fh works fine though, as this function
does not move or use the file offset of $in_fh.
Please note that "aio_sendfile" can read more bytes from $in_fh than
are written, and there is no way to find out how many bytes have
been read from "aio_sendfile" alone, as "aio_sendfile" only provides
the number of bytes written to $out_fh. Only if the result value
equals $length one can assume that $length bytes have been read.
are written, and there is no way to find out how many more bytes
have been read from "aio_sendfile" alone, as "aio_sendfile" only
provides the number of bytes written to $out_fh. Only if the result
value equals $length one can assume that $length bytes have been
read.
Unlike with other "aio_" functions, it makes a lot of sense to use
"aio_sendfile" on non-blocking sockets, as long as one end
......@@ -385,17 +387,25 @@ FUNCTIONS
some data with readahead, then fails to write all data, and when the
socket is ready the next time, the data in the cache is already
lost, forcing "aio_sendfile" to again hit the disk. Explicit
"aio_read" + "aio_write" let's you control resource usage much
better.
"aio_read" + "aio_write" let's you better control resource usage.
This call tries to make use of a native "sendfile" syscall to
This call tries to make use of a native "sendfile"-like syscall to
provide zero-copy operation. For this to work, $out_fh should refer
to a socket, and $in_fh should refer to an mmap'able file.
If a native sendfile cannot be found or it fails with "ENOSYS",
"ENOTSUP", "EOPNOTSUPP", "EAFNOSUPPORT", "EPROTOTYPE" or "ENOTSOCK",
it will be emulated, so you can call "aio_sendfile" on any type of
filehandle regardless of the limitations of the operating system.
"EINVAL", "ENOTSUP", "EOPNOTSUPP", "EAFNOSUPPORT", "EPROTOTYPE" or
"ENOTSOCK", it will be emulated, so you can call "aio_sendfile" on
any type of filehandle regardless of the limitations of the
operating system.
As native sendfile syscalls (as practically any non-POSIX interface
hacked together in a hurry to improve benchmark numbers) tend to be
rather buggy on many systems, this implementation tries to work
around some known bugs in Linux and FreeBSD kernels (probably
others, too), but that might fail, so you really really should check
the return value of "aio_sendfile" - fewre bytes than expected might
have been transferred.
aio_readahead $fh,$offset,$length, $callback->($retval)
"aio_readahead" populates the page cache with data from a file so
......@@ -1172,22 +1182,39 @@ FUNCTIONS
threads are allowed to exit. SEe "IO::AIO::max_idle".
IO::AIO::max_outstanding $maxreqs
Sets the maximum number of outstanding requests to $nreqs. If you do
queue up more than this number of requests, the next call to
"IO::AIO::poll_cb" (and other functions calling "poll_cb", such as
"IO::AIO::flush" or "IO::AIO::poll") will block until the limit is
no longer exceeded.
In other words, this setting does not enforce a queue limit, but can
be used to make poll functions block if the limit is exceeded.
This is a very bad function to use in interactive programs because
it blocks, and a bad way to reduce concurrency because it is
inexact: Better use an "aio_group" together with a feed callback.
Sets the maximum number of outstanding requests to $nreqs. If you do
queue up more than this number of requests, the next call to the
"poll_cb" (and "poll_some" and other functions calling "poll_cb")
function will block until the limit is no longer exceeded.
It's main use is in scripts without an event loop - when you want to
stat a lot of files, you can write somehting like this:
IO::AIO::max_outstanding 32;
for my $path (...) {
aio_stat $path , ...;
IO::AIO::poll_cb;
}
IO::AIO::flush;
The default value is very large, so there is no practical limit on
the number of outstanding requests.
The call to "poll_cb" inside the loop will normally return
instantly, but as soon as more thna 32 reqeusts are in-flight, it
will block until some requests have been handled. This keeps the
loop from pushing a large number of "aio_stat" requests onto the
queue.
You can still queue as many requests as you want. Therefore,
"max_outstanding" is mainly useful in simple scripts (with low
values) or as a stop gap to shield against fatal memory overflow
(with large values).
The default value for "max_outstanding" is very large, so there is
no practical limit on the number of outstanding requests.
STATISTICAL INFORMATION
IO::AIO::nreqs
......@@ -1343,19 +1370,17 @@ EVENT LOOP INTEGRATION
\&IO::AIO::poll_cb);
FORK BEHAVIOUR
This module should do "the right thing" when the process using it forks:
Before the fork, IO::AIO enters a quiescent state where no requests can
be added in other threads and no results will be processed. After the
fork the parent simply leaves the quiescent state and continues
request/result processing, while the child frees the request/result
queue (so that the requests started before the fork will only be handled
in the parent). Threads will be started on demand until the limit set in
the parent process has been reached again.
In short: the parent will, after a short pause, continue as if fork had
not been called, while the child will act as if IO::AIO has not been
used yet.
Usage of pthreads in a program changes the semantics of fork
considerably. Specifically, only async-safe functions can be called
after fork. Perl doesn't know about this, so in general, you cannot call
fork with defined behaviour in perl. IO::AIO uses pthreads, so this
applies, but many other extensions and (for inexplicable reasons) perl
itself often is linked against pthreads, so this limitation applies.
Some operating systems have extensions that allow safe use of fork, and
this module should do "the right thing" on those, and tries on others.
At the time of this writing (2011) only GNU/Linux supports these
extensions to POSIX.
MEMORY USAGE
Per-request usage:
......
This diff is collapsed.
This diff is collapsed.
......@@ -200,7 +200,7 @@ struct eio_req
void *data;
eio_cb finish;
void (*destroy)(eio_req *req); /* called when requets no longer needed */
void (*destroy)(eio_req *req); /* called when request no longer needed */
void (*feed)(eio_req *req); /* only used for group requests */
EIO_REQ_MEMBERS
......@@ -249,7 +249,7 @@ unsigned int eio_npending (void); /* numbe rof finished but unhandled requests *
unsigned int eio_nthreads (void); /* number of worker threads in use currently */
/*****************************************************************************/
/* convinience wrappers */
/* convenience wrappers */
#ifndef EIO_NO_WRAPPERS
eio_req *eio_nop (int pri, eio_cb cb, void *data); /* does nothing except go through the whole process */
......@@ -291,7 +291,7 @@ eio_req *eio_mknod (const char *path, mode_t mode, dev_t dev, int pri, eio_c
eio_req *eio_link (const char *path, const char *new_path, int pri, eio_cb cb, void *data);
eio_req *eio_symlink (const char *path, const char *new_path, int pri, eio_cb cb, void *data);
eio_req *eio_rename (const char *path, const char *new_path, int pri, eio_cb cb, void *data);
eio_req *eio_custom (eio_cb execute, int pri, eio_cb cb, void *data);
eio_req *eio_custom (void (*execute)(eio_req *), int pri, eio_cb cb, void *data);
#endif
/*****************************************************************************/
......
dnl openbsd in it's neverending brokenness requires stdint.h for intptr_t,
dnl but that header isn't very portable...
AC_CHECK_HEADERS([stdint.h])
AC_SEARCH_LIBS(
pthread_create,
[pthread pthreads pthreadVC2],
......
#!/usr/bin/perl
BEGIN {
if ($^O ne "linux") {
print qq{1..0 # SKIP only linux supports pthreads and fork\n};
exit 0;
}
}
use Test;
use IO::AIO;
......@@ -13,7 +20,7 @@ IO::AIO::aio_nop sub {
print "ok 6\n";
};
IO::AIO::aio_busy 0.2, sub {
IO::AIO::aio_busy 1, sub {
print "ok 8\n";
};
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment