SlideShare a Scribd company logo
1 of 18
Download to read offline
Concurrency vs Parallelism
Concurrency is NOT parallelism.
SJ Campus Model
Speed up from 4 minutes to 40 seconds (6 times faster)

If also include Optimisation time, we speed up around 12 times.
Concurrency vs Parallelism
• Rob Pike, the inventor of Go and member of Unix team

• Gave a talk in 2013, when introducing the Go concurrency primitives

• “Concurrency is NOT parallelism”
• https://blog.golang.org/waza-talk
Concurrency vs Parallelism
• The modern world is parallel

• CPU, Network, Users, Workers, etc

• A lot of programming language provides concurrency primitives

• Concurrent execution

• Synchronisation and messaging
Concurrency vs Parallelism
• Concurrency

• Programming as the composition of independently executing
processes.

• Parallelism

• Programming as the simultaneous execution of (possibly related)
computations.
Concurrency vs Parallelism
• Concurrency is about dealing with lots of things at once.

• Parallelism is about doing lots of things at once.

• Concurrency is about structure, parallelism is about execution.

• Concurrency provides a way to structure a solution to solve a problem
that may (but not necessarily) be parallelizable.
Concurrency plus communication
• Concurrency is a way to structure a program by breaking it into pieces
that can be executed independently.

• Communication is the means to coordinate the independent executions.

• CSP (Communicating Sequential Processes), 1978

• https://www.cs.cmu.edu/~crary/819-f09/Hoare78.pdf
Parallelism example
• Multi-Threading

• Multi-Processing

• Clusters
Parallelism example
Concurrent Dictionary (Meshes, …)
Thread 1: IO, Read and parse data from disk.
Thread 2: loop forever and
if the mesh does not have
collider, attach it.
Thread 3: loop forever and if there
is new mesh instances, merge it.
4 threads used
including main thread.
Problem?
Concurrent Dictionary (Meshes, …)
Thread 1: IO, Read and parse data from disk.
Thread 2: loop forever and
if the mesh does not have
collider, attach it.
Thread 3: loop forever and if there
is new mesh instances, merge it.
Workload: High
Workload: Medium, but
need wait for main thread
Workload: low
Low-level concurrency model is
NOT able to utilise the
computational resources
Problem?
Concurrent Dictionary (Meshes, …)
Thread 1: IO, Read and parse data from disk.
Thread 2: loop forever and
if the mesh does not have
collider, attach it.
Thread 3: loop forever and if there
is new mesh instances, merge it.
Loop forever, busy wait
Workload: low
Loop forever, busy wait
Low-level concurrency model
creates OVERHEAD
Modern Concurrency Model
• Task (promise, coroutine, worker) model

• Thread pool model

• Be able to utilise all computational resources

• Be able to write code in sequential way
Task Model
Concurrent Queue (Tasks…) Push task to the queue
Thread 1: loop forever and
try dequeue, if there is a
task, executes it.
Thread 2: loop forever and
try dequeue, if there is a
task, executes it.
Thread 3: loop forever and
try dequeue, if there is a
task, executes it.
Worker Threads
Thread Pool
Problem?
Concurrent Queue (Tasks…) Push task to the queue
Thread 1: loop forever and
try dequeue, if there is a
task, executes it.
Thread 2: loop forever and
try dequeue, if there is a
task, executes it.
Thread 3: loop forever and
try dequeue, if there is a
task, executes it.
Worker Threads
When thread 1 is busy, thread 2 can
take the task and execute

