Introduce Concurrency Threading in Servers. A Recurring Theme Concurrent programming is not for the weak hearted! –Deadlocks, blocked threads, critical.

Slides:



Advertisements
Similar presentations
Concurrency Important and difficult (Ada slides copied from Ed Schonberg)
Advertisements

Ade Azurat, Advanced Programming 2004 (Based on LYS Stefanus’s slides) Advanced Programming 2004, Based on LYS Stefanus’s slides Slide 2.1 Multithreading.
Liang, Introduction to Java Programming, Seventh Edition, (c) 2009 Pearson Education, Inc. All rights reserved Chapter 5 Multithreading and.
Multithreading The objectives of this chapter are:
Threads Load new page Page is loading Browser still responds to user (can read pages in other tabs)
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 5: Threads Overview Multithreading Models Threading Issues Pthreads Solaris.
Precept 3 COS 461. Concurrency is Useful Multi Processor/Core Multiple Inputs Don’t wait on slow devices.
1 Chapter 4 Threads Threads: Resource ownership and execution.
Race Conditions CS550 Operating Systems. Review So far, we have discussed Processes and Threads and talked about multithreading and MPI processes by example.
Threads Chapter 4. Modern Process & Thread –Process is an infrastructure in which execution takes place  (address space + resources) –Thread is a program.
Multithreading.
Discussion Week 3 TA: Kyle Dewey. Overview Concurrency overview Synchronization primitives Semaphores Locks Conditions Project #1.
1 Thread II Slides courtesy of Dr. Nilanjan Banerjee.
- Tausief Shaikh (Senior Server developer). Introduction Covers sense of responsibility towards Project development in IT Focusing on memory and CPU utilizations.
Locks CSCI 201L Jeffrey Miller, Ph.D. HTTP :// WWW - SCF. USC. EDU /~ CSCI 201 USC CSCI 201L.
Object Oriented Analysis & Design SDL Threads. Contents 2  Processes  Thread Concepts  Creating threads  Critical sections  Synchronizing threads.
Threads Many software packages are multi-threaded Web browser: one thread display images, another thread retrieves data from the network Word processor:
ICOM 6115©Manuel Rodriguez-Martinez ICOM 6115 – Computer Networks and the WWW Manuel Rodriguez-Martinez, Ph.D. Lecture 6.
Threads in Java. History  Process is a program in execution  Has stack/heap memory  Has a program counter  Multiuser operating systems since the sixties.
Multi-Threaded Application CSNB534 Asma Shakil. Overview Software applications employ a strategy called multi- threaded programming to split tasks into.
1 Concurrent Languages – Part 1 COMP 640 Programming Languages.
Java Threads 11 Threading and Concurrent Programming in Java Introduction and Definitions D.W. Denbo Introduction and Definitions D.W. Denbo.
An Intro to Programming with C# Threads Presentation by: Jason Bender, Garrett Lund, Ben Gamble, Michael Calvo, and Jeff Corbell.
Proactor Pattern Venkita Subramonian & Christopher Gill
Copyright ©: University of Illinois CS 241 Staff1 Threads Systems Concepts.
Synchronizing threads, thread pools, etc.
Laboratory - 4.  Threading Concept  Threading in.NET  Multi-Threaded Socket  Example.
Week 3, Day 2: Threads Questions about Threads “Multithreading” in Swing Lab tomorrow: Quiz Lab 3: Threading! SE-2811 Slide design: Dr. Mark L. Hornick.
Multithreading Chapter Introduction Consider ability of _____________ to multitask –Breathing, heartbeat, chew gum, walk … In many situations we.
Multithreading Chapter Introduction Consider ability of human body to ___________ –Breathing, heartbeat, chew gum, walk … In many situations we.
Java Thread and Memory Model
Concurrency Control 1 Fall 2014 CS7020: Game Design and Development.
Concurrency & Context Switching Process Control Block What's in it and why? How is it used? Who sees it? 5 State Process Model State Labels. Causes of.
13-1 Chapter 13 Concurrency Topics Introduction Introduction to Subprogram-Level Concurrency Semaphores Monitors Message Passing Java Threads C# Threads.
Thread basics. A computer process Every time a program is executed a process is created It is managed via a data structure that keeps all things memory.
Project 2 Overview (Threads in Practice) CSE451 Andrew Whitaker.
C H A P T E R E L E V E N Concurrent Programming Programming Languages – Principles and Paradigms by Allen Tucker, Robert Noonan.
Multithreading The objectives of this chapter are: To understand the purpose of multithreading To describe Java's multithreading mechanism.
1 Why Threads are a Bad Idea (for most purposes) based on a presentation by John Ousterhout Sun Microsystems Laboratories Threads!
L6: Threads “the future is parallel” COMP206, Geoff Holmes and Bernhard Pfahringer.
CSC Multiprocessor Programming, Spring, 2012 Chapter 10 – Avoiding Liveness Hazards Dr. Dale E. Parson, week 11.
Producer/Consumer CSCI 201L Jeffrey Miller, Ph.D. HTTP :// WWW - SCF. USC. EDU /~ CSCI 201 USC CSCI 201L.
Concurrent Programming in Java Based on Notes by J. Johns (based on Java in a Nutshell, Learning Java) Also Java Tutorial, Concurrent Programming in Java.
Contents 1.Overview 2.Multithreading Model 3.Thread Libraries 4.Threading Issues 5.Operating-system Example 2 OS Lab Sun Suk Kim.
Asynchronous Programming Writing Asynchronous Code in Java SoftUni Team Technical Trainers Software University
Multithreading The objectives of this chapter are:
A brief intro to: Parallelism, Threads, and Concurrency
Multithreading / Concurrency
Scalability: Load Balancing
Multi Threading.
Slide design: Dr. Mark L. Hornick
PA1 Discussion.
Advanced Topics in Concurrency and Reactive Programming: Asynchronous Programming Majeed Kassis.
Processes and Threads Processes and their scheduling
CSC Multiprocessor Programming, Spring, 2011
Distributed Systems - Comp 655
Multithreading Chapter 23.
Prof. Leonardo Mostarda University of Camerino
Concurrency: Processes CSE 333 Summer 2018
Threads and Multithreading
Slide design: Dr. Mark L. Hornick
Chapter 4: Threads.
Multithreading The objectives of this chapter are:
Software Engineering and Architecture
Software Engineering and Architecture
Software Engineering and Architecture
Concurrency in GO CS240 23/8/2017.
CSC Multiprocessor Programming, Spring, 2011
Java Chapter 3 (Estifanos Tilahun Mihret--Tech with Estif)
Presentation transcript:

