Hacker News new | ask | show | jobs
by dillon 3063 days ago

    ... our CPU has to wait and does nothing, instead of doing some useful job.
Please correct me where I'm wrong, but IIRC your CPU is never waiting if there is more work to be done. Yes, there is the overhead of context switching if you're using mod_php. Otherwise I think most operating systems are smart enough to make use of resources.

EDIT: Maybe an OS expert can clear up how this works?

1 comments

Correct. If a process is waiting on a recv()/send() (or any other non-asynchronous IO syscall on Linux), the userspace process will go into (un)interruptible sleep and another process can be scheduled in it's place. When data is ready to process (or a signal needs to be delivered) the original process will be scheduled again and the syscall will return. It would be absurd for the CPU to busy wait on data.

And if the language you're choosing is a slow interpreted language like PHP then I'm fairly sure the context switch overhead is negligible.