Be able to utilise all resources (if
there are tasks in the queue)
Problem?
Concurrent Queue (Tasks…) Push task to the queue
Thread 1: loop forever and
try dequeue, if there is a
task, executes it.
Thread 2: loop forever and
try dequeue, if there is a
task, executes it.
Thread 3: loop forever and
try dequeue, if there is a
task, executes it.
Worker Threads
If there is no tasks or just a few
tasks in the queue, we can reduce
the amount of the worker threads.
And increase them when more
tasks come in. (Less overhead)
Dependency?
Concurrent Queue (Tasks…) Push task to the queue
Thread 1: loop forever and
try dequeue, if there is a
task, executes it.
Thread 2: loop forever and
try dequeue, if there is a
task, executes it.
Thread 3: loop forever and
try dequeue, if there is a
task, executes it.
Worker Threads
What if tasks have dependency? i.e.
task 2 must execute after task 1.

We can enqueue task 2 after task 1
finishes.
Priority?
Concurrent Queue (Tasks…) Push task to the queue
Thread 1: loop forever and
try dequeue, if there is a
task, executes it.
Thread 2: loop forever and
try dequeue, if there is a
task, executes it.
Thread 3: loop forever and
try dequeue, if there is a
task, executes it.
Worker Threads
We can use multiple task queues if
task has priority. Or we can create a
special task queue for main thread.
Concurrent Queue (Tasks…)
Concurrent Queue (Tasks…)
Question
• Unity StartCoroutine

• Is it a concurrency model?

• Does it run parallel? 

• How does Unity implement the coroutine? 

• What is the potential issue of the Task model?

More Related Content

What's hot

evolution of operating system
evolution of operating systemevolution of operating system
evolution of operating systemAmir Khan
 
Real Time Operating system (RTOS) - Embedded systems
Real Time Operating system (RTOS) - Embedded systemsReal Time Operating system (RTOS) - Embedded systems
Real Time Operating system (RTOS) - Embedded systemsHariharan Ganesan
 
파이콘 한국 2019 - 파이썬으로 서버를 극한까지 끌어다 쓰기: Async I/O의 밑바닥
파이콘 한국 2019 - 파이썬으로 서버를 극한까지 끌어다 쓰기: Async I/O의 밑바닥파이콘 한국 2019 - 파이썬으로 서버를 극한까지 끌어다 쓰기: Async I/O의 밑바닥
파이콘 한국 2019 - 파이썬으로 서버를 극한까지 끌어다 쓰기: Async I/O의 밑바닥Seomgi Han
 
Directory and discovery services
Directory and discovery servicesDirectory and discovery services
Directory and discovery servicesRamchandraRegmi
 
CORBA Basic and Deployment of CORBA
CORBA Basic and Deployment of CORBACORBA Basic and Deployment of CORBA
CORBA Basic and Deployment of CORBAPriyanka Patil
 
The Basics of MongoDB
The Basics of MongoDBThe Basics of MongoDB
The Basics of MongoDBvaluebound
 
Message queues
Message queuesMessage queues
Message queuesMax Bodnar
 
Real time Operating System
Real time Operating SystemReal time Operating System
Real time Operating SystemTech_MX
 
Parallel computing
Parallel computingParallel computing
Parallel computingVinay Gupta
 
Writing Scalable Software in Java
Writing Scalable Software in JavaWriting Scalable Software in Java
Writing Scalable Software in JavaRuben Badaró
 
Introduction to parallel_computing
Introduction to parallel_computingIntroduction to parallel_computing
Introduction to parallel_computingMehul Patel
 
Apache Flink Adoption at Shopify
Apache Flink Adoption at ShopifyApache Flink Adoption at Shopify
Apache Flink Adoption at ShopifyYaroslav Tkachenko
 
Go Profiling - John Graham-Cumming
Go Profiling - John Graham-Cumming Go Profiling - John Graham-Cumming
Go Profiling - John Graham-Cumming Cloudflare
 
Real time operating system
Real time operating systemReal time operating system
Real time operating systemPratik Hiremath
 
Reverse Engineering a (M)MORPG
Reverse Engineering a (M)MORPGReverse Engineering a (M)MORPG
Reverse Engineering a (M)MORPGAntonin Beaujeant
 
