ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/AnyEvent/lib/AnyEvent.pm
(Generate patch)

Comparing AnyEvent/lib/AnyEvent.pm (file contents):
Revision 1.211 by root, Sat Jun 6 12:04:30 2009 UTC vs.
Revision 1.216 by root, Tue Jun 23 12:21:34 2009 UTC

931no warnings; 931no warnings;
932use strict qw(vars subs); 932use strict qw(vars subs);
933 933
934use Carp; 934use Carp;
935 935
936our $VERSION = 4.41; 936our $VERSION = 4.411;
937our $MODEL; 937our $MODEL;
938 938
939our $AUTOLOAD; 939our $AUTOLOAD;
940our @ISA; 940our @ISA;
941 941
942our @REGISTRY; 942our @REGISTRY;
943 943
944our $WIN32; 944our $WIN32;
945 945
946BEGIN { 946BEGIN {
947 my $win32 = ! ! ($^O =~ /mswin32/i); 947 eval "sub WIN32(){ " . (($^O =~ /mswin32/i)*1) ." }";
948 eval "sub WIN32(){ $win32 }"; 948 eval "sub TAINT(){ " . (${^TAINT}*1) . " }";
949
950 delete @ENV{grep /^PERL_ANYEVENT_/, keys %ENV}
951 if ${^TAINT};
949} 952}
950 953
951our $verbose = $ENV{PERL_ANYEVENT_VERBOSE}*1; 954our $verbose = $ENV{PERL_ANYEVENT_VERBOSE}*1;
952 955
953our %PROTOCOL; # (ipv4|ipv6) => (1|2), higher numbers are preferred 956our %PROTOCOL; # (ipv4|ipv6) => (1|2), higher numbers are preferred
1337so on. 1340so on.
1338 1341
1339=head1 ENVIRONMENT VARIABLES 1342=head1 ENVIRONMENT VARIABLES
1340 1343
1341The following environment variables are used by this module or its 1344The following environment variables are used by this module or its
1342submodules: 1345submodules.
1346
1347Note that AnyEvent will remove I<all> environment variables starting with
1348C<PERL_ANYEVENT_> from C<%ENV> when it is loaded while taint mode is
1349enabled.
1343 1350
1344=over 4 1351=over 4
1345 1352
1346=item C<PERL_ANYEVENT_VERBOSE> 1353=item C<PERL_ANYEVENT_VERBOSE>
1347 1354
1887=item * C-based event loops perform very well with small number of 1894=item * C-based event loops perform very well with small number of
1888watchers, as the management overhead dominates. 1895watchers, as the management overhead dominates.
1889 1896
1890=back 1897=back
1891 1898
1899=head2 THE IO::Lambda BENCHMARK
1900
1901Recently I was told about the benchmark in the IO::Lambda manpage, which
1902could be misinterpreted to make AnyEvent look bad. In fact, the benchmark
1903simply compares IO::Lambda with POE, and IO::Lambda looks better (which
1904shouldn't come as a surprise to anybody). As such, the benchmark is
1905fine, and shows that the AnyEvent backend from IO::Lambda isn't very
1906optimal. But how would AnyEvent compare when used without the extra
1907baggage? To explore this, I wrote the equivalent benchmark for AnyEvent.
1908
1909The benchmark itself creates an echo-server, and then, for 500 times,
1910connects to the echo server, sends a line, waits for the reply, and then
1911creates the next connection. This is a rather bad benchmark, as it doesn't
1912test the efficiency of the framework, but it is a benchmark nevertheless.
1913
1914 name runtime
1915 Lambda/select 0.330 sec
1916 + optimized 0.122 sec
1917 Lambda/AnyEvent 0.327 sec
1918 + optimized 0.138 sec
1919 Raw sockets/select 0.077 sec
1920 POE/select, components 0.662 sec
1921 POE/select, raw sockets 0.226 sec
1922 POE/select, optimized 0.404 sec
1923
1924 AnyEvent/select/nb 0.085 sec
1925 AnyEvent/EV/nb 0.068 sec
1926 +state machine 0.134 sec
1927
1928The benchmark is also a bit unfair (my fault) - the IO::Lambda
1929benchmarks actually make blocking connects and use 100% blocking I/O,
1930defeating the purpose of an event-based solution. All of the newly
1931written AnyEvent benchmarks use 100% non-blocking connects (using
1932AnyEvent::Socket::tcp_connect and the asynchronous pure perl DNS
1933resolver), so AnyEvent is at a disadvantage here as non-blocking connects
1934generally require a lot more bookkeeping and event handling than blocking
1935connects (which involve a single syscall only).
1936
1937The last AnyEvent benchmark additionally uses L<AnyEvent::Handle>, which
1938offers similar expressive power as POE and IO::Lambda (using conventional
1939Perl syntax), which means both the echo server and the client are 100%
1940non-blocking w.r.t. I/O, further placing it at a disadvantage.
1941
1942As you can see, AnyEvent + EV even beats the hand-optimised "raw sockets
1943benchmark", while AnyEvent + its pure perl backend easily beats
1944IO::Lambda and POE.
1945
1946And even the 100% non-blocking version written using the high-level (and
1947slow :) L<AnyEvent::Handle> abstraction beats both POE and IO::Lambda,
1948even thought it does all of DNS, tcp-connect and socket I/O in a
1949non-blocking way.
1950
1951The two AnyEvent benchmarks can be found as F<eg/ae0.pl> and F<eg/ae2.pl>
1952in the AnyEvent distribution, the remaining benchmarks are part of the
1953IO::lambda distribution and were used without any changes.
1954
1892 1955
1893=head1 SIGNALS 1956=head1 SIGNALS
1894 1957
1895AnyEvent currently installs handlers for these signals: 1958AnyEvent currently installs handlers for these signals:
1896 1959
1953 use AnyEvent; 2016 use AnyEvent;
1954 2017
1955Similar considerations apply to $ENV{PERL_ANYEVENT_VERBOSE}, as that can 2018Similar considerations apply to $ENV{PERL_ANYEVENT_VERBOSE}, as that can
1956be used to probe what backend is used and gain other information (which is 2019be used to probe what backend is used and gain other information (which is
1957probably even less useful to an attacker than PERL_ANYEVENT_MODEL), and 2020probably even less useful to an attacker than PERL_ANYEVENT_MODEL), and
1958$ENV{PERL_ANYEGENT_STRICT}. 2021$ENV{PERL_ANYEVENT_STRICT}.
1959 2022
1960 2023
1961=head1 BUGS 2024=head1 BUGS
1962 2025
1963Perl 5.8 has numerous memleaks that sometimes hit this module and are hard 2026Perl 5.8 has numerous memleaks that sometimes hit this module and are hard

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines