List:General Discussion« Previous MessageNext Message »
From:Sasha Pachev Date:May 7 1999 3:53am
Subject:How fast can a daemon stick a fork() into your ribs?
View as plain text  
There was a discussion on this list lately about C vs PHP. Somebody
suggested that PHP parsing could be finished before a forked process
would even have a chance to start. I began to wonder about the speed of
fork() and wrote a rather crude benchmark to estimate the amount of time
consumed by the overhead of fork() + execve(). The benchmark is very
simple: We fork off childern in a loop, each child calls execl() to
start a dummy process which as simple as I could make it in C:
 int main { return 0;}

After a child is forked, the parent does a waitpid() for it. Overall
time (not just CPU, so if you have many processes, the benchmark will
not be quite accurate) will be divided by the number of forked childeren
which gives us an estimate of fork() +  execl().

Anyway, if you are curious about this subject, download the source from
http://www.sashanet.com/internet/download/fork_bench.tar.gz , drop it
into a new directory, gunzip -c fork_bench.tar.gz | tar xvf - ; make run
and see the results. You might want to do make run a few times to see if
the results change. If you find some glaring faults in the code, feel
free to let me/everyone know or better - patch them if you can.

Here is what I got on my systems:

Static parent/Dynamic child
# fork_bench test on Linux 2.0.33 www.sashanet.com i586   : Pentium 166
32 MB EDO RAM 
Avg fork() + execl() time = 8.36 ms
Static parent/Static child
# fork_bench test on Linux 2.0.33 www.sashanet.com i586   : Pentium 166
32 MB EDO RAM 
Avg fork() + execl() time = 1.95 ms
Dynamic parent/Dynamic child
# fork_bench test on Linux 2.0.33 www.sashanet.com i586   : Pentium 166
32 MB EDO RAM 
Avg fork() + execl() time = 8.80 ms
Dynamic parent/Static child
# fork_bench test on Linux 2.0.33 www.sashanet.com i586   : Pentium 166
32 MB EDO RAM 
Avg fork() + execl() time = 2.48 ms

Static parent/Dynamic child
# fork_bench test on Linux 2.0.36 www.isshost.com i686   : Pentium II
350 128 MB SDRAM 
Avg fork() + execl() time = 2.31 ms
Static parent/Static child
# fork_bench test on Linux 2.0.36 www.isshost.com i686   : Pentium II
350 128 MB SDRAM 
Avg fork() + execl() time = 0.43 ms
Dynamic parent/Dynamic child
# fork_bench test on Linux 2.0.36 www.isshost.com i686   : Pentium II
350 128 MB SDRAM 
Avg fork() + execl() time = 2.45 ms
Dynamic parent/Static child
# fork_bench test on Linux 2.0.36 www.isshost.com i686   : Pentium II
350 128 MB SDRAM 
Avg fork() + execl() time = 0.55 ms



I'd be interested to see what you get on others. From the results I got,
it seems that unless your server(Intel hardware/Linux) gets hit in the
order of magnitude of 1000 times per second, the overhead of fork() +
execve()  is relatively insignificant. Correct me if my interpretation
of the results is in error.

-- 
Sasha Pachev
http://www.sashanet.com
Thread
How fast can a daemon stick a fork() into your ribs?Sasha Pachev7 May
  • Re: How fast can a daemon stick a fork() into your ribs?Dan Nelson7 May
  • Re: How fast can a daemon stick a fork() into your ribs?Orlando Andico7 May
  • Re: How fast can a daemon stick a fork() into your ribs?Kevin Ying7 May