Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

The problem child for classic CGI is Windows, where process creation is 100x slower than any other POSIX implementation.

You can measure this easily, get a copy of Windows busybox and write a shell script that forks off a process a few thousand times. The performance difference is stark.






That's interesting. I hadn't thought about that. Still, fork() (plus _exit() and wait()) takes 0.7ms in Termux on my phone for small processes, as measured by http://canonical.org/~kragen/sw/dev3/forkovh.c.

Are you really saying that it takes 70ms on Microsoft Windows? I don't have an installed copy here to test.

Even if it does, that would still be about 15% of the time required for `python3 -m cgi`, so it seems unlikely to be an overriding concern for CGI programs written in Python, at least on manycore servers serving less than tens of millions of hits per day. Or does it also fail to scale across cores?


Let's consider ten thousand forks.

  $ cat winforktest.sh
  #!/home/busybox-1.35 sh

  i=1; while [ $i -lt 10000 ]; do (echo $i); i=$((i+1)); done
On Linux, this takes:

  $  cat /etc/redhat-release
  Red Hat Enterprise Linux release 8.10 (Ootpa)

  $ time ./winforktest.sh > /dev/null
  real    0m0.792s
  user    0m0.490s
  sys     0m0.361s
On Windows,

  c:\users\x>ver

  Microsoft Windows [Version 10.0.22631.5472]

  c:\users\x>busybox | busybox head -2
  BusyBox v1.37.0-FRP-5236-g7dff7f376 (2023-12-06 10:31:32 GMT)
  (mingw64-gcc 13.2.1-5.fc39; mingw64-crt 11.0.0-2.fc39; glob)

  c:\users\x>busybox sh

  ~ $ time ./winforktest > /dev/null
  real    3m 44.44s
  user    0m 0.32s
  sys     0m 4.90s
Windows is quite a bit slower, at least with Busybox.

I understand that WSLv1 presents a more efficient fork(), which is not really available to shims like Cygwin or mingw.


Thank you very much!

So, that does 19999 fork()s in 224 seconds, which works out to about 11 milliseconds per fork(). (On my Linux box, it's actually doing clone(), and also does a bunch of wait4(), rt_sigaction(), exit_group(), etc., but let's assume the fork() is the bottleneck.)

This is pretty slow, but it's still about 6× faster than the 70 milliseconds I had inferred from your "100× slower than any other POSIX".

Also note that your Red Hat machine is evidently forking in 39μs, which is several times faster than I've ever seen Linux fork.


Let me know how your tests go.

I did!

That’s more an argument against using Windows for a web server than against using CGI.



Consider applying for YC's Fall 2025 batch! Applications are open till Aug 4

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: