Perl threads and libwww wierdness
peter at vereshagin.org
Fri Dec 16 05:18:57 GMT 2011
2011/12/16 12:38:16 +1100 Toby Wintermute <tjc at wintrmute.net> => To London.pm Perl M[ou]ngers :
TW> > (i)Threaded perl5 ( 'use threads' ) doesn't seem to be recommended for
TW> > production environments.
TW> I know it certainly wasn't recommended back in the days of 5.6 or 5.8,
TW> but I thought things had improved since then..
They did. Perl6 was released and it seems to have threads those can be recommended.
Perl5 have fork() that 'just works' and seems to be enough.
TW> > Forks are the standard IPC method for perl5. Event-driven stuff (AE/EV) is a
TW> > more advanced way, but for 40 parallel requests the forks are just ok.
TW> I'm not sure IPC means what you think it means - or I'm
TW> misunderstanding you - It's Inter-process communication, right?
TW> It'd say that forking, threading, and event-driven, are all methods of
TW> doing simultaneous processing - but don't specify anything about IPC.
Right. I just use to avoid telling many words like 'method of doing
simultaneous processing' in favor of 'perlipc' in this case because:
$ man perlipc | grep fork | wc -l
$ man perlipc | grep thread | wc -l
and having several perl processes to communicate between is made just easier
by mean of fork().
TW> Which is the reason I was using threads - it's easy to do IPC between
... processes? (=
TW> them by sharing access to some data structures.
TW> Whereas with forking you need to set up pipes, posix shared memory,
TW> sockets, or some other means.
Memory-mapped file doesn't seem to be bad:
TW> In the end, I bit the bullet yesterday and did rewrite the code to use
TW> fork(), and then used Net::STOMP::Client with RabbitMQ to perform the
Ouch. Isn't *MQ about to 'lose data under some circumstances' ?
TW> Total throughput is actually slightly faster than the threaded
TW> version, it uses quite a bit less memory, and critically, doesn't get
TW> any spurious errors.
That's it about getting a life with perl5: use forks, be happy. (=
ps. should like to know if there is a threads.pm implementation that means
'native threads' on ms-windows.
Peter Vereshagin <peter at vereshagin.org> (http://vereshagin.org) pgp: A0E26627
More information about the london.pm