views:

159

answers:

2

Kernel threads do context switch at kernel level instead of process level.

I am planning to set up an httpserver in perl. I want to know if perl threads have same advantage as kernel threads from the perspective of context switch.

+1  A: 

/usr/bin/perl is a userland application and as such doesn't use kernel threads - therefore, it'll be at process level, not kernel level. The only time kernel threads are used is in kernel code - everything else is in userland. So if you're not writing a kernel module or writing C on the kernel source tree, you're in user-land.

Ninefingers
+2  A: 

I'm reasonably convinced that if you're trying to write a high performance server, Perl is NOT the way to go about it - threads or no threads (Perl threads suck by the way, but that is irrelevant).

Context switching is NOT why the kernel-mode stuff is "more efficient" - but because they don't have system call overheads. Having said that, the benefits of these low level optimisations are very, very edge-case. If your application is so performance critical that it needs these optimisations, you can probably just throw more machines at it more cheaply (this is of course a management decision). Writing kernel code is error prone (i.e. mistakes crash or break the kernel) and difficult to maintain as it needs to be updated for each new kernel version.

MarkR
+1 I agree. If you want a high performance web server, use C/C++ and link to pthreads. Note Apache uses a combination of fork() and pthreads for optimum performance (mpm_prefork), not just pthreads alone.
Ninefingers
@Ninefingers, no, prefork is thread free, you are thinking of mpm_worker. And where perl is concerned, that 'optimum' is arguable.
ysth