Scalability, Availability & Stability Patterns
Scalability, Availability & Stability PatternsScalability, Availability & Stability Patterns
Scalability, Availability & Stability PatternsJonas Bonér
 

What's hot (20)

evolution of operating system
evolution of operating systemevolution of operating system
evolution of operating system
 
Real Time Operating system (RTOS) - Embedded systems
Real Time Operating system (RTOS) - Embedded systemsReal Time Operating system (RTOS) - Embedded systems
Real Time Operating system (RTOS) - Embedded systems
 
파이콘 한국 2019 - 파이썬으로 서버를 극한까지 끌어다 쓰기: Async I/O의 밑바닥
파이콘 한국 2019 - 파이썬으로 서버를 극한까지 끌어다 쓰기: Async I/O의 밑바닥파이콘 한국 2019 - 파이썬으로 서버를 극한까지 끌어다 쓰기: Async I/O의 밑바닥
파이콘 한국 2019 - 파이썬으로 서버를 극한까지 끌어다 쓰기: Async I/O의 밑바닥
 
Context switching
Context switchingContext switching
Context switching
 
Directory and discovery services
Directory and discovery servicesDirectory and discovery services
Directory and discovery services
 
Peer to peer system
Peer to peer systemPeer to peer system
Peer to peer system
 
Multi threading models
Multi threading modelsMulti threading models
Multi threading models
 
CORBA Basic and Deployment of CORBA
CORBA Basic and Deployment of CORBACORBA Basic and Deployment of CORBA
CORBA Basic and Deployment of CORBA
 
The Basics of MongoDB
The Basics of MongoDBThe Basics of MongoDB
The Basics of MongoDB
 
Message queues
Message queuesMessage queues
Message queues
 
Real time Operating System
Real time Operating SystemReal time Operating System
Real time Operating System
 
Parallel computing
Parallel computingParallel computing
Parallel computing
 
Writing Scalable Software in Java
Writing Scalable Software in JavaWriting Scalable Software in Java
Writing Scalable Software in Java
 
Introduction to parallel_computing
Introduction to parallel_computingIntroduction to parallel_computing
Introduction to parallel_computing
 
Introduction to MongoDB
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDB
 
Apache Flink Adoption at Shopify
Apache Flink Adoption at ShopifyApache Flink Adoption at Shopify
Apache Flink Adoption at Shopify
 
Go Profiling - John Graham-Cumming
Go Profiling - John Graham-Cumming Go Profiling - John Graham-Cumming
Go Profiling - John Graham-Cumming
 
Real time operating system
Real time operating systemReal time operating system
Real time operating system
 
Reverse Engineering a (M)MORPG
Reverse Engineering a (M)MORPGReverse Engineering a (M)MORPG
Reverse Engineering a (M)MORPG
 
Scalability, Availability & Stability Patterns
Scalability, Availability & Stability PatternsScalability, Availability & Stability Patterns
Scalability, Availability & Stability Patterns
 

Similar to Concurrency vs parallelism

Parallel programming
Parallel programmingParallel programming
Parallel programmingSwain Loda
 
Asynchronous Python A Gentle Introduction
Asynchronous Python A Gentle IntroductionAsynchronous Python A Gentle Introduction
Asynchronous Python A Gentle IntroductionPyData
 
U4 JAVA.pptx
U4 JAVA.pptxU4 JAVA.pptx
U4 JAVA.pptxmadan r
 
Parallel Programming: Beyond the Critical Section
Parallel Programming: Beyond the Critical SectionParallel Programming: Beyond the Critical Section
Parallel Programming: Beyond the Critical SectionTony Albrecht
 
cs4240-multithreading.ppt presentation on multi threading
cs4240-multithreading.ppt presentation on multi threadingcs4240-multithreading.ppt presentation on multi threading
cs4240-multithreading.ppt presentation on multi threadingShrutiPanda12
 
