Intelligent People. Uncommon Ideas. Async IO, Non Blocking IO, Blocking IO and Multithreading By Bhavin Turakhia CEO, Directi

Slides:



Advertisements
Similar presentations
ITR3 lecture 7: more introduction to UNIX Thomas Krichel
Advertisements

CSC 360- Instructor: K. Wu Overview of Operating Systems.
Slide 2-1 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 2 Using the Operating System 2.
Flash: An efficient and portable Web server Authors: Vivek S. Pai, Peter Druschel, Willy Zwaenepoel Presented at the Usenix Technical Conference, June.
1 External Sorting Chapter Why Sort?  A classic problem in computer science!  Data requested in sorted order  e.g., find students in increasing.
Day 10 Threads. Threads and Processes  Process is seen as two entities Unit of resource allocation (process or task) Unit of dispatch or scheduling (thread.
Chapter 4: Threads. Overview Multithreading Models Threading Issues Pthreads Windows XP Threads.
Wednesday, June 07, 2006 “Unix is user friendly … it’s just picky about it’s friends”. - Anonymous.
Server Architecture Models Operating Systems Hebrew University Spring 2004.
1 School of Computing Science Simon Fraser University CMPT 300: Operating Systems I Ch 4: Threads Dr. Mohamed Hefeeda.
Client Server Design Alternatives© Dr. Ayman Abdel-Hamid, CS4254 Spring CS4254 Computer Network Architecture and Programming Dr. Ayman A. Abdel-Hamid.
1 External Sorting Chapter Why Sort?  A classic problem in computer science!  Data requested in sorted order  e.g., find students in increasing.
CS 4432lecture #10 - indexing & hashing1 CS4432: Database Systems II Lecture #10 Professor Elke A. Rundensteiner.
1 Chapter 4 Threads Threads: Resource ownership and execution.
1 External Sorting for Query Processing Yanlei Diao UMass Amherst Feb 27, 2007 Slides Courtesy of R. Ramakrishnan and J. Gehrke.
Chapter 51 Threads Chapter 5. 2 Process Characteristics  Concept of Process has two facets.  A Process is: A Unit of resource ownership:  a virtual.
Processes Part I Processes & Threads* *Referred to slides by Dr. Sanjeev Setia at George Mason University Chapter 3.
Intelligent People. Uncommon Ideas. (A brief overview) Visit for detailshttp://careers.directi.com.
Flash An efficient and portable Web server. Today’s paper, FLASH Quite old (1999) Reading old papers gives us lessons We can see which solution among.
1 Lecture 4: Threads Operating System Fall Contents Overview: Processes & Threads Benefits of Threads Thread State and Operations User Thread.
 Introduction to Operating System Introduction to Operating System  Types Of An Operating System Types Of An Operating System  Single User Single User.
Intelligent People. Uncommon Ideas. Tech (A brief overview) Visit for detailshttp://careers.directi.com.
Threads, Thread management & Resource Management.
Kiew-Hong Chua a.k.a Francis Computer Network Presentation 12/5/00.
Chapter 2 Processes and Threads Introduction 2.2 Processes A Process is the execution of a Program More specifically… – A process is a program.
CSE 451: Operating Systems Winter 2015 Module 5 1 / 2 User-Level Threads & Scheduler Activations Mark Zbikowski 476 Allen Center.
Lecture 5: Threads process as a unit of scheduling and a unit of resource allocation processes vs. threads what to program with threads why use threads.
Chapter 4: Multithreaded Programming. 4.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts What is Thread “Thread is a part of a program.
Threads, Thread management & Resource Management.
Threads. Readings r Silberschatz et al : Chapter 4.
Code Development for High Performance Servers Topics Multithreaded Servers Event Driven Servers Example - Game Server code (Quake) A parallelization exercise.
Chapter 4: Threads. 4.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts – 7 th edition, Jan 23, 2005 Typical Program Processor utilization?
Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition Chapter 4: Threads.
for Event Driven Servers
External Sorting. Why Sort? A classic problem in computer science! Data requested in sorted order –e.g., find students in increasing gpa order Sorting.
Background Computer System Architectures Computer System Software.
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.
Multithreading vs. Event Driven in Code Development of High Performance Servers.
Input/Output (I/O) Important OS function – control I/O
Chapter 4: Threads Modified by Dr. Neerja Mhaskar for CS 3SH3.
Introduction to threads
Getting the Most out of Scientific Computing Resources
Getting the Most out of Scientific Computing Resources
OPERATING SYSTEM CONCEPT AND PRACTISE
Chapter 4: Threads.
CS 6560: Operating Systems Design
Processes and Threads Processes and their scheduling
CS240: Advanced Programming Concepts
Day 12 Threads.
Chapter 4: Multithreaded Programming
Chapter 4 Threads.
Introduction to Parallelism.
Threads & multithreading
Operating Systems (CS 340 D)
Capriccio – A Thread Model
Chapter 15, Exploring the Digital Domain
Chapter 4: Threads.
Modified by H. Schulzrinne 02/15/10 Chapter 4: Threads.
Threads Chapter 4.
Multithreaded Programming
Operating Systems (CS 340 D)
Chapter 4: Threads & Concurrency
Concurrency: Processes CSE 333 Summer 2018
Process Management -Compiled for CSIT
Chapter 4: Threads.
Chapter 1: Introduction CSS503 Systems Programming
Threads -For CSIT.
External Sorting Dina Said
Chapter 4:Threads Book: Operating System Principles , 9th Edition , Abraham Silberschatz, Peter Baer Galvin, Greg Gagne.
Presentation transcript:

Intelligent People. Uncommon Ideas. Async IO, Non Blocking IO, Blocking IO and Multithreading By Bhavin Turakhia CEO, Directi

Agenda Multithreading Blocking IO Async Blocking IO Async Non Blocking IO

Introduction A program performs the following activities – Requests Input Performs Computations Publishes Output A program requires the following resources CPU Memory A CPU can only do one thing at a time

Scenario 1 – Computational Task Person => Process God => CPU Task Inspect the Bucket (purely computational) Will adding additional Persons help? God is busy all the time doing exactly what we want ie computing GOD

Rule 1 – We always want to keep God Busy Rule 1 – We always want to keep the CPU Busy

Scenario 2 – Same Task – Multi-Process Persons => Processes God => CPU Task Inspect the Bucket (purely computational) Now God is busy all the time but not doing what we want Spends time picking up person A Spends time computing Spends time putting person A down Repeat with person B GOD

Rule 2 – We want to keep God Busy doing important stuff. Switching between Persons is not the best utilization of Gods time Rule 2 – We want to keep the CPU Busy doing important stuff. Switching between processes is not the best utilization of the CPUs time

Corollary – Multiple processes reduce performance for tasks that are CPU-bound GOD

Scenario 2 - IO Person => Process God => CPU Bucket => Input Task Wait for Bucket to be filled (Input) Inspect Bucket (Compute) GOD

But God is twiddling his thumbs while the bucket is filling!!!

Rule 1 – We always want to keep God Busy

Scenario 3 – Multiple Processes Persons => Processes God => CPU Bucket => Input God can now switch between Persons while they are blocked on Input GOD

Rule 3 – If a person is waiting for his bucket to be filled, God can drop him and pick up another person Rule 3 – If a process is waiting for IO, the CPU can switch its attention to another Process (context switching)

But Persons are Heavy!!!

Scenario 4 – Multi-threading Person => Process Hands => Threads God => CPU Bucket => Input One Hand per bucket God can now switch between Hands while they are blocked on Input If God picks a hand whose bucket is full, God begins computation Switching between hands is faster than switching between persons GOD

Rule 4 – God can switch between hands, faster than switching between persons Rule 4 – The CPU can switch between threads, faster than switching between processes

Threads vs Processes Threads take up lesser memory -> lesser context switching time -> more efficient CPU utilization Lean towards multi-threaded servers as opposed to multi- process servers Keep in mind other parameters of the application (eg MySQL does not necessarily win Postgres vs MySQL) Async IO will outperform both (depending on the application) More Tips Try and keep the memory utilization of threads to a minimum Try and use separate thread pools to perform separate tasks. That way each thread only has as much context as it requires

Scenario 5 – Async Blocking IO Person => Process Hands => Threads God => CPU Bucket => Input All buckets scanned periodically to check which one is full Number of hands required < Num of buckets (in some cases only 1) Lesser hands => Lesser context switching select() or poll() GOD

Scenario 5 – Async Blocking IO select() and poll() can be used to check status of multiple file descriptors poll() supports unlimited file descriptors while select() has a limit Both calls however are blocking calls, for the duration of the scan Both support a timeout parameter to reduce blocking

Scenario 6 – Async Non-Blocking IO Person => Process Hands => Threads God => CPU Bucket => Input The bucket notifies God that I am done Number of hands required = 1 Epoll(), KQueue GOD

Scenario 5 – Async Blocking IO epoll() and Kqueue()

Advantages of Async Non-blocking IO Removes requirement of threads -> eliminates context switching

Is there a scenario where I would want multiple threads even if I use Async I/O ??

Scenario 6 – More than 1 GOD Each God can only do one thing at a time With Async IO, if I have two Gods, I should have two hands This applies to CPUs and CPU Cores Eg Dual Core Dual CPUs => 4 threads GOD

Software you need to be aware of select(), poll(), epoll() in Linux Kqueue() in BSD AIO Posix AIO for Disk IO Twisted Libevent JDK now supports Async IO Apache MINA Project Grizzly (erstwhile Glassfish)

Async IO Success Stories Tomcat 6.0 – simultaneous connections Apache MINA + Async Web

About Directi A $300 million tech enterprise 500+ employees and growing Ranked amongst the fastest growing Tech companies by Deloitte and Touche for 2005, 2006 and 2007 Revenue and headcount more than doubles every year (Revenue Growth Chart) (Employee Growth Chart)

Facts about Some of Our myriad Products and Services - crawl over 90 million domains provide web services to millions of users power 3+ million domains run on infrastructure spanning hundreds of distributed servers use Petabytes of physical storage space serve billions of page views every month respond to millions of DNS queries every month serve tens of billions of ad units and $150+ million of ad inventory annually

Intelligent People. Uncommon Ideas. | Join us in building a billion dollar Enterprise