… | |
… | |
34 | This module only creates processes and lets you pass file handles and |
34 | This module only creates processes and lets you pass file handles and |
35 | strings to it, and run perl code. It does not implement any kind of RPC - |
35 | strings to it, and run perl code. It does not implement any kind of RPC - |
36 | there is no back channel from the process back to you, and there is no RPC |
36 | there is no back channel from the process back to you, and there is no RPC |
37 | or message passing going on. |
37 | or message passing going on. |
38 | |
38 | |
39 | If you need some form of RPC, you can either implement it yourself |
39 | If you need some form of RPC, you could use the L<AnyEvent::Fork::RPC> |
40 | in whatever way you like, use some message-passing module such |
40 | companion module, which adds simple RPC/job queueing to a process created |
41 | as L<AnyEvent::MP>, some pipe such as L<AnyEvent::ZeroMQ>, use |
41 | by this module. |
42 | L<AnyEvent::Handle> on both sides to send e.g. JSON or Storable messages, |
42 | |
43 | and so on. |
43 | Or you can implement it yourself in whatever way you like, use some |
|
|
44 | message-passing module such as L<AnyEvent::MP>, some pipe such as |
|
|
45 | L<AnyEvent::ZeroMQ>, use L<AnyEvent::Handle> on both sides to send |
|
|
46 | e.g. JSON or Storable messages, and so on. |
44 | |
47 | |
45 | =head2 COMPARISON TO OTHER MODULES |
48 | =head2 COMPARISON TO OTHER MODULES |
46 | |
49 | |
47 | There is an abundance of modules on CPAN that do "something fork", such as |
50 | There is an abundance of modules on CPAN that do "something fork", such as |
48 | L<Parallel::ForkManager>, L<AnyEvent::ForkManager>, L<AnyEvent::Worker> |
51 | L<Parallel::ForkManager>, L<AnyEvent::ForkManager>, L<AnyEvent::Worker> |
… | |
… | |
371 | use AnyEvent::Util (); |
374 | use AnyEvent::Util (); |
372 | |
375 | |
373 | use IO::FDPass; |
376 | use IO::FDPass; |
374 | |
377 | |
375 | our $VERSION = 0.6; |
378 | our $VERSION = 0.6; |
376 | |
|
|
377 | =over 4 |
|
|
378 | |
|
|
379 | =back |
|
|
380 | |
|
|
381 | =cut |
|
|
382 | |
379 | |
383 | # the early fork template process |
380 | # the early fork template process |
384 | our $EARLY; |
381 | our $EARLY; |
385 | |
382 | |
386 | # the empty template process |
383 | # the empty template process |
… | |
… | |
804 | So how can C<< AnyEvent->new >> be faster than a standard fork, even |
801 | So how can C<< AnyEvent->new >> be faster than a standard fork, even |
805 | though it uses the same operations, but adds a lot of overhead? |
802 | though it uses the same operations, but adds a lot of overhead? |
806 | |
803 | |
807 | The difference is simply the process size: forking the 5MB process takes |
804 | The difference is simply the process size: forking the 5MB process takes |
808 | so much longer than forking the 2.5MB template process that the extra |
805 | so much longer than forking the 2.5MB template process that the extra |
809 | overhead introduced is canceled out. |
806 | overhead is canceled out. |
810 | |
807 | |
811 | If the benchmark process grows, the normal fork becomes even slower: |
808 | If the benchmark process grows, the normal fork becomes even slower: |
812 | |
809 | |
813 | 1340 new processes, manual fork of a 20MB process |
810 | 1340 new processes, manual fork of a 20MB process |
814 | 731 new processes, manual fork of a 200MB process |
811 | 731 new processes, manual fork of a 200MB process |
… | |
… | |
913 | |
910 | |
914 | L<AnyEvent::Fork::Early> (to avoid executing a perl interpreter), |
911 | L<AnyEvent::Fork::Early> (to avoid executing a perl interpreter), |
915 | L<AnyEvent::Fork::Template> (to create a process by forking the main |
912 | L<AnyEvent::Fork::Template> (to create a process by forking the main |
916 | program at a convenient time). |
913 | program at a convenient time). |
917 | |
914 | |
918 | =head1 AUTHOR |
915 | =head1 AUTHOR AND CONTACT INFORMATION |
919 | |
916 | |
920 | Marc Lehmann <schmorp@schmorp.de> |
917 | Marc Lehmann <schmorp@schmorp.de> |
921 | http://home.schmorp.de/ |
918 | http://software.schmorp.de/pkg/AnyEvent-Fork |
922 | |
919 | |
923 | =cut |
920 | =cut |
924 | |
921 | |
925 | 1 |
922 | 1 |
926 | |
923 | |