Parallel Computing - Lec 5
Parallel Computing - Lec 5Parallel Computing - Lec 5
Parallel Computing - Lec 5Shah Zaib
 
Repeating History...On Purpose...with Elixir
Repeating History...On Purpose...with ElixirRepeating History...On Purpose...with Elixir
Repeating History...On Purpose...with ElixirBarry Jones
 
Copy of Multithreaded Programming.pptx
Copy of Multithreaded Programming.pptxCopy of Multithreaded Programming.pptx
Copy of Multithreaded Programming.pptxYehanNk
 
Modern Java Concurrency (OSCON 2012)
Modern Java Concurrency (OSCON 2012)Modern Java Concurrency (OSCON 2012)
Modern Java Concurrency (OSCON 2012)Martijn Verburg
 
Concurrency Programming in Java - 01 - Introduction to Concurrency Programming
Concurrency Programming in Java - 01 - Introduction to Concurrency ProgrammingConcurrency Programming in Java - 01 - Introduction to Concurrency Programming
Concurrency Programming in Java - 01 - Introduction to Concurrency ProgrammingSachintha Gunasena
 
1.17 Thread in java.pptx
1.17 Thread in java.pptx1.17 Thread in java.pptx
1.17 Thread in java.pptxTREXSHyNE
 
Sync, async and multithreading
Sync, async and multithreadingSync, async and multithreading
Sync, async and multithreadingTuan Chau
 
A tour on Spur for non-VM experts
A tour on Spur for non-VM expertsA tour on Spur for non-VM experts
A tour on Spur for non-VM expertsESUG
 
MERIMeeting du 27 mai 2014 - Parallel Programming
MERIMeeting du 27 mai 2014 - Parallel ProgrammingMERIMeeting du 27 mai 2014 - Parallel Programming
MERIMeeting du 27 mai 2014 - Parallel ProgrammingOlivier NAVARRE
 
Java multi threading
Java multi threadingJava multi threading
Java multi threadingRaja Sekhar
 
Multithreading Introduction and Lifecyle of thread
Multithreading Introduction and Lifecyle of threadMultithreading Introduction and Lifecyle of thread
Multithreading Introduction and Lifecyle of threadKartik Dube
 
Nondeterminism is unavoidable, but data races are pure evil
Nondeterminism is unavoidable, but data races are pure evilNondeterminism is unavoidable, but data races are pure evil
Nondeterminism is unavoidable, but data races are pure evilracesworkshop
 
Multithreading programming in java
Multithreading programming in javaMultithreading programming in java
Multithreading programming in javaElizabeth alexander
 

Similar to Concurrency vs parallelism (20)

Parallel programming
Parallel programmingParallel programming
Parallel programming
 
Asynchronous Python A Gentle Introduction
Asynchronous Python A Gentle IntroductionAsynchronous Python A Gentle Introduction
Asynchronous Python A Gentle Introduction
 
U4 JAVA.pptx
U4 JAVA.pptxU4 JAVA.pptx
U4 JAVA.pptx
 
Parallel Programming: Beyond the Critical Section
Parallel Programming: Beyond the Critical SectionParallel Programming: Beyond the Critical Section
Parallel Programming: Beyond the Critical Section
 
Adsa u4 ver 1.0
Adsa u4 ver 1.0Adsa u4 ver 1.0
Adsa u4 ver 1.0
 
cs4240-multithreading.ppt presentation on multi threading
cs4240-multithreading.ppt presentation on multi threadingcs4240-multithreading.ppt presentation on multi threading
cs4240-multithreading.ppt presentation on multi threading
 
Parallel Computing - Lec 5
Parallel Computing - Lec 5Parallel Computing - Lec 5
Parallel Computing - Lec 5
 
Repeating History...On Purpose...with Elixir
Repeating History...On Purpose...with ElixirRepeating History...On Purpose...with Elixir
Repeating History...On Purpose...with Elixir
 
Concurrency on the JVM
Concurrency on the JVMConcurrency on the JVM
Concurrency on the JVM
 
