01 Apr 2010, 21:15

Threads in Perl are broken


Ok, for most experienced perl programmers this is not new, but let me repeat it:

Threads in Perl are broken. Really, really, severe broken. Do not use threads with Perl.
Thread async is probably ok for smaller computations but for anything else use fork().

Not only are IPC-Signals really dangerous with threads and DBI can’t work with threads but also the memory usage is magnitudes higher with threads than with fork(). At the moment I’m hacking a perl app that uses a lot ressouces but I was impressed how fast I could kill my system with fair amout of concurrent threads. From Java I was used to threads being very lightweight, but with Perl this is the other way round. My app has its core part modularized and I’ve wrote it once using threads and once using fork(). The threads-version uses about 300MB RSS while the fork()ing version uses no more the 30MB RSS for the same workload. Quiet a difference.