O slideshow foi denunciado.
Seu SlideShare está sendo baixado. ×

Brief Introduction to Concurrent Programming

Anúncio
Anúncio
Anúncio
Anúncio
Anúncio
Anúncio
Anúncio
Anúncio
Anúncio
Anúncio
Anúncio
Anúncio
Carregando em…3
×

Confira estes a seguir

1 de 26 Anúncio
Anúncio

Mais Conteúdo rRelacionado

Diapositivos para si (20)

Semelhante a Brief Introduction to Concurrent Programming (20)

Anúncio

Mais recentes (20)

Anúncio

Brief Introduction to Concurrent Programming

  1. 1. Rob Keefer, PhD
 @rbkeefer A Brief Introduction to Concurrent Programming
  2. 2. pomiet.com @rbkeefer Goal Goal of Concurrency is to get more done in less time. Multiple independent tasks Repeat same task Solution: Parallelism
  3. 3. pomiet.com @rbkeefer Parallelism
  4. 4. pomiet.com @rbkeefer Direction Processes Problems with Concurrency Traditional Solutions New Approaches
  5. 5. pomiet.com @rbkeefer Turn the Crank
  6. 6. pomiet.com @rbkeefer Processor
  7. 7. pomiet.com @rbkeefer Processor
  8. 8. pomiet.com @rbkeefer Processor
  9. 9. pomiet.com @rbkeefer Processor
  10. 10. pomiet.com @rbkeefer Take Advantage of the Tech
  11. 11. pomiet.com @rbkeefer Problems 1. Starting / maintaining processes 2. Communication between processes • Remote procedure call (RPC) • Message passing 3. Shared Resources • Deadlock • Livelock • Race conditions • Starvation
  12. 12. pomiet.com @rbkeefer Five Volunteers
  13. 13. pomiet.com @rbkeefer Problems: Deadlock
  14. 14. pomiet.com @rbkeefer Problems: Livelock
  15. 15. pomiet.com @rbkeefer Problems: Race Condition
  16. 16. pomiet.com @rbkeefer Problems: Starvation
  17. 17. pomiet.com @rbkeefer Approaches Traditional Object Oriented Modern Functional General Philosophy: Failure Prevention General Philosophy: Embrace Failure Monitor Mutual Exclusion (Mutex) Prioritization Algorithms Support process death and resurrection Support atomic functions Fairness algorithms embedded in VM
  18. 18. pomiet.com @rbkeefer Monitor
  19. 19. pomiet.com @rbkeefer Mutex
  20. 20. pomiet.com @rbkeefer def call(process_name, message, timeout 5000) ref = Process.monitor(process_name) try do send(process_name, {:message, {ref, self()}, message}) rescue _ -> :error end receive do {:reply, ref, reply} -> Process.demonitor(ref, [:flush]) reply {:DOWN, ref, :process, _, reason} -> {:error, reason} exit(reason) after timeout -> exit(:timeout) end end Elixir - Lock Prevention <- exit on timeout
  21. 21. pomiet.com @rbkeefer def answer(process_name, message, timeout 5000) receive do {:knock, ref, reply} -> reply # "Who's there?" {:DOWN, ref, :process, _, reason} -> {:error, reason} exit(reason) # No one knocking after timeout -> exit(:timeout) end . . . def knock(process_name, message, timeout 5000) receive do {:reply, ref, reply} -> reply # Tell who you are {:DOWN, ref, :process, _, reason} -> {:error, reason} exit(reason) # No one home after timeout -> exit(:timeout) end . . . Elixir - Race Condition <- exit on timeout <- exit on timeout
  22. 22. pomiet.com @rbkeefer Note on Garbage Collection Credit: Greg Mefford
  23. 23. pomiet.com @rbkeefer A Few Facts Traditional Object Oriented Modern Functional Bring data and behaviors together Simulation of behavior (heuristics) Overhead: Java threads 512 Kb / thread Require thread pools / execution management Shared heap Hard limits on memory use Separate data from behaviors Data manipulation (algorithms) Overhead: Elixir 512 b / process Processes easily accessible Individual private heap Unbounded memory
  24. 24. pomiet.com @rbkeefer Scale with Resilience Resilience: ability of a system to adapt or keep working when challenges occur
  25. 25. pomiet.com @rbkeefer Questions to Consider Think Different: Fault Tolerance: What happens if a dependency starts failing slowly? What’s the worse-scenario for total failure? Efficiency: Is it possible to precompute data? Are you doing as little work as possible? Is load testing part of the regression test suite? Operability: Where are the nonlinearities in load or failure responses? What are the capacity needs? How does the system scale?
  26. 26. pomiet.com @rbkeefer Continue the Conversation Rob Keefer, PhD rob.Keefer@pomiet.com @rbkeefer

×