Copy of Multithreaded Programming.pptx
Copy of Multithreaded Programming.pptxCopy of Multithreaded Programming.pptx
Copy of Multithreaded Programming.pptx
 
Modern Java Concurrency (OSCON 2012)
Modern Java Concurrency (OSCON 2012)Modern Java Concurrency (OSCON 2012)
Modern Java Concurrency (OSCON 2012)
 
Concurrency Programming in Java - 01 - Introduction to Concurrency Programming
Concurrency Programming in Java - 01 - Introduction to Concurrency ProgrammingConcurrency Programming in Java - 01 - Introduction to Concurrency Programming
Concurrency Programming in Java - 01 - Introduction to Concurrency Programming
 
1.17 Thread in java.pptx
1.17 Thread in java.pptx1.17 Thread in java.pptx
1.17 Thread in java.pptx
 
Sync, async and multithreading
Sync, async and multithreadingSync, async and multithreading
Sync, async and multithreading
 
A tour on Spur for non-VM experts
A tour on Spur for non-VM expertsA tour on Spur for non-VM experts
A tour on Spur for non-VM experts
 
MERIMeeting du 27 mai 2014 - Parallel Programming
MERIMeeting du 27 mai 2014 - Parallel ProgrammingMERIMeeting du 27 mai 2014 - Parallel Programming
MERIMeeting du 27 mai 2014 - Parallel Programming
 
Java multi threading
Java multi threadingJava multi threading
Java multi threading
 
Multithreading Introduction and Lifecyle of thread
Multithreading Introduction and Lifecyle of threadMultithreading Introduction and Lifecyle of thread
Multithreading Introduction and Lifecyle of thread
 
Nondeterminism is unavoidable, but data races are pure evil
Nondeterminism is unavoidable, but data races are pure evilNondeterminism is unavoidable, but data races are pure evil
Nondeterminism is unavoidable, but data races are pure evil
 
Multithreading programming in java
Multithreading programming in javaMultithreading programming in java
Multithreading programming in java
 

Recently uploaded

Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)OPEN KNOWLEDGE GmbH
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...MyIntelliSource, Inc.
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...OnePlan Solutions
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...stazi3110
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio, Inc.
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfAlina Yurenko
 
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024StefanoLambiase
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantAxelRicardoTrocheRiq
 
Folding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesFolding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesPhilip Schwarz
 
The Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfThe Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfPower Karaoke
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...gurkirankumar98700
 
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样umasea
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEOrtus Solutions, Corp
 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...Christina Lin
 
React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaHanief Utama
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based projectAnoyGreter
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityNeo4j
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEEVICTOR MAESTRE RAMIREZ
 
Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Andreas Granig
 

Recently uploaded (20)

Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
 
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service Consultant
 
Folding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesFolding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a series
 
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
 
The Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfThe Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdf
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
 
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
 
React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief Utama
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based project
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered Sustainability
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEE
 
Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024
 

