SlideShare a Scribd company logo
1 of 26
Download to read offline
Rob Keefer, PhD

@rbkeefer
A Brief Introduction to Concurrent
Programming
pomiet.com @rbkeefer
Goal
Goal of Concurrency is to get more done in less time.
Multiple independent tasks
Repeat same task
Solution: Parallelism
pomiet.com @rbkeefer
Parallelism
pomiet.com @rbkeefer
Direction
Processes
Problems with Concurrency
Traditional Solutions
New Approaches
pomiet.com @rbkeefer
Turn the Crank
pomiet.com @rbkeefer
Processor
pomiet.com @rbkeefer
Processor
pomiet.com @rbkeefer
Processor
pomiet.com @rbkeefer
Processor
pomiet.com @rbkeefer
Take Advantage of the Tech
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
pomiet.com @rbkeefer
Five Volunteers
pomiet.com @rbkeefer
Problems: Deadlock
pomiet.com @rbkeefer
Problems: Livelock
pomiet.com @rbkeefer
Problems: Race Condition
pomiet.com @rbkeefer
Problems: Starvation
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
pomiet.com @rbkeefer
Monitor
pomiet.com @rbkeefer
Mutex
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
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
pomiet.com @rbkeefer
Note on Garbage Collection
Credit: Greg Mefford
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
pomiet.com @rbkeefer
Scale with Resilience
Resilience: ability of a system to adapt or keep
working when challenges occur
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?
pomiet.com @rbkeefer
Continue the Conversation
Rob Keefer, PhD
rob.Keefer@pomiet.com
@rbkeefer

More Related Content

What's hot

RedisConf17 - Too Big to Failover - A cautionary tale of scaling Redis
RedisConf17 - Too Big to Failover - A cautionary tale of scaling RedisRedisConf17 - Too Big to Failover - A cautionary tale of scaling Redis
RedisConf17 - Too Big to Failover - A cautionary tale of scaling Redis
Redis Labs
 
Алексей Петров "PHP at Scale: Knowing enough to be dangerous!"
Алексей Петров "PHP at Scale: Knowing enough to be dangerous!"Алексей Петров "PHP at Scale: Knowing enough to be dangerous!"
Алексей Петров "PHP at Scale: Knowing enough to be dangerous!"
Fwdays
 
Http/2 - What's it all about?
Http/2  - What's it all about?Http/2  - What's it all about?
Http/2 - What's it all about?
Andy Davies
 
Erlang plus BDB: Disrupting the Conventional Web Wisdom
Erlang plus BDB: Disrupting the Conventional Web WisdomErlang plus BDB: Disrupting the Conventional Web Wisdom
Erlang plus BDB: Disrupting the Conventional Web Wisdom
guest3933de
 
Best practices-wordpress-enterprise
Best practices-wordpress-enterpriseBest practices-wordpress-enterprise
Best practices-wordpress-enterprise
Taylor Lovett
 

What's hot (20)

Functional Programming with Streams in node.js
Functional Programming with Streams in node.jsFunctional Programming with Streams in node.js
Functional Programming with Streams in node.js
 
Andres Gutierrez "Phalcon 3.0, Zephir & PHP7"
Andres Gutierrez "Phalcon 3.0, Zephir & PHP7"Andres Gutierrez "Phalcon 3.0, Zephir & PHP7"
Andres Gutierrez "Phalcon 3.0, Zephir & PHP7"
 
Александр Махомет "Beyond the code или как мониторить ваш PHP сайт"
Александр Махомет "Beyond the code или как мониторить ваш PHP сайт"Александр Махомет "Beyond the code или как мониторить ваш PHP сайт"
Александр Махомет "Beyond the code или как мониторить ваш PHP сайт"
 
RedisConf17 - Too Big to Failover - A cautionary tale of scaling Redis
RedisConf17 - Too Big to Failover - A cautionary tale of scaling RedisRedisConf17 - Too Big to Failover - A cautionary tale of scaling Redis
RedisConf17 - Too Big to Failover - A cautionary tale of scaling Redis
 
Алексей Петров "PHP at Scale: Knowing enough to be dangerous!"
Алексей Петров "PHP at Scale: Knowing enough to be dangerous!"Алексей Петров "PHP at Scale: Knowing enough to be dangerous!"
Алексей Петров "PHP at Scale: Knowing enough to be dangerous!"
 
Pycon 2014
Pycon 2014Pycon 2014
Pycon 2014
 
HTTP/2 Changes Everything
HTTP/2 Changes EverythingHTTP/2 Changes Everything
HTTP/2 Changes Everything
 
