Ruby Concurrency and Parallelism

15 Jul 2016
0 Comments
Ruby Concurrency and Parallelism

Ruby concurrency is when two tasks will begin, run, and complete in overlapping time periods. It doesn’t essentially mean, though, that they’ll ever each be running at a similar instant (e.g., multiple threads on a single-core machine). In distinction, correspondence is once 2 tasks virtually run at a similar time (e.g., multiple threads on a multicore processor).

Multiple Processes vs. Multithreading: Processes:

  • Uses a lot of memory
  • If parent dies before kids have exited, kids will become zombie processes
  • More expensive for forked processes to modify context since OS has to save and reload everything
  • Forked processes ar given a brand new computer storage area
  • Requires inter-process communication
  • Slower to make and destroy
  • Easier to code and correct

Threading:

  • Uses less memory
  • All threads die once the method dies
  • Threads have significantly less overhead since they share address area and memory
  • Threads share a similar memory, thus have to be compelled to management and affect synchronous memory problems
  • Can "communicate" via queues and shared memory
  • Faster to make and destroy
  • Can be considerably a lot of advanced to code and correct

Examples of Ruby solutions that use multiple processes:

Resque: A Redis-backed Ruby library for making background jobs, inserting them on multiple queues, and process them later.

Unicorn: AN protocol server for Rack applications designed to solely serve quick shoppers on low-latency, high-bandwidth connections and profit of options in Unix/Unix-like kernels.

Examples of Ruby solutions that use multithreading:

Sidekiq: A full-featured backgrounding framework for Ruby. It aims to be easy to integrate with any trendy Rails application and far higher performance than different existing solutions.

Puma: A Ruby internet server engineered for concurrency.

Thin: a awfully quick and easy Ruby internet server.




Leave a comment: