Threads or processes

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)

http://celluloid.io

On 2013-10-10 9:34, Tony A. 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?

pangj [email protected] wrote:

On 2013-10-10 9:34, Tony A. 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?

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.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs