ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/AnyEvent-Fork/Fork.pm
(Generate patch)

Comparing AnyEvent-Fork/Fork.pm (file contents):
Revision 1.35 by root, Sat Apr 6 09:39:12 2013 UTC vs.
Revision 1.36 by root, Sat Apr 6 09:43:15 2013 UTC

780 479 vfork+execs per second, using AnyEvent::Fork->new_exec 780 479 vfork+execs per second, using AnyEvent::Fork->new_exec
781 781
782So how can C<< AnyEvent->new >> be faster than a standard fork, even 782So how can C<< AnyEvent->new >> be faster than a standard fork, even
783though it uses the same operations, but adds a lot of overhead? 783though it uses the same operations, but adds a lot of overhead?
784 784
785The difference is simply the process size: forking the 6MB process takes 785The difference is simply the process size: forking the 5MB process takes
786so much longer than forking the 2.5MB template process that the overhead 786so much longer than forking the 2.5MB template process that the extra
787introduced is canceled out. 787overhead introduced is canceled out.
788 788
789If the benchmark process grows, the normal fork becomes even slower: 789If the benchmark process grows, the normal fork becomes even slower:
790 790
791 1340 new processes, manual fork in a 20MB process 791 1340 new processes, manual fork of a 20MB process
792 731 new processes, manual fork in a 200MB process 792 731 new processes, manual fork of a 200MB process
793 235 new processes, manual fork in a 2000MB process 793 235 new processes, manual fork of a 2000MB process
794 794
795What that means (to me) is that I can use this module without having a 795What that means (to me) is that I can use this module without having a bad
796very bad conscience because of the extra overhead required to start new 796conscience because of the extra overhead required to start new processes.
797processes.
798 797
799=head1 TYPICAL PROBLEMS 798=head1 TYPICAL PROBLEMS
800 799
801This section lists typical problems that remain. I hope by recognising 800This section lists typical problems that remain. I hope by recognising
802them, most can be avoided. 801them, most can be avoided.
803 802
804=over 4 803=over 4
805 804
806=item "leaked" file descriptors for exec'ed processes 805=item leaked file descriptors for exec'ed processes
807 806
808POSIX systems inherit file descriptors by default when exec'ing a new 807POSIX systems inherit file descriptors by default when exec'ing a new
809process. While perl itself laudably sets the close-on-exec flags on new 808process. While perl itself laudably sets the close-on-exec flags on new
810file handles, most C libraries don't care, and even if all cared, it's 809file handles, most C libraries don't care, and even if all cared, it's
811often not possible to set the flag in a race-free manner. 810often not possible to set the flag in a race-free manner.
831libraries or the code that leaks those file descriptors. 830libraries or the code that leaks those file descriptors.
832 831
833Fortunately, most of these leaked descriptors do no harm, other than 832Fortunately, most of these leaked descriptors do no harm, other than
834sitting on some resources. 833sitting on some resources.
835 834
836=item "leaked" file descriptors for fork'ed processes 835=item leaked file descriptors for fork'ed processes
837 836
838Normally, L<AnyEvent::Fork> does start new processes by exec'ing them, 837Normally, L<AnyEvent::Fork> does start new processes by exec'ing them,
839which closes file descriptors not marked for being inherited. 838which closes file descriptors not marked for being inherited.
840 839
841However, L<AnyEvent::Fork::Early> and L<AnyEvent::Fork::Template> offer 840However, L<AnyEvent::Fork::Early> and L<AnyEvent::Fork::Template> offer
882to make it so, mostly due to the bloody broken perl that nobody seems to 881to make it so, mostly due to the bloody broken perl that nobody seems to
883care about. The fork emulation is a bad joke - I have yet to see something 882care about. The fork emulation is a bad joke - I have yet to see something
884useful that you can do with it without running into memory corruption 883useful that you can do with it without running into memory corruption
885issues or other braindamage. Hrrrr. 884issues or other braindamage. Hrrrr.
886 885
887Cygwin perl is not supported at the moment, as it should implement fd 886Cygwin perl is not supported at the moment due to some hilarious
888passing, but doesn't, and rolling my own is hard, as cygwin doesn't 887shortcomings of its API - see L<IO::FDPoll> for more details.
889support enough functionality to do it.
890 888
891=head1 SEE ALSO 889=head1 SEE ALSO
892 890
893L<AnyEvent::Fork::Early> (to avoid executing a perl interpreter), 891L<AnyEvent::Fork::Early> (to avoid executing a perl interpreter),
894L<AnyEvent::Fork::Template> (to create a process by forking the main 892L<AnyEvent::Fork::Template> (to create a process by forking the main

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines