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