… | |
… | |
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 | |
… | |
… | |
1366 | =item C<PERL_ANYEVENT_STRICT> |
1366 | =item C<PERL_ANYEVENT_STRICT> |
1367 | |
1367 | |
1368 | AnyEvent does not do much argument checking by default, as thorough |
1368 | AnyEvent does not do much argument checking by default, as thorough |
1369 | 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 |
1370 | 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 |
1371 | 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, |
1372 | it will croak. |
1372 | it will croak. |
1373 | |
1373 | |
1374 | In other words, enables "strict" mode. |
1374 | In other words, enables "strict" mode. |
1375 | |
1375 | |
1376 | 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 |
1377 | production. Keeping C<PERL_ANYEVENT_STRICT=1> in your environment while |
1377 | production. Keeping C<PERL_ANYEVENT_STRICT=1> in your environment while |
1378 | developing programs can be very useful, however. |
1378 | developing programs can be very useful, however. |
1379 | |
1379 | |
1380 | =item C<PERL_ANYEVENT_MODEL> |
1380 | =item C<PERL_ANYEVENT_MODEL> |
1381 | |
1381 | |
… | |
… | |
1900 | |
1900 | |
1901 | Recently I was told about the benchmark in the IO::Lambda manpage, which |
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 |
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 |
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 |
1904 | shouldn't come as a surprise to anybody). As such, the benchmark is |
1905 | fine, and shows that the AnyEvent backend from IO::Lambda isn't very |
1905 | fine, and mostly shows that the AnyEvent backend from IO::Lambda isn't |
1906 | optimal. But how would AnyEvent compare when used without the extra |
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. |
1907 | baggage? To explore this, I wrote the equivalent benchmark for AnyEvent. |
1908 | |
1908 | |
1909 | The benchmark itself creates an echo-server, and then, for 500 times, |
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 |
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 |
1911 | creates the next connection. This is a rather bad benchmark, as it doesn't |
1912 | test the efficiency of the framework, but it is a benchmark nevertheless. |
1912 | test the efficiency of the framework or much non-blocking I/O, but it is a |
|
|
1913 | benchmark nevertheless. |
1913 | |
1914 | |
1914 | name runtime |
1915 | name runtime |
1915 | Lambda/select 0.330 sec |
1916 | Lambda/select 0.330 sec |
1916 | + optimized 0.122 sec |
1917 | + optimized 0.122 sec |
1917 | Lambda/AnyEvent 0.327 sec |
1918 | Lambda/AnyEvent 0.327 sec |
… | |
… | |
1923 | |
1924 | |
1924 | AnyEvent/select/nb 0.085 sec |
1925 | AnyEvent/select/nb 0.085 sec |
1925 | AnyEvent/EV/nb 0.068 sec |
1926 | AnyEvent/EV/nb 0.068 sec |
1926 | +state machine 0.134 sec |
1927 | +state machine 0.134 sec |
1927 | |
1928 | |
1928 | The benchmark is also a bit unfair (my fault) - the IO::Lambda |
1929 | The benchmark is also a bit unfair (my fault): the IO::Lambda/POE |
1929 | benchmarks actually make blocking connects and use 100% blocking I/O, |
1930 | benchmarks actually make blocking connects and use 100% blocking I/O, |
1930 | defeating the purpose of an event-based solution. All of the newly |
1931 | defeating the purpose of an event-based solution. All of the newly |
1931 | written AnyEvent benchmarks use 100% non-blocking connects (using |
1932 | written AnyEvent benchmarks use 100% non-blocking connects (using |
1932 | AnyEvent::Socket::tcp_connect and the asynchronous pure perl DNS |
1933 | AnyEvent::Socket::tcp_connect and the asynchronous pure perl DNS |
1933 | resolver), so AnyEvent is at a disadvantage here as non-blocking connects |
1934 | resolver), so AnyEvent is at a disadvantage here, as non-blocking connects |
1934 | generally require a lot more bookkeeping and event handling than blocking |
1935 | generally require a lot more bookkeeping and event handling than blocking |
1935 | connects (which involve a single syscall only). |
1936 | connects (which involve a single syscall only). |
1936 | |
1937 | |
1937 | The last AnyEvent benchmark additionally uses L<AnyEvent::Handle>, which |
1938 | The last AnyEvent benchmark additionally uses L<AnyEvent::Handle>, which |
1938 | offers similar expressive power as POE and IO::Lambda (using conventional |
1939 | offers similar expressive power as POE and IO::Lambda, using conventional |
1939 | Perl syntax), which means both the echo server and the client are 100% |
1940 | Perl syntax. This means that both the echo server and the client are 100% |
1940 | non-blocking w.r.t. I/O, further placing it at a disadvantage. |
1941 | non-blocking, further placing it at a disadvantage. |
1941 | |
1942 | |
1942 | As you can see, AnyEvent + EV even beats the hand-optimised "raw sockets |
1943 | As you can see, the AnyEvent + EV combination even beats the |
1943 | benchmark", while AnyEvent + its pure perl backend easily beats |
1944 | hand-optimised "raw sockets benchmark", while AnyEvent + its pure perl |
1944 | IO::Lambda and POE. |
1945 | backend easily beats IO::Lambda and POE. |
1945 | |
1946 | |
1946 | And even the 100% non-blocking version written using the high-level (and |
1947 | And even the 100% non-blocking version written using the high-level (and |
1947 | slow :) L<AnyEvent::Handle> abstraction beats both POE and IO::Lambda, |
1948 | slow :) L<AnyEvent::Handle> abstraction beats both POE and IO::Lambda by a |
1948 | even thought it does all of DNS, tcp-connect and socket I/O in a |
1949 | large margin, even though it does all of DNS, tcp-connect and socket I/O |
1949 | non-blocking way. |
1950 | in a non-blocking way. |
1950 | |
1951 | |
1951 | The two AnyEvent benchmarks can be found as F<eg/ae0.pl> and F<eg/ae2.pl> |
1952 | The two AnyEvent benchmarks programs can be found as F<eg/ae0.pl> and |
1952 | in the AnyEvent distribution, the remaining benchmarks are part of the |
1953 | F<eg/ae2.pl> in the AnyEvent distribution, the remaining benchmarks are |
1953 | IO::lambda distribution and were used without any changes. |
1954 | part of the IO::lambda distribution and were used without any changes. |
1954 | |
1955 | |
1955 | |
1956 | |
1956 | =head1 SIGNALS |
1957 | =head1 SIGNALS |
1957 | |
1958 | |
1958 | AnyEvent currently installs handlers for these signals: |
1959 | AnyEvent currently installs handlers for these signals: |
… | |
… | |
2018 | Similar considerations apply to $ENV{PERL_ANYEVENT_VERBOSE}, as that can |
2019 | Similar considerations apply to $ENV{PERL_ANYEVENT_VERBOSE}, as that can |
2019 | 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 |
2020 | 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 |
2021 | $ENV{PERL_ANYEVENT_STRICT}. |
2022 | $ENV{PERL_ANYEVENT_STRICT}. |
2022 | |
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 | |
2023 | |
2028 | |
2024 | =head1 BUGS |
2029 | =head1 BUGS |
2025 | |
2030 | |
2026 | 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 |
2027 | 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 |