Async or Parallel? No they aren’t the same thing!

Slides:



Advertisements
Similar presentations
Chap 4 Multithreaded Programming. Thread A thread is a basic unit of CPU utilization It comprises a thread ID, a program counter, a register set and a.
Advertisements

Silberschatz, Galvin and Gagne ©2009Operating System Concepts – 8 th Edition Chapter 4: Threads.
Async Programming WITH ASYNC TASK
Chapter 4: Multithreaded Programming
Computer Systems/Operating Systems - Class 8
Chapter 4: Threads. Overview Multithreading Models Threading Issues Pthreads Windows XP Threads.
Intro to Threading CS221 – 4/20/09. What we’ll cover today Finish the DOTS program Introduction to threads and multi-threading.
Virtual techdays INDIA │ 9-11 February 2011 Parallelism in.NET 4.0 Parag Paithankar │ Technology Advisor - Web, Microsoft India.
1 Chapter 4 Threads Threads: Resource ownership and execution.
A. Frank - P. Weisberg Operating Systems Introduction to Tasks/Threads.
Silberschatz, Galvin and Gagne ©2009Operating System Concepts – 8 th Edition Chapter 4: Threads.
1 Threads Chapter 4 Reading: 4.1,4.4, Process Characteristics l Unit of resource ownership - process is allocated: n a virtual address space to.
Parallel Programming in.NET Kevin Luty.  History of Parallelism  Benefits of Parallel Programming and Designs  What to Consider  Defining Types of.
Chapter 51 Threads Chapter 5. 2 Process Characteristics  Concept of Process has two facets.  A Process is: A Unit of resource ownership:  a virtual.
Operating Systems CSE 411 CPU Management Sept Lecture 11 Instructor: Bhuvan Urgaonkar.
A Bridge to Your First Computer Science Course Prof. H.E. Dunsmore Concurrent Programming Threads Synchronization.
1 Lecture 4: Threads Operating System Fall Contents Overview: Processes & Threads Benefits of Threads Thread State and Operations User Thread.
Silberschatz, Galvin and Gagne ©2011Operating System Concepts Essentials – 8 th Edition Chapter 4: Threads.
Silberschatz, Galvin and Gagne ©2009Operating System Concepts – 8 th Edition Chapter 4: Threads.
Threaded Applications Introducing additional threads in a Delphi application is easy.
4.1 Introduction to Threads Overview Multithreading Models Thread Libraries Threading Issues Operating System Examples Windows XP Threads Linux Threads.
Lecture 21 Parallel Programming Richard Gesick. Parallel Computing Parallel computing is a form of computation in which many operations are carried out.
WHO WILL BENEFIT FROM THIS TALK TOPICS WHAT YOU’LL LEAVE WITH ASP.NET developers, including Web Forms & MVC History of async programming in.NET How async.
Multithreaded Programing. Outline Overview of threads Threads Multithreaded Models  Many-to-One  One-to-One  Many-to-Many Thread Libraries  Pthread.
Chapter 4: Threads. 4.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts – 7 th edition, Jan 23, 2005 Chapter 4: Threads Overview Multithreading.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 4: Threads.
Cs431-cotter1 Processes and Threads Tanenbaum 2.1, 2.2 Crowley Chapters 3, 5 Stallings Chapter 3, 4 Silberschaz & Galvin 3, 4.
4.1 Introduction to Threads Overview Multithreading Models Thread Libraries Threading Issues Operating System Examples Windows XP Threads Linux Threads.
Operating System Concepts
Silberschatz, Galvin and Gagne ©2009Operating System Concepts – 8 th Edition Chapter 4: Threads.
Silberschatz, Galvin and Gagne ©2009Operating System Concepts – 8 th Edition Chapter 4: Threads.
Lecturer 3: Processes multithreaded Operating System Concepts Process Concept Process Scheduling Operation on Processes Cooperating Processes Interprocess.
Silberschatz, Galvin and Gagne ©2009Operating System Concepts – 8 th Edition Chapter 4: Threads.
Concepts of Multithreading CS 378 – Mobile Computing for iOS Dr. William C. Bulko.
Introduction to Operating Systems Concepts
Chapter 4: Threads Modified by Dr. Neerja Mhaskar for CS 3SH3.
Introduction to threads
Threads Some of these slides were originally made by Dr. Roger deBry. They include text, figures, and information from this class’s textbook, Operating.
Remote Procedure Calls
Chapter 4: Threads.
OPERATING SYSTEM CONCEPT AND PRACTISE
Chapter 4: Threads.
Processes and threads.
Mobile App Development
Background on the need for Synchronization
Operating Systems (CS 340 D)
CS240: Advanced Programming Concepts
Thread Fundamentals Header Advanced .NET Threading, Part 1
Operating System (013022) Dr. H. Iwidat
Chapter 4: Multithreaded Programming
Chapter 4: Threads.
Staying Afloat in the .NET Async Ocean
Chapter 4 Multithreading programming
Chapter 4: Threads.
12 Asynchronous Programming
Modified by H. Schulzrinne 02/15/10 Chapter 4: Threads.
Lecture Topics: 11/1 General Operating System Concepts Processes
Lecture 4- Threads, SMP, and Microkernels
Threads and Concurrency
Threads Chapter 4.
Multithreaded Programming
Hold up, wait a minute, let me put some async in it
Chapter 4: Threads.
Building Web Applications with Microsoft ASP
Chapter 4: Threads.
EECE.4810/EECE.5730 Operating Systems
Lecture 20 Parallel Programming CSE /8/2019.
Chapter 3: Process Management
Chapter 4:Threads Book: Operating System Principles , 9th Edition , Abraham Silberschatz, Peter Baer Galvin, Greg Gagne.
Presentation transcript:

