This is the mail archive of the
cygwin
mailing list for the Cygwin project.
Efficient posix_spawn implementation for Cygwin
- From: dancol at dancol dot org
- To: cygwin at cygwin dot com
- Date: Tue, 3 Jan 2012 14:25:28 -0800
- Subject: Efficient posix_spawn implementation for Cygwin
posix_spawn [1] is an optional POSIX facility that allows programs to
start other programs without using fork or vfork. I've created an
efficient implementation of posix_spawn for Cygwin. The code is available
at https://github.com/dcolascione/cygspawn.
This library uses Cygwin's nonstandard spawn* family calls in process.h to
provide the full suite of posix_spawn* functionality. Implementing
posix_spawn in terms of spawn turns out to be non-trivial. Nevertheless,
using posix_spawn can improve process startup performance considerably,
especially for large programs:
+ env ITER=1000 JUNKBYTES=209715200 ./testspawn true
real 0m5.179s
user 0m1.550s
sys 0m2.661s
+ env ITER=1000 JUNKBYTES=209715200 ./testfork true
real 1m57.523s
user 0m3.049s
sys 1m52.339s
(JUNKBYTES here tells both programs to malloc 200MB of private data before
doing anything else; this allocation simulates the working set of a large
program.)
Hopefully, it will be more feasible to add posix_spawn support to other
projects than to add Cygwin-specific cases for direct calls to spawn.
posix_spawn is natively supported on OS X, and gnulib provides an
implementation in terms of fork or vfork for all other common platforms.
One example: Emacs is an example of a large program that routinely runs
subprocesses. In my case, fork latency was so great that I had to disable
Emacs' support for version control integration: I didn't want to wait for
two seconds after opening a new file while Emacs queried the . I'm working
on adding support to posix_spawn to Emacs [2]; when it works, I'll be able
to use the built-in version control integration under Cygwin just like I
do on other Unix systems.
[1] http://pubs.opengroup.org/onlinepubs/009695399/functions/posix_spawn.html
[2] https://github.com/dcolascione/emacs/tree/cygw32
--
Problem reports: http://cygwin.com/problems.html
FAQ: http://cygwin.com/faq/
Documentation: http://cygwin.com/docs.html
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple