Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Threads and Processes (Lightning Talk Given at ...

Ariel Caplan
November 24, 2015

Threads and Processes (Lightning Talk Given at Rails Israel 2015)

Many of us use threads and/or processes in our code, whether explicitly or implicitly. But do we really understand what threads and processes are? Can we clearly evaluate the pros and cons of each? We will attempt to clarify these concepts in a simple, concise fashion.

Ariel Caplan

November 24, 2015
Tweet

More Decks by Ariel Caplan

Other Decks in Technology

Transcript

  1. Threads && Processes Both provide concurrent execution of code! Neither

    guarantee execution order! Both add overhead to your code!
  2. Threads vs. Processes @var @var @var = 1 @var @var

    @var = 2 @var = 2 WARNING:
 OVERSIMPLIFICATION
  3. Threads vs. Processes in MRI Threads share memory and state!

    Processes share nothing! Threads are concurrent, not parallel, due to the GIL 
 (Global Interpreter Lock)! Processes operate in true parallel
  4. Implication: Sidekiq Concurrency For a server running only Sidekiq on

    MRI:! 1 Sidekiq process per core! Concurrency (number of threads) = 1 / CPU Time! Example: 8-core machine with 75% IO, 25% CPU:! 8 Sidekiq processes! Sidekiq concurrency of 1/(25%) = 4