Async or Parallel? No they aren’t the same thing! Andie Saizan Email: Andie.Saizan@gmail.com Async or Parallel? No they aren’t the same thing!

Processes & Threads

Processes A process is a collection of virtual memory space, code, data, and system resources. Processes communicate with one another through messages, using Microsoft's Remote Procedure Call (RPC) technology to pass information to one another. There is no difference to the caller between a call coming from a process on a remote machine and a call coming from another process on the same machine.

Threads A thread is code that is to be serially executed within a process. A processor executes threads, not processes, so each application has at least one process, and a process always has at least one thread of execution, known as the primary or main thread. A process can have multiple threads in addition to the primary thread.

When a thread begins to execute, it continues until it is killed or until it is interrupted by a thread with higher priority. Each thread can run separate sections of code, or multiple threads can execute the same section of code. Threads executing the same block of code maintain separate stacks. Each thread in a process shares that process's global variables and resources.

Deadlocks & Races Multithreaded applications must avoid two threading problems: deadlocks and races. A deadlock occurs when each thread is waiting for the other to do something. A race condition occurs when one thread finishes before another on which it depends, causing the former to use an uninitialized value because the latter has not yet supplied a valid one.

So what’s the difference?

Asnyc != Parallel = true Asnyc For operations that are I/O bound. Improves responsiveness Frees up main thread to continue work on other processes. Normally involved long running tasks & responsiveness is the goal Parallel For operations that are CPU bound. Improves performance speed Blocks main thread while processing. Normally performance is the goal.

Synchronous Processing Boring!

Asynchronous Processing This normally involves longer running tasks and tasks which are perhaps waiting on some kind of external data or process to complete. Async processing targets I/O bound requests such as requests to Database Server, API Service, File Service etc.

Parallel Processing Normally with parallel programming performance is important and all the threads are working to a common goal. Parallel processing is targets CPU bound requests such as performing calculations are large collections. It allows us to utilize more available resources (cores) to perform a task.

Task Parallel Linq Library (TPL)

TPL The Task Parallel Library (TPL) is a set of public types and APIs in the System.Threading and System.Threading.Tasks namespaces. The purpose of the TPL is simply to simplify task basked programming. Built-in async/await handles deadlocks & races

Simple Async Example private async Task<string> DoStuff() { var result = await LongRunningOperation(); Console.WriteLine($"Counts complete: {result}"); return result; }

Web Api Async Example In the UI Async we primarily use Async to keep the UI responsive. For server applications, the primary benefit of async is scalability. Open Web Interface for .NET (OWIN) was designed from the ground up to be asynchronous; and ASP.NET can also be asynchronous. Async: It’s not just for UI apps! https://msdn.microsoft.com/en-us/magazine/dn802603.aspx

Parallel LINQ (PLINQ)

PLINQ Parallel LINQ (PLINQ) is a full set of LINQ standard query operations as extensions methods for the System.Linq namespace that provides parallel operations to Objects The purpose PLINQ is simply to simplify task basked programming.

Simple Parallel Examples Task parallel or PLINQ is not automatically mean it’s always the most efficient. Knowing you application and testing variations of Task.ForEach, .AsParallel.ForAll, or simply .ForEach when optimizing performance, is needed. In the sample code, take time to note that the list is not processed in order. PLINQ does support order preservation but the ForAll doesn’t return results. You can use .AsParallel.AsOrdered.Select(…). The select will not process in order but it will return the result set as ordered.

Lets Review

Processors execute threads, and threads execute processes All applications have at least one main thread. Multiple threads do not mean, multiple cores A single thread can execute across multiple cores

Asynchronous programming does NOT make your application faster Asynchronous programming does NOT make your application faster. It makes it more responsive and/or scalable. Async is best used for operations that are I/O bound. Parallel programming does make you application faster, but it’s not always the best approach. .Net provides and easy button with TPL and PLINQ