Concurrency vs parallelism

  • 2. SJ Campus Model Speed up from 4 minutes to 40 seconds (6 times faster) If also include Optimisation time, we speed up around 12 times.
  • 3. Concurrency vs Parallelism • Rob Pike, the inventor of Go and member of Unix team • Gave a talk in 2013, when introducing the Go concurrency primitives • “Concurrency is NOT parallelism” • https://blog.golang.org/waza-talk
  • 4. Concurrency vs Parallelism • The modern world is parallel • CPU, Network, Users, Workers, etc • A lot of programming language provides concurrency primitives • Concurrent execution • Synchronisation and messaging
  • 5. Concurrency vs Parallelism • Concurrency • Programming as the composition of independently executing processes. • Parallelism • Programming as the simultaneous execution of (possibly related) computations.
  • 6. Concurrency vs Parallelism • Concurrency is about dealing with lots of things at once. • Parallelism is about doing lots of things at once. • Concurrency is about structure, parallelism is about execution. • Concurrency provides a way to structure a solution to solve a problem that may (but not necessarily) be parallelizable.
  • 7. Concurrency plus communication • Concurrency is a way to structure a program by breaking it into pieces that can be executed independently. • Communication is the means to coordinate the independent executions. • CSP (Communicating Sequential Processes), 1978 • https://www.cs.cmu.edu/~crary/819-f09/Hoare78.pdf
  • 8. Parallelism example • Multi-Threading • Multi-Processing • Clusters
  • 9. Parallelism example Concurrent Dictionary (Meshes, …) Thread 1: IO, Read and parse data from disk. Thread 2: loop forever and if the mesh does not have collider, attach it. Thread 3: loop forever and if there is new mesh instances, merge it. 4 threads used including main thread.
  • 10. Problem? Concurrent Dictionary (Meshes, …) Thread 1: IO, Read and parse data from disk. Thread 2: loop forever and if the mesh does not have collider, attach it. Thread 3: loop forever and if there is new mesh instances, merge it. Workload: High Workload: Medium, but need wait for main thread Workload: low Low-level concurrency model is NOT able to utilise the computational resources
  • 11. Problem? Concurrent Dictionary (Meshes, …) Thread 1: IO, Read and parse data from disk. Thread 2: loop forever and if the mesh does not have collider, attach it. Thread 3: loop forever and if there is new mesh instances, merge it. Loop forever, busy wait Workload: low Loop forever, busy wait Low-level concurrency model creates OVERHEAD
  • 12. Modern Concurrency Model • Task (promise, coroutine, worker) model • Thread pool model • Be able to utilise all computational resources • Be able to write code in sequential way
  • 13. Task Model Concurrent Queue (Tasks…) Push task to the queue Thread 1: loop forever and try dequeue, if there is a task, executes it. Thread 2: loop forever and try dequeue, if there is a task, executes it. Thread 3: loop forever and try dequeue, if there is a task, executes it. Worker Threads Thread Pool
  • 14. Problem? Concurrent Queue (Tasks…) Push task to the queue Thread 1: loop forever and try dequeue, if there is a task, executes it. Thread 2: loop forever and try dequeue, if there is a task, executes it. Thread 3: loop forever and try dequeue, if there is a task, executes it. Worker Threads When thread 1 is busy, thread 2 can take the task and execute Be able to utilise all resources (if there are tasks in the queue)
  • 15. Problem? Concurrent Queue (Tasks…) Push task to the queue Thread 1: loop forever and try dequeue, if there is a task, executes it. Thread 2: loop forever and try dequeue, if there is a task, executes it. Thread 3: loop forever and try dequeue, if there is a task, executes it. Worker Threads If there is no tasks or just a few tasks in the queue, we can reduce the amount of the worker threads. And increase them when more tasks come in. (Less overhead)
  • 16. Dependency? Concurrent Queue (Tasks…) Push task to the queue Thread 1: loop forever and try dequeue, if there is a task, executes it. Thread 2: loop forever and try dequeue, if there is a task, executes it. Thread 3: loop forever and try dequeue, if there is a task, executes it. Worker Threads What if tasks have dependency? i.e. task 2 must execute after task 1. We can enqueue task 2 after task 1 finishes.
  • 17. Priority? Concurrent Queue (Tasks…) Push task to the queue Thread 1: loop forever and try dequeue, if there is a task, executes it. Thread 2: loop forever and try dequeue, if there is a task, executes it. Thread 3: loop forever and try dequeue, if there is a task, executes it. Worker Threads We can use multiple task queues if task has priority. Or we can create a special task queue for main thread. Concurrent Queue (Tasks…) Concurrent Queue (Tasks…)
  • 18. Question • Unity StartCoroutine • Is it a concurrency model? • Does it run parallel? • How does Unity implement the coroutine? • What is the potential issue of the Task model?