Introduce Concurrency Threading in Servers

A Recurring Theme Concurrent programming is not for the weak hearted! –Deadlocks, blocked threads, critical regions, … Tactics and Patterns –Ressource pool –Introduce Concurrency Bærbak Christensen2

Thread Pool Thread pool –Keep a fixed size pool of N threads ready –Accept request and Retrieve a thread from pool to process request Return thread to pool after processing has finished –Result N requests can be processed in parallel Bærbak Christensen3

Why Not… Multi-threaded –Accept request and Spawn a new thread Terminate thread after processing has finished Why is this a lesser solution? –Performance (time/space) –Availability Bærbak Christensen4

Java Support ExecutorService Hint: Jenkov has nice tutorial –SocketReactor is modeled over his single-thread srv. Bærbak Christensen5

In Action… Bærbak Christensen6

But… Bærbak Christensen7

Parallel Execution The nasty-ness of shared resources hits us… Let us analyze the flow in SkyCave –Consider that a max peak we have 15 concurrent threads commited to executing requests from 15 clients Can some of these 15 requests represent a request from the same player? Some may include ‘login’s? Bærbak Christensen8

In Reactor s = serverSocket.accept() –readAndDispatch(s) Bærbak Christensen9 Any problems?

In Invoker Bærbak Christensen10

In (Player) Dispatcher Bærbak Christensen11

Ex: digRoom Bærbak Christensen12

MongoDB Phew… –Seems we are safe there… Bærbak Christensen13

Java Concurrency Super fast reiteration Bærbak Christensen14

Monitor Add ‘syncronized’ to a method –Becomes critical region Only one thread allowed to execute at a time –Multiple threads wait in queue for execution If several threads call the method at the same time The ‘queue’ controlling object is the object of the method –i.e. there is a ‘per object’ queue –If the method freeze All queued threads does as well! Bærbak Christensen15

ReentrantLock You can declare a specific ‘queue/lock’ object and synchronize on that –More tedios, but much finer control Locking across a set of objects –Allows timeout!Avoid ‘blocked threads’ Bærbak Christensen16

Idiom Alternative: tryLock(timeout) Bærbak Christensen17 lock.lock(); try { // critical region } finally { lock.unlock(); } lock.lock(); try { // critical region } finally { lock.unlock(); }

Tutorials… Jenkov’s tutorials appear very nice… Bærbak Christensen18

Our Tool Stack Help! Bærbak Christensen19

Blocked Threads! Load Generator, my faulty first version –N players execute M sets of operations Output Bærbak Christensen20

How to diagnose? ‘jvisualvm’ Bærbak Christensen21

Thread Dump Pick VM, Threads Pane, Click Thead Dump Bærbak Christensen22

Review Dump Locate the blocking thread, see stack trace ! Bærbak Christensen23

Monitoring Performance Started ‘load.cave’ Bærbak Christensen24

More Load Started SkyCave app server on small machine Bærbak Christensen25

More Load Started 1 x load.cave of 100 players each Bærbak Christensen26

More Load Started 15 x load.cave of 100 players each Bærbak Christensen27 One server, Approx req/s One server, Approx req/s

The ‘Lyon Airport’ Test Karibu System: Daemon died from exhausted memory Bærbak Christensen28

Going Further Bærbak Christensen29