Concurrency in Ruby

20
@jaisonerick @jonatasdp hosted by supported by Concurrency

Transcript of Concurrency in Ruby

Page 2: Concurrency in Ruby

Concurrency

Page 3: Concurrency in Ruby

Case 1:

Migrating DATA

Page 4: Concurrency in Ruby

Migrating DATA

Case da BONUZ (@jaisonerick)

Page 5: Concurrency in Ruby

Migrating DATA

Case da Resultados Digitais(@jonatasdp)

Page 6: Concurrency in Ruby

Case 2:

BONUZ

WEB APPLICATIONS

Page 7: Concurrency in Ruby

Pessimistic Optimistic

Page 8: Concurrency in Ruby

MODE● SHARED● EXCLUSIVE

Page 9: Concurrency in Ruby

Exclusive Pessimistic Lock

SELECT * FROM `accounts` where `id`=1 FOR UPDATE;

Page 10: Concurrency in Ruby

Shared Pessimistic Lock

SELECT * FROM `accounts`where `id`=1 LOCK IN SHARE MODE;

Page 11: Concurrency in Ruby

Item Model:

Item Controller:

Page 12: Concurrency in Ruby

Threads● MUTEX● DEAD LOCK

Page 13: Concurrency in Ruby

Encapsulated

Page 14: Concurrency in Ruby
Page 15: Concurrency in Ruby

Always lock in the same order!

Page 16: Concurrency in Ruby

● Don't do it, if you can avoid it.

● If you must do it, don't share data across

threads.

● If you must share data across threads, don't share

mutable data.

● If you must share mutable data across threads,

synchronize access to that data.

JRUBY - Concurrency Rules:

Page 17: Concurrency in Ruby

Testing Concurrency...with concurrency

Page 18: Concurrency in Ruby
Page 19: Concurrency in Ruby

Hands On!

Page 20: Concurrency in Ruby

Perguntas?