tech-kern archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

nanosleep() for shorted than schedule slice



Hello

I just encountered a situation where PHP performance on NetBSD is rather
weak compared to Linux or MacOS X.

The code calls PHP's uniqid() a lot of time. uniqid() creates an unique
id based on the clock. In order to avoid giving the same value for two
consecutive calls, PHP's uniqid() calls usleep(1) to skip to make sure
the current microsecond has changed.

On NetBSD this turns into a 16 ms sleep, which is 16000 what was
requested. This happens because the kernel scheduled another process,
which is the behavior documented in the man page. However the result is
that a PHP script full of uniqid() is ridiculously slow. 

I worked around the problem by reimplementing PHP uniqid() using
uuidgen(), but that kind of performance problem could exist in many
other softwares.

I wonder if it would make sense for nanosleep(2) to check that requested
sleeping time is shorter than a schedule slice, and if it is, spin the
CPU instead of scheduling another process. Any opinion on this?

-- 
Emmanuel Dreyfus
http://hcpnet.free.fr/pubz
manu%netbsd.org@localhost


Home | Main Index | Thread Index | Old Index