Do perl threads have the same advantage as kernel threads?
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.
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.
/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.
精彩评论