Plack server with threads

There was no non-single threaded Plack server for Windows. It is because current implementations use preforking which is completly broken on this system. But wait, Perl already has threads which works better on Windows.

So I wrote Thrall: multithreaded Plack server for Windows. To be strict - it is hacked Starlet server with preforking removed, so now works with Perl on Windows correctly.

Threads on Perl?

Well, I've noticed that threads are really stable and useful and its API is very nice. It is only one thing that breaks everything: threads::shared. It is horribly unstable and broken on Windows, so I avoided it as far as simple server might not to need it. Spawning new threads is very slow, so it is suggested to use large value for --max-reqs-per-child option.

It is interesting, that Thrall can be converted automagically to preforking server when it is started with -Mforks option/


Just hammered it a bit with ab and everything seems to be fine. No big leaks (i saw a 2mb increase in a 350 mb process over 10000 requests, might've been my app) and fairly fast.

However this worries me a bit:

Complete requests: 10000
Failed requests: 9982
(Connect: 0, Receive: 0, Length: 9982, Exceptions: 0)

Are you maybe not opening file handles in binary mode, leading to newline munging?

Otherwise, really good work. Thank you. :)

> It is only one thing that breaks everything: threads::shared.
That really shouldn't happen. Either you're not using it correctly, or something really weird is going on.

Leave a comment

About Piotr Roszatycki

user-pic I blog about Perl.