Hi,
for a common parallel task (not web service), should I use threads or processes to handle it? is ruby's threads stable?
Thanks.
Hi,
for a common parallel task (not web service), should I use threads or processes to handle it? is ruby's threads stable?
Thanks.
Yes, Ruby's threads are stable. If you use a fancy implementation like
JRuby or Rubinius they'll also run in parallel on multiple CPU cores (on
MRI only I/O is parallel)
There's also nifty frameworks for multithreaded programming like Celluloid!
(written by yours truly)
On Wed, Oct 9, 2013 at 5:49 PM, pangj <pangj@laposte.net> wrote:
Hi,
for a common parallel task (not web service), should I use threads or
processes to handle it? is ruby's threads stable?Thanks.
--
Tony Arcieri
Thanks. how about ruby's multi-processes?
On 2013-10-10 9:34, Tony Arcieri wrote:
Yes, Ruby's threads are stable. If you use a fancy implementation like
JRuby or Rubinius they'll also run in parallel on multiple CPU cores (on
MRI only I/O is parallel)
That works great, too. You'll have higher memory usage; but MRI 2.0+
has a copy-on-write friendly GC to save some memory.
Anything allocating memory or file descriptors can be a source of
contention in multithreaded situations (things like
malloc/free/open/close, which Ruby uses internally).
Multiple processes can work around those limitations, even.
I combine threads and processes, too. Some configurations of the
Rainbows! HTTP server do this.
Historically; it was not recommended to fork/exec new processes if
threads are already running, but recent-ish Linux + Ruby 2.0 where
FD_CLOEXEC is default, it's fine.
pangj <pangj@laposte.net> wrote:
On 2013-10-10 9:34, Tony Arcieri wrote:
>Yes, Ruby's threads are stable. If you use a fancy implementation like
>JRuby or Rubinius they'll also run in parallel on multiple CPU cores (on
>MRI only I/O is parallel)Thanks. how about ruby's multi-processes?