Go from a PHP Perspective
Go from a PHP PerspectiveGo from a PHP Perspective
Go from a PHP Perspective
 
Tuenti Release Workflow
Tuenti Release WorkflowTuenti Release Workflow
Tuenti Release Workflow
 
Http/2 - What's it all about?
Http/2  - What's it all about?Http/2  - What's it all about?
Http/2 - What's it all about?
 
NDC London 2014: Erlang Patterns Matching Business Needs
NDC London 2014: Erlang Patterns Matching Business NeedsNDC London 2014: Erlang Patterns Matching Business Needs
NDC London 2014: Erlang Patterns Matching Business Needs
 
HTTP/2 What's inside and Why
HTTP/2 What's inside and WhyHTTP/2 What's inside and Why
HTTP/2 What's inside and Why
 
HTTP/2 - for TCP/IP Geeks Stockholm
HTTP/2 - for TCP/IP Geeks StockholmHTTP/2 - for TCP/IP Geeks Stockholm
HTTP/2 - for TCP/IP Geeks Stockholm
 
Erlang plus BDB: Disrupting the Conventional Web Wisdom
Erlang plus BDB: Disrupting the Conventional Web WisdomErlang plus BDB: Disrupting the Conventional Web Wisdom
Erlang plus BDB: Disrupting the Conventional Web Wisdom
 
SPDY Talk
SPDY TalkSPDY Talk
SPDY Talk
 
Debugging with Fiddler
Debugging with FiddlerDebugging with Fiddler
Debugging with Fiddler
 
Using Communication and Messaging API in the HTML5 World
Using Communication and Messaging API in the HTML5 WorldUsing Communication and Messaging API in the HTML5 World
Using Communication and Messaging API in the HTML5 World
 
Best practices-wordpress-enterprise
Best practices-wordpress-enterpriseBest practices-wordpress-enterprise
Best practices-wordpress-enterprise
 
PAC 2019 virtual Mark Tomlinson
PAC 2019 virtual Mark TomlinsonPAC 2019 virtual Mark Tomlinson
PAC 2019 virtual Mark Tomlinson
 
4.2. Web analyst fiddler
4.2. Web analyst fiddler4.2. Web analyst fiddler
4.2. Web analyst fiddler
 

Similar to Brief Introduction to Concurrent Programming

Fixing Twitter Improving The Performance And Scalability Of The Worlds Most ...
Fixing Twitter  Improving The Performance And Scalability Of The Worlds Most ...Fixing Twitter  Improving The Performance And Scalability Of The Worlds Most ...
Fixing Twitter Improving The Performance And Scalability Of The Worlds Most ...
xlight
 
Polyglot and Poly-paradigm Programming for Better Agility
Polyglot and Poly-paradigm Programming for Better AgilityPolyglot and Poly-paradigm Programming for Better Agility
Polyglot and Poly-paradigm Programming for Better Agility
elliando dias
 

Similar to Brief Introduction to Concurrent Programming (20)

Loom promises: be there!
Loom promises: be there!Loom promises: be there!
Loom promises: be there!
 
BTV PHP - Building Fast Websites
BTV PHP - Building Fast WebsitesBTV PHP - Building Fast Websites
BTV PHP - Building Fast Websites
 
Introduction to memcached
Introduction to memcachedIntroduction to memcached
Introduction to memcached
 
Cortex: Prometheus as a Service, One Year On
Cortex: Prometheus as a Service, One Year OnCortex: Prometheus as a Service, One Year On
Cortex: Prometheus as a Service, One Year On
 
Northeast PHP - High Performance PHP
Northeast PHP - High Performance PHPNortheast PHP - High Performance PHP
Northeast PHP - High Performance PHP
 
Into The Box 2020 Keynote Day 1
Into The Box 2020 Keynote Day 1Into The Box 2020 Keynote Day 1
Into The Box 2020 Keynote Day 1
 
Realtime traffic analyser
Realtime traffic analyserRealtime traffic analyser
Realtime traffic analyser
 
Making fitting in RooFit faster
Making fitting in RooFit fasterMaking fitting in RooFit faster
Making fitting in RooFit faster
 
STP 2014 - Lets Learn from the Top Performance Mistakes in 2013
STP 2014 - Lets Learn from the Top Performance Mistakes in 2013STP 2014 - Lets Learn from the Top Performance Mistakes in 2013
STP 2014 - Lets Learn from the Top Performance Mistakes in 2013
 
Lessons Learnt in 2009
Lessons Learnt in 2009Lessons Learnt in 2009
Lessons Learnt in 2009
 
Fixing twitter
Fixing twitterFixing twitter
Fixing twitter
 
