… | |
… | |
65 | technically possible. |
65 | technically possible. |
66 | |
66 | |
67 | Of course, if you want lots of policy (this can arguably be somewhat |
67 | Of course, if you want lots of policy (this can arguably be somewhat |
68 | useful) and you want to force your users to use the one and only event |
68 | useful) and you want to force your users to use the one and only event |
69 | model, you should I<not> use this module. |
69 | model, you should I<not> use this module. |
70 | |
|
|
71 | #TODO# |
|
|
72 | |
|
|
73 | Net::IRC3 |
|
|
74 | AnyEvent::HTTPD |
|
|
75 | AnyEvent::DNS |
|
|
76 | IO::AnyEvent |
|
|
77 | Net::FPing |
|
|
78 | Net::XMPP2 |
|
|
79 | Coro |
|
|
80 | |
|
|
81 | AnyEvent::IRC |
|
|
82 | AnyEvent::HTTPD |
|
|
83 | AnyEvent::DNS |
|
|
84 | AnyEvent::Handle |
|
|
85 | AnyEvent::Socket |
|
|
86 | AnyEvent::FPing |
|
|
87 | AnyEvent::XMPP |
|
|
88 | AnyEvent::SNMP |
|
|
89 | Coro |
|
|
90 | |
70 | |
91 | =head1 DESCRIPTION |
71 | =head1 DESCRIPTION |
92 | |
72 | |
93 | L<AnyEvent> provides an identical interface to multiple event loops. This |
73 | L<AnyEvent> provides an identical interface to multiple event loops. This |
94 | allows module authors to utilise an event loop without forcing module |
74 | allows module authors to utilise an event loop without forcing module |
… | |
… | |
410 | |
390 | |
411 | AnyEvent::Impl::CoroEV based on Coro::EV, best choice. |
391 | AnyEvent::Impl::CoroEV based on Coro::EV, best choice. |
412 | AnyEvent::Impl::CoroEvent based on Coro::Event, second best choice. |
392 | AnyEvent::Impl::CoroEvent based on Coro::Event, second best choice. |
413 | AnyEvent::Impl::EV based on EV (an interface to libev, best choice). |
393 | AnyEvent::Impl::EV based on EV (an interface to libev, best choice). |
414 | AnyEvent::Impl::Event based on Event, second best choice. |
394 | AnyEvent::Impl::Event based on Event, second best choice. |
|
|
395 | AnyEvent::Impl::Perl pure-perl implementation, fast and portable. |
415 | AnyEvent::Impl::Glib based on Glib, third-best choice. |
396 | AnyEvent::Impl::Glib based on Glib, third-best choice. |
416 | AnyEvent::Impl::Perl pure-perl implementation, inefficient but portable. |
|
|
417 | AnyEvent::Impl::Tk based on Tk, very bad choice. |
397 | AnyEvent::Impl::Tk based on Tk, very bad choice. |
418 | AnyEvent::Impl::Qt based on Qt, cannot be autoprobed (see its docs). |
398 | AnyEvent::Impl::Qt based on Qt, cannot be autoprobed (see its docs). |
419 | AnyEvent::Impl::EventLib based on Event::Lib, leaks memory and worse. |
399 | AnyEvent::Impl::EventLib based on Event::Lib, leaks memory and worse. |
420 | AnyEvent::Impl::POE based on POE, not generic enough for full support. |
400 | AnyEvent::Impl::POE based on POE, not generic enough for full support. |
421 | |
401 | |
… | |
… | |
479 | loading the C<AnyEvent::Impl::Perl> module, which gives you similar |
459 | loading the C<AnyEvent::Impl::Perl> module, which gives you similar |
480 | behaviour everywhere, but letting AnyEvent chose is generally better. |
460 | behaviour everywhere, but letting AnyEvent chose is generally better. |
481 | |
461 | |
482 | =head1 OTHER MODULES |
462 | =head1 OTHER MODULES |
483 | |
463 | |
484 | L<AnyEvent> itself comes with useful utility modules: |
464 | The following is a non-exhaustive list of additional modules that use |
485 | |
465 | AnyEvent and can therefore be mixed easily with other AnyEvent modules |
486 | To make it easier to do non-blocking IO the modules L<AnyEvent::Handle> |
466 | in the same program. Some of the modules come with AnyEvent, some are |
487 | and L<AnyEvent::Socket> are provided. L<AnyEvent::Handle> provides |
467 | available via CPAN. |
488 | read and write buffers and manages watchers for reads and writes. |
|
|
489 | L<AnyEvent::Socket> provides means to do non-blocking connects. |
|
|
490 | |
|
|
491 | Aside from those there are these modules that support AnyEvent (and use it |
|
|
492 | for non-blocking IO): |
|
|
493 | |
468 | |
494 | =over 4 |
469 | =over 4 |
495 | |
470 | |
|
|
471 | =item L<AnyEvent::Util> |
|
|
472 | |
|
|
473 | Contains various utility functions that replace often-used but blocking |
|
|
474 | functions such as C<inet_aton> by event-/callback-based versions. |
|
|
475 | |
|
|
476 | =item L<AnyEvent::Handle> |
|
|
477 | |
|
|
478 | Provide read and write buffers and manages watchers for reads and writes. |
|
|
479 | |
|
|
480 | =item L<AnyEvent::Socket> |
|
|
481 | |
|
|
482 | Provides a means to do non-blocking connects, accepts etc. |
|
|
483 | |
|
|
484 | =item L<AnyEvent::HTTPD> |
|
|
485 | |
|
|
486 | Provides a simple web application server framework. |
|
|
487 | |
|
|
488 | =item L<AnyEvent::DNS> |
|
|
489 | |
|
|
490 | Provides asynchronous DNS resolver capabilities, beyond what |
|
|
491 | L<AnyEvent::Util> offers. |
|
|
492 | |
496 | =item L<AnyEvent::FastPing> |
493 | =item L<AnyEvent::FastPing> |
497 | |
494 | |
|
|
495 | The fastest ping in the west. |
|
|
496 | |
498 | =item L<Net::IRC3> |
497 | =item L<Net::IRC3> |
499 | |
498 | |
|
|
499 | AnyEvent based IRC client module family. |
|
|
500 | |
500 | =item L<Net::XMPP2> |
501 | =item L<Net::XMPP2> |
|
|
502 | |
|
|
503 | AnyEvent based XMPP (Jabber protocol) module family. |
|
|
504 | |
|
|
505 | =item L<Net::FCP> |
|
|
506 | |
|
|
507 | AnyEvent-based implementation of the Freenet Client Protocol, birthplace |
|
|
508 | of AnyEvent. |
|
|
509 | |
|
|
510 | =item L<Event::ExecFlow> |
|
|
511 | |
|
|
512 | High level API for event-based execution flow control. |
|
|
513 | |
|
|
514 | =item L<Coro> |
|
|
515 | |
|
|
516 | Has special support for AnyEvent. |
|
|
517 | |
|
|
518 | =item L<IO::Lambda> |
|
|
519 | |
|
|
520 | The lambda approach to I/O - don't ask, look there. Can use AnyEvent. |
|
|
521 | |
|
|
522 | =item L<IO::AIO> |
|
|
523 | |
|
|
524 | Truly asynchronous I/O, should be in the toolbox of every event |
|
|
525 | programmer. Can be trivially made to use AnyEvent. |
|
|
526 | |
|
|
527 | =item L<BDB> |
|
|
528 | |
|
|
529 | Truly asynchronous Berkeley DB access. Can be trivially made to use |
|
|
530 | AnyEvent. |
501 | |
531 | |
502 | =back |
532 | =back |
503 | |
533 | |
504 | =cut |
534 | =cut |
505 | |
535 | |
… | |
… | |
523 | my @models = ( |
553 | my @models = ( |
524 | [Coro::EV:: => AnyEvent::Impl::CoroEV::], |
554 | [Coro::EV:: => AnyEvent::Impl::CoroEV::], |
525 | [Coro::Event:: => AnyEvent::Impl::CoroEvent::], |
555 | [Coro::Event:: => AnyEvent::Impl::CoroEvent::], |
526 | [EV:: => AnyEvent::Impl::EV::], |
556 | [EV:: => AnyEvent::Impl::EV::], |
527 | [Event:: => AnyEvent::Impl::Event::], |
557 | [Event:: => AnyEvent::Impl::Event::], |
528 | [Glib:: => AnyEvent::Impl::Glib::], |
|
|
529 | [Tk:: => AnyEvent::Impl::Tk::], |
558 | [Tk:: => AnyEvent::Impl::Tk::], |
530 | [Wx:: => AnyEvent::Impl::POE::], |
559 | [Wx:: => AnyEvent::Impl::POE::], |
531 | [Prima:: => AnyEvent::Impl::POE::], |
560 | [Prima:: => AnyEvent::Impl::POE::], |
532 | [AnyEvent::Impl::Perl:: => AnyEvent::Impl::Perl::], |
561 | [AnyEvent::Impl::Perl:: => AnyEvent::Impl::Perl::], |
533 | # everything below here will not be autoprobed as the pureperl backend should work everywhere |
562 | # everything below here will not be autoprobed as the pureperl backend should work everywhere |
|
|
563 | [Glib:: => AnyEvent::Impl::Glib::], |
534 | [Event::Lib:: => AnyEvent::Impl::EventLib::], # too buggy |
564 | [Event::Lib:: => AnyEvent::Impl::EventLib::], # too buggy |
535 | [Qt:: => AnyEvent::Impl::Qt::], # requires special main program |
565 | [Qt:: => AnyEvent::Impl::Qt::], # requires special main program |
536 | [POE::Kernel:: => AnyEvent::Impl::POE::], # lasciate ogni speranza |
566 | [POE::Kernel:: => AnyEvent::Impl::POE::], # lasciate ogni speranza |
537 | ); |
567 | ); |
538 | |
568 | |
… | |
… | |
1041 | file descriptor is dup()ed for each watcher. This shows that the dup() |
1071 | file descriptor is dup()ed for each watcher. This shows that the dup() |
1042 | employed by some adaptors is not a big performance issue (it does incur a |
1072 | employed by some adaptors is not a big performance issue (it does incur a |
1043 | hidden memory cost inside the kernel which is not reflected in the figures |
1073 | hidden memory cost inside the kernel which is not reflected in the figures |
1044 | above). |
1074 | above). |
1045 | |
1075 | |
1046 | C<POE>, regardless of underlying event loop (whether using its pure |
1076 | C<POE>, regardless of underlying event loop (whether using its pure perl |
1047 | perl select-based backend or the Event module, the POE-EV backend |
1077 | select-based backend or the Event module, the POE-EV backend couldn't |
1048 | couldn't be tested because it wasn't working) shows abysmal performance |
1078 | be tested because it wasn't working) shows abysmal performance and |
1049 | and memory usage: Watchers use almost 30 times as much memory as |
1079 | memory usage with AnyEvent: Watchers use almost 30 times as much memory |
1050 | EV watchers, and 10 times as much memory as Event (the high memory |
1080 | as EV watchers, and 10 times as much memory as Event (the high memory |
1051 | requirements are caused by requiring a session for each watcher). Watcher |
1081 | requirements are caused by requiring a session for each watcher). Watcher |
1052 | invocation speed is almost 900 times slower than with AnyEvent's pure perl |
1082 | invocation speed is almost 900 times slower than with AnyEvent's pure perl |
|
|
1083 | implementation. |
|
|
1084 | |
1053 | implementation. The design of the POE adaptor class in AnyEvent can not |
1085 | The design of the POE adaptor class in AnyEvent can not really account |
1054 | really account for this, as session creation overhead is small compared |
1086 | for the performance issues, though, as session creation overhead is |
1055 | to execution of the state machine, which is coded pretty optimally within |
1087 | small compared to execution of the state machine, which is coded pretty |
1056 | L<AnyEvent::Impl::POE>. POE simply seems to be abysmally slow. |
1088 | optimally within L<AnyEvent::Impl::POE> (and while everybody agrees that |
|
|
1089 | using multiple sessions is not a good approach, especially regarding |
|
|
1090 | memory usage, even the author of POE could not come up with a faster |
|
|
1091 | design). |
1057 | |
1092 | |
1058 | =head3 Summary |
1093 | =head3 Summary |
1059 | |
1094 | |
1060 | =over 4 |
1095 | =over 4 |
1061 | |
1096 | |
… | |
… | |
1140 | |
1175 | |
1141 | =head3 Summary |
1176 | =head3 Summary |
1142 | |
1177 | |
1143 | =over 4 |
1178 | =over 4 |
1144 | |
1179 | |
1145 | =item * The pure perl implementation performs extremely well, considering |
1180 | =item * The pure perl implementation performs extremely well. |
1146 | that it uses select. |
|
|
1147 | |
1181 | |
1148 | =item * Avoid Glib or POE in large projects where performance matters. |
1182 | =item * Avoid Glib or POE in large projects where performance matters. |
1149 | |
1183 | |
1150 | =back |
1184 | =back |
1151 | |
1185 | |
… | |
… | |
1180 | speed most when you have lots of watchers, not when you only have a few of |
1214 | speed most when you have lots of watchers, not when you only have a few of |
1181 | them). |
1215 | them). |
1182 | |
1216 | |
1183 | EV is again fastest. |
1217 | EV is again fastest. |
1184 | |
1218 | |
1185 | The C-based event loops Event and Glib come in second this time, as the |
1219 | Perl again comes second. It is noticably faster than the C-based event |
1186 | overhead of running an iteration is much smaller in C than in Perl (little |
1220 | loops Event and Glib, although the difference is too small to really |
1187 | code to execute in the inner loop, and perl's function calling overhead is |
1221 | matter. |
1188 | high, and updating all the data structures is costly). |
|
|
1189 | |
|
|
1190 | The pure perl event loop is much slower, but still competitive. |
|
|
1191 | |
1222 | |
1192 | POE also performs much better in this case, but is is still far behind the |
1223 | POE also performs much better in this case, but is is still far behind the |
1193 | others. |
1224 | others. |
1194 | |
1225 | |
1195 | =head3 Summary |
1226 | =head3 Summary |
… | |
… | |
1203 | |
1234 | |
1204 | |
1235 | |
1205 | =head1 FORK |
1236 | =head1 FORK |
1206 | |
1237 | |
1207 | Most event libraries are not fork-safe. The ones who are usually are |
1238 | Most event libraries are not fork-safe. The ones who are usually are |
1208 | because they are so inefficient. Only L<EV> is fully fork-aware. |
1239 | because they rely on inefficient but fork-safe C<select> or C<poll> |
|
|
1240 | calls. Only L<EV> is fully fork-aware. |
1209 | |
1241 | |
1210 | If you have to fork, you must either do so I<before> creating your first |
1242 | If you have to fork, you must either do so I<before> creating your first |
1211 | watcher OR you must not use AnyEvent at all in the child. |
1243 | watcher OR you must not use AnyEvent at all in the child. |
1212 | |
1244 | |
1213 | |
1245 | |