Multithreading, Blocking IO and Async IO

Loading...

Flash Player 9 (or above) is needed to view presentations.
We have detected that you do not have it on your computer. To install it, go here.

0 comments

Post a comment

    Post a comment
    Embed Video
    Edit your comment Cancel

    Favorites, Groups & Events

    Multithreading, Blocking IO and Async IO - Presentation Transcript

    1. Multithreading, Blocking IO and Async IO By Bhavin Turakhia CEO, Directi [email_address]
    2. Agenda
      • Multithreading
      • Blocking IO
      • Async Blocking IO
      • Async Non Blocking IO
    3. 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
    4. Analogy = Task = Process = CPU GOD
    5. Scenario 1 – Computational Task
      • Person => Process
      • God => CPU
      • Task
        • Inspect the Bucket (purely computational)
      • 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
      • Will adding one more person make a difference?
    6. 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 God’s 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
    7. 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
    8. 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!!!
    9. 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 take up lesser memory -> lesser context switching time -> more efficient CPU utilization
      Threads vs Processes
    10. Is there a scenario where I would want to use processes instead of threads anyways?
    11. Scenario 5 – Async IO
      • Person => Process
      • Hands => Threads
      • God => CPU
      • Bucket => Input
      • The bucket notifies God that I am done
      • Number of hands required = 1
      GOD
    12. Scenario 5 – Async Blocking IO
      • epoll() and Kqueue()
    13. Advantages of Async Non-blocking IO
      • Removes requirement of threads -> eliminates context switching
    14. Is there a scenario where I would want multiple threads even if I use Async I/O ??
    15. 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 GOD
    16. Async IO Success Story
      • Tomcat 6.0 – 16000 simultaneous connections
      • Apache MINA + Async Web
    17. http://www.directi.com | http://careers.directi.com Questions? Email me: [email_address] Follow me: http://twitter.com/bhavintu Facebook: http://www.facebook.com/bhavin.t Blog: http://bhavin.directi.com Website: http://directi.com Download Slides: http://wiki.directi.com
    SlideShare Zeitgeist 2009

    + Directi GroupDirecti Group Nominate

    custom

    173 views, 0 favs, 0 embeds more stats

    More info about this document

    © All Rights Reserved

    Go to text version

    • Total Views 173
      • 173 on SlideShare
      • 0 from embeds
    • Comments 0
    • Favorites 0
    • Downloads 0
    Most viewed embeds

    more

    All embeds

    less

    Flagged as inappropriate Flag as inappropriate
    Flag as inappropriate

    Select your reason for flagging this presentation as inappropriate. If needed, use the feedback form to let us know more details.

    Cancel
    File a copyright complaint
    Having problems? Go to our helpdesk?

    Categories