Fixing_Twitter
Fixing_TwitterFixing_Twitter
Fixing_Twitter
 
Fixing Twitter Improving The Performance And Scalability Of The Worlds Most ...
Fixing Twitter  Improving The Performance And Scalability Of The Worlds Most ...Fixing Twitter  Improving The Performance And Scalability Of The Worlds Most ...
Fixing Twitter Improving The Performance And Scalability Of The Worlds Most ...
 
Fixing Twitter Improving The Performance And Scalability Of The Worlds Most ...
Fixing Twitter  Improving The Performance And Scalability Of The Worlds Most ...Fixing Twitter  Improving The Performance And Scalability Of The Worlds Most ...
Fixing Twitter Improving The Performance And Scalability Of The Worlds Most ...
 
Polyglot and Poly-paradigm Programming for Better Agility
Polyglot and Poly-paradigm Programming for Better AgilityPolyglot and Poly-paradigm Programming for Better Agility
Polyglot and Poly-paradigm Programming for Better Agility
 
LCache DrupalCon Dublin 2016
LCache DrupalCon Dublin 2016LCache DrupalCon Dublin 2016
LCache DrupalCon Dublin 2016
 
FreeSWITCH as a Microservice
FreeSWITCH as a MicroserviceFreeSWITCH as a Microservice
FreeSWITCH as a Microservice
 
Oracle Fuson Middleware Diagnostics, Performance and Troubleshoot
Oracle Fuson Middleware Diagnostics, Performance and TroubleshootOracle Fuson Middleware Diagnostics, Performance and Troubleshoot
Oracle Fuson Middleware Diagnostics, Performance and Troubleshoot
 
Celery: The Distributed Task Queue
Celery: The Distributed Task QueueCelery: The Distributed Task Queue
Celery: The Distributed Task Queue
 
Static Code Analysis PHP[tek] 2023
Static Code Analysis PHP[tek] 2023Static Code Analysis PHP[tek] 2023
Static Code Analysis PHP[tek] 2023
 

More from Rob Keefer

More from Rob Keefer (17)

Goldilocks and AI
Goldilocks and AIGoldilocks and AI
Goldilocks and AI
 
7 Habits of Highly Effective Stakeholders
7 Habits of Highly Effective Stakeholders7 Habits of Highly Effective Stakeholders
7 Habits of Highly Effective Stakeholders
 
Tranquilty Over Tubulence
Tranquilty Over TubulenceTranquilty Over Tubulence
Tranquilty Over Tubulence
 
Project Peace of Mind
Project Peace of MindProject Peace of Mind
Project Peace of Mind
 
MVP in Complex Environments
MVP in Complex EnvironmentsMVP in Complex Environments
MVP in Complex Environments
 
Technostress in Healthcare
Technostress in HealthcareTechnostress in Healthcare
Technostress in Healthcare
 
Fail Smart, Not Just Fast: FMEA Workshop
Fail Smart, Not Just Fast: FMEA WorkshopFail Smart, Not Just Fast: FMEA Workshop
Fail Smart, Not Just Fast: FMEA Workshop
 
Embrace Complexity
Embrace ComplexityEmbrace Complexity
Embrace Complexity
 
Do Go Map
Do Go MapDo Go Map
Do Go Map
 
Developer Flow
Developer FlowDeveloper Flow
Developer Flow
 
Brain Sketching
Brain SketchingBrain Sketching
Brain Sketching
 
Blocks to DevOps
Blocks to DevOpsBlocks to DevOps
Blocks to DevOps
 
Agile UX
Agile UXAgile UX
Agile UX
 
DoGo Map Workshop
DoGo Map WorkshopDoGo Map Workshop
DoGo Map Workshop
 
Team Peace of Mind
Team Peace of MindTeam Peace of Mind
Team Peace of Mind
 
Design Innovation
Design InnovationDesign Innovation
Design Innovation
 
Agile UX
Agile UXAgile UX
Agile UX
 

Recently uploaded

%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
masabamasaba
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 

Recently uploaded (20)

%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
 
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
 
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park %in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
Announcing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK SoftwareAnnouncing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK Software
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learn
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
10 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 202410 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 2024
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
 
%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
 
Chinsurah Escorts ☎️8617697112 Starting From 5K to 15K High Profile Escorts ...
Chinsurah Escorts ☎️8617697112  Starting From 5K to 15K High Profile Escorts ...Chinsurah Escorts ☎️8617697112  Starting From 5K to 15K High Profile Escorts ...
Chinsurah Escorts ☎️8617697112 Starting From 5K to 15K High Profile Escorts ...
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial Goals
 
%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Harare%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Harare
 

Brief Introduction to Concurrent Programming