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.213 by root, Sat Jun 20 07:14:35 2009 UTC vs.
Revision 1.218 by root, Wed Jun 24 10:03:42 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.411; 936our $VERSION = 4.412;
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
1359=item C<PERL_ANYEVENT_STRICT> 1366=item C<PERL_ANYEVENT_STRICT>
1360 1367
1361AnyEvent does not do much argument checking by default, as thorough 1368AnyEvent does not do much argument checking by default, as thorough
1362argument checking is very costly. Setting this variable to a true value 1369argument checking is very costly. Setting this variable to a true value
1363will cause AnyEvent to load C<AnyEvent::Strict> and then to thoroughly 1370will cause AnyEvent to load C<AnyEvent::Strict> and then to thoroughly
1364check the arguments passed to most method calls. If it finds any problems 1371check the arguments passed to most method calls. If it finds any problems,
1365it will croak. 1372it will croak.
1366 1373
1367In other words, enables "strict" mode. 1374In other words, enables "strict" mode.
1368 1375
1369Unlike C<use strict>, it is definitely recommended ot keep it off in 1376Unlike C<use strict>, it is definitely recommended to keep it off in
1370production. Keeping C<PERL_ANYEVENT_STRICT=1> in your environment while 1377production. Keeping C<PERL_ANYEVENT_STRICT=1> in your environment while
1371developing programs can be very useful, however. 1378developing programs can be very useful, however.
1372 1379
1373=item C<PERL_ANYEVENT_MODEL> 1380=item C<PERL_ANYEVENT_MODEL>
1374 1381
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 mostly shows that the AnyEvent backend from IO::Lambda isn't
1906very optimal. 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 or much non-blocking I/O, but it is a
1913benchmark nevertheless.
1914
1915 name runtime
1916 Lambda/select 0.330 sec
1917 + optimized 0.122 sec
1918 Lambda/AnyEvent 0.327 sec
1919 + optimized 0.138 sec
1920 Raw sockets/select 0.077 sec
1921 POE/select, components 0.662 sec
1922 POE/select, raw sockets 0.226 sec
1923 POE/select, optimized 0.404 sec
1924
1925 AnyEvent/select/nb 0.085 sec
1926 AnyEvent/EV/nb 0.068 sec
1927 +state machine 0.134 sec
1928
1929The benchmark is also a bit unfair (my fault): the IO::Lambda/POE
1930benchmarks actually make blocking connects and use 100% blocking I/O,
1931defeating the purpose of an event-based solution. All of the newly
1932written AnyEvent benchmarks use 100% non-blocking connects (using
1933AnyEvent::Socket::tcp_connect and the asynchronous pure perl DNS
1934resolver), so AnyEvent is at a disadvantage here, as non-blocking connects
1935generally require a lot more bookkeeping and event handling than blocking
1936connects (which involve a single syscall only).
1937
1938The last AnyEvent benchmark additionally uses L<AnyEvent::Handle>, which
1939offers similar expressive power as POE and IO::Lambda, using conventional
1940Perl syntax. This means that both the echo server and the client are 100%
1941non-blocking, further placing it at a disadvantage.
1942
1943As you can see, the AnyEvent + EV combination even beats the
1944hand-optimised "raw sockets benchmark", while AnyEvent + its pure perl
1945backend easily beats IO::Lambda and POE.
1946
1947And even the 100% non-blocking version written using the high-level (and
1948slow :) L<AnyEvent::Handle> abstraction beats both POE and IO::Lambda by a
1949large margin, even though it does all of DNS, tcp-connect and socket I/O
1950in a non-blocking way.
1951
1952The two AnyEvent benchmarks programs can be found as F<eg/ae0.pl> and
1953F<eg/ae2.pl> in the AnyEvent distribution, the remaining benchmarks are
1954part of the IO::lambda distribution and were used without any changes.
1955
1892 1956
1893=head1 SIGNALS 1957=head1 SIGNALS
1894 1958
1895AnyEvent currently installs handlers for these signals: 1959AnyEvent currently installs handlers for these signals:
1896 1960
1955Similar considerations apply to $ENV{PERL_ANYEVENT_VERBOSE}, as that can 2019Similar considerations apply to $ENV{PERL_ANYEVENT_VERBOSE}, as that can
1956be used to probe what backend is used and gain other information (which is 2020be 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 2021probably even less useful to an attacker than PERL_ANYEVENT_MODEL), and
1958$ENV{PERL_ANYEVENT_STRICT}. 2022$ENV{PERL_ANYEVENT_STRICT}.
1959 2023
2024Note that AnyEvent will remove I<all> environment variables starting with
2025C<PERL_ANYEVENT_> from C<%ENV> when it is loaded while taint mode is
2026enabled.
2027
1960 2028
1961=head1 BUGS 2029=head1 BUGS
1962 2030
1963Perl 5.8 has numerous memleaks that sometimes hit this module and are hard 2031Perl 5.8 has numerous memleaks that sometimes hit this module and are hard
1964to work around. If you suffer from memleaks, first upgrade to Perl 5.10 2032to work around. If you suffer from memleaks, first upgrade to Perl 5.10

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines