… | |
… | |
931 | no warnings; |
931 | no warnings; |
932 | use strict qw(vars subs); |
932 | use strict qw(vars subs); |
933 | |
933 | |
934 | use Carp; |
934 | use Carp; |
935 | |
935 | |
936 | our $VERSION = 4.411; |
936 | our $VERSION = 4.412; |
937 | our $MODEL; |
937 | our $MODEL; |
938 | |
938 | |
939 | our $AUTOLOAD; |
939 | our $AUTOLOAD; |
940 | our @ISA; |
940 | our @ISA; |
941 | |
941 | |
942 | our @REGISTRY; |
942 | our @REGISTRY; |
943 | |
943 | |
944 | our $WIN32; |
944 | our $WIN32; |
945 | |
945 | |
946 | BEGIN { |
946 | BEGIN { |
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 | |
951 | our $verbose = $ENV{PERL_ANYEVENT_VERBOSE}*1; |
954 | our $verbose = $ENV{PERL_ANYEVENT_VERBOSE}*1; |
952 | |
955 | |
953 | our %PROTOCOL; # (ipv4|ipv6) => (1|2), higher numbers are preferred |
956 | our %PROTOCOL; # (ipv4|ipv6) => (1|2), higher numbers are preferred |
… | |
… | |
1337 | so on. |
1340 | so on. |
1338 | |
1341 | |
1339 | =head1 ENVIRONMENT VARIABLES |
1342 | =head1 ENVIRONMENT VARIABLES |
1340 | |
1343 | |
1341 | The following environment variables are used by this module or its |
1344 | The following environment variables are used by this module or its |
1342 | submodules: |
1345 | submodules. |
|
|
1346 | |
|
|
1347 | Note that AnyEvent will remove I<all> environment variables starting with |
|
|
1348 | C<PERL_ANYEVENT_> from C<%ENV> when it is loaded while taint mode is |
|
|
1349 | enabled. |
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 | |
1361 | AnyEvent does not do much argument checking by default, as thorough |
1368 | AnyEvent does not do much argument checking by default, as thorough |
1362 | argument checking is very costly. Setting this variable to a true value |
1369 | argument checking is very costly. Setting this variable to a true value |
1363 | will cause AnyEvent to load C<AnyEvent::Strict> and then to thoroughly |
1370 | will cause AnyEvent to load C<AnyEvent::Strict> and then to thoroughly |
1364 | check the arguments passed to most method calls. If it finds any problems |
1371 | check the arguments passed to most method calls. If it finds any problems, |
1365 | it will croak. |
1372 | it will croak. |
1366 | |
1373 | |
1367 | In other words, enables "strict" mode. |
1374 | In other words, enables "strict" mode. |
1368 | |
1375 | |
1369 | Unlike C<use strict>, it is definitely recommended ot keep it off in |
1376 | Unlike C<use strict>, it is definitely recommended to keep it off in |
1370 | production. Keeping C<PERL_ANYEVENT_STRICT=1> in your environment while |
1377 | production. Keeping C<PERL_ANYEVENT_STRICT=1> in your environment while |
1371 | developing programs can be very useful, however. |
1378 | developing 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 |
1888 | watchers, as the management overhead dominates. |
1895 | watchers, as the management overhead dominates. |
1889 | |
1896 | |
1890 | =back |
1897 | =back |
1891 | |
1898 | |
|
|
1899 | =head2 THE IO::Lambda BENCHMARK |
|
|
1900 | |
|
|
1901 | Recently I was told about the benchmark in the IO::Lambda manpage, which |
|
|
1902 | could be misinterpreted to make AnyEvent look bad. In fact, the benchmark |
|
|
1903 | simply compares IO::Lambda with POE, and IO::Lambda looks better (which |
|
|
1904 | shouldn't come as a surprise to anybody). As such, the benchmark is |
|
|
1905 | fine, and mostly shows that the AnyEvent backend from IO::Lambda isn't |
|
|
1906 | very optimal. But how would AnyEvent compare when used without the extra |
|
|
1907 | baggage? To explore this, I wrote the equivalent benchmark for AnyEvent. |
|
|
1908 | |
|
|
1909 | The benchmark itself creates an echo-server, and then, for 500 times, |
|
|
1910 | connects to the echo server, sends a line, waits for the reply, and then |
|
|
1911 | creates the next connection. This is a rather bad benchmark, as it doesn't |
|
|
1912 | test the efficiency of the framework or much non-blocking I/O, but it is a |
|
|
1913 | benchmark 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 | |
|
|
1929 | The benchmark is also a bit unfair (my fault): the IO::Lambda/POE |
|
|
1930 | benchmarks actually make blocking connects and use 100% blocking I/O, |
|
|
1931 | defeating the purpose of an event-based solution. All of the newly |
|
|
1932 | written AnyEvent benchmarks use 100% non-blocking connects (using |
|
|
1933 | AnyEvent::Socket::tcp_connect and the asynchronous pure perl DNS |
|
|
1934 | resolver), so AnyEvent is at a disadvantage here, as non-blocking connects |
|
|
1935 | generally require a lot more bookkeeping and event handling than blocking |
|
|
1936 | connects (which involve a single syscall only). |
|
|
1937 | |
|
|
1938 | The last AnyEvent benchmark additionally uses L<AnyEvent::Handle>, which |
|
|
1939 | offers similar expressive power as POE and IO::Lambda, using conventional |
|
|
1940 | Perl syntax. This means that both the echo server and the client are 100% |
|
|
1941 | non-blocking, further placing it at a disadvantage. |
|
|
1942 | |
|
|
1943 | As you can see, the AnyEvent + EV combination even beats the |
|
|
1944 | hand-optimised "raw sockets benchmark", while AnyEvent + its pure perl |
|
|
1945 | backend easily beats IO::Lambda and POE. |
|
|
1946 | |
|
|
1947 | And even the 100% non-blocking version written using the high-level (and |
|
|
1948 | slow :) L<AnyEvent::Handle> abstraction beats both POE and IO::Lambda by a |
|
|
1949 | large margin, even though it does all of DNS, tcp-connect and socket I/O |
|
|
1950 | in a non-blocking way. |
|
|
1951 | |
|
|
1952 | The two AnyEvent benchmarks programs can be found as F<eg/ae0.pl> and |
|
|
1953 | F<eg/ae2.pl> in the AnyEvent distribution, the remaining benchmarks are |
|
|
1954 | part of the IO::lambda distribution and were used without any changes. |
|
|
1955 | |
1892 | |
1956 | |
1893 | =head1 SIGNALS |
1957 | =head1 SIGNALS |
1894 | |
1958 | |
1895 | AnyEvent currently installs handlers for these signals: |
1959 | AnyEvent currently installs handlers for these signals: |
1896 | |
1960 | |
… | |
… | |
1955 | Similar considerations apply to $ENV{PERL_ANYEVENT_VERBOSE}, as that can |
2019 | Similar considerations apply to $ENV{PERL_ANYEVENT_VERBOSE}, as that can |
1956 | be used to probe what backend is used and gain other information (which is |
2020 | be used to probe what backend is used and gain other information (which is |
1957 | probably even less useful to an attacker than PERL_ANYEVENT_MODEL), and |
2021 | probably even less useful to an attacker than PERL_ANYEVENT_MODEL), and |
1958 | $ENV{PERL_ANYEVENT_STRICT}. |
2022 | $ENV{PERL_ANYEVENT_STRICT}. |
1959 | |
2023 | |
|
|
2024 | Note that AnyEvent will remove I<all> environment variables starting with |
|
|
2025 | C<PERL_ANYEVENT_> from C<%ENV> when it is loaded while taint mode is |
|
|
2026 | enabled. |
|
|
2027 | |
1960 | |
2028 | |
1961 | =head1 BUGS |
2029 | =head1 BUGS |
1962 | |
2030 | |
1963 | Perl 5.8 has numerous memleaks that sometimes hit this module and are hard |
2031 | Perl 5.8 has numerous memleaks that sometimes hit this module and are hard |
1964 | to work around. If you suffer from memleaks, first upgrade to Perl 5.10 |
2032 | to work around. If you suffer from memleaks, first upgrade to Perl 5.10 |