Rapid Development of High Performance Servers Khaled ElMeleegy Alan Cox Willy Zwaenepoel.

Slides:



Advertisements
Similar presentations
Lazy Asynchronous I/O For Event-Driven Servers Khaled Elmeleegy, Anupam Chanda and Alan L. Cox Department of Computer Science Rice University, Houston,
Advertisements

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.
Threads. Objectives To introduce the notion of a thread — a fundamental unit of CPU utilization that forms the basis of multithreaded computer systems.
Threads.
Flash: An efficient and portable Web server Authors: Vivek S. Pai, Peter Druschel, Willy Zwaenepoel Presented at the Usenix Technical Conference, June.
CSC 501 Lecture 2: Processes. Von Neumann Model Both program and data reside in memory Execution stages in CPU: Fetch instruction Decode instruction Execute.
Course: Operating Systems Instructor: Umar Kalim NUST Institute of Information Technology, Pakistan Operating Systems.
Precept 3 COS 461. Concurrency is Useful Multi Processor/Core Multiple Inputs Don’t wait on slow devices.
4.1 Silberschatz, Galvin and Gagne ©2005 Operating System Principles Chapter 4 Multithreaded Programming Objectives Objectives To introduce a notion of.
Threads - Definition - Advantages using Threads - User and Kernel Threads - Multithreading Models - Java and Solaris Threads - Examples - Definition -
CS533 Concepts of Operating Systems Class 5 Event-Based Systems.
Threads CSCI 444/544 Operating Systems Fall 2008.
Chapter 4: Threads. 4.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts – 7 th edition, Jan 23, 2005 Chapter 4: Threads Overview Multithreading.
Chapter 4: Threads. 4.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Objectives Thread definitions and relationship to process Multithreading.
Threads CS 416: Operating Systems Design, Spring 2001 Department of Computer Science Rutgers University
Silberschatz, Galvin and Gagne ©2009Operating System Concepts – 8 th Edition Chapter 4: Threads.
Chapter 4: Threads. 4.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Chapter 4: Threads Overview Multithreading Models Threading Issues.
 A JavaScript runtime environment running Google Chrome’s V8 engine ◦ a.k.a. a server-side solution for JS ◦ Compiles JS, making it really fast  Runs.
Chapter 51 Threads Chapter 5. 2 Process Characteristics  Concept of Process has two facets.  A Process is: A Unit of resource ownership:  a virtual.
1 Lecture 4: Threads Operating System Fall Contents Overview: Processes & Threads Benefits of Threads Thread State and Operations User Thread.
Chapter 4: Multithreaded Programming. 4.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Chapter 4: Multithreaded Programming Overview.
Multithreading Allows application to split itself into multiple “threads” of execution (“threads of execution”). OS support for creating threads, terminating.
Chapter 4: Threads. 4.2 Chapter 4: Threads Overview Multithreading Models Threading Issues Pthreads Windows XP Threads Linux Threads Java Threads.
Silberschatz, Galvin and Gagne ©2011Operating System Concepts Essentials – 8 th Edition Chapter 4: Threads.
Threads Many software packages are multi-threaded Web browser: one thread display images, another thread retrieves data from the network Word processor:
1 RTOS Design Some of the content of this set of slides is taken from the documentation existing on the FreeRTOS website
Continuations And Java Regis -
Background: Operating Systems Brad Karp UCL Computer Science CS GZ03 / M th November, 2008.
Multiprogramming. Readings r Silberschatz, Galvin, Gagne, “Operating System Concepts”, 8 th edition: Chapter 3.1, 3.2.
Chapter 2 Processes and Threads Introduction 2.2 Processes A Process is the execution of a Program More specifically… – A process is a program.
1 Lecture 4: Threads Advanced Operating System Fall 2010.
CSE 451: Operating Systems Winter 2015 Module 5 1 / 2 User-Level Threads & Scheduler Activations Mark Zbikowski 476 Allen Center.
Operating Systems CSE 411 CPU Management Sept Lecture 10 Instructor: Bhuvan Urgaonkar.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 4: Threads.
Processes, Threads, and Process States. Programs and Processes  Program: an executable file (before/after compilation)  Process: an instance of a program.
Processes & Threads Introduction to Operating Systems: Module 5.
LAIO: Lazy Asynchronous I/O For Event Driven Servers Khaled Elmeleegy Alan L. Cox.
CSC 360, Instructor: Kui Wu Thread & PThread. CSC 360, Instructor: Kui Wu Agenda 1.What is thread? 2.User vs kernel threads 3.Thread models 4.Thread issues.
Threads versus Events CSE451 Andrew Whitaker. This Class Threads vs. events is an ongoing debate  So, neat-and-tidy answers aren’t necessarily available.
An Efficient Threading Model to Boost Server Performance Anupam Chanda.
OSes: 2. Structs 1 Operating Systems v Objective –to give a (selective) overview of computer system architectures Certificate Program in Software Development.
Code Development for High Performance Servers Topics Multithreaded Servers Event Driven Servers Example - Game Server code (Quake) A parallelization exercise.
1 Why Threads are a Bad Idea (for most purposes) based on a presentation by John Ousterhout Sun Microsystems Laboratories Threads!
for Event Driven Servers
Operating System Concepts
Lecturer 3: Processes multithreaded Operating System Concepts Process Concept Process Scheduling Operation on Processes Cooperating Processes Interprocess.
Multithreading vs. Event Driven in Code Development of High Performance Servers.
Advanced Operating Systems CS6025 Spring 2016 Processes and Threads (Chapter 2)
Multiprogramming. Readings r Chapter 2.1 of the textbook.
Introduction to Operating Systems Concepts
OPERATING SYSTEM CONCEPT AND PRACTISE
Chapter 4: Threads.
Process concept.
Threads vs. Events SEDA – An Event Model 5204 – Operating Systems.
Why Events Are A Bad Idea (for high-concurrency servers)
CS 6560: Operating Systems Design
Scheduler activations
Chapter 4: Multithreaded Programming
Chapter 4: Threads.
Operating System Concepts
Chapter 4: Threads.
Threads Chapter 4.
Threads and Concurrency
Chapter 4: Threads.
Chapter 4: Threads.
Chapter 4: Threads.
Chapter 4: Threads.
CS703 – Advanced Operating Systems
Chapter 4: Threads.
CS Introduction to Operating Systems
Presentation transcript:

Rapid Development of High Performance Servers Khaled ElMeleegy Alan Cox Willy Zwaenepoel

Goals Maximize server utilization and decrease its latency. –Server process doesn’t block! Robust under heavy loads. Relatively easy to develop.

Key Idea Get the best of the two worlds. Event Driven Multi-Threaded Programming level: Implementation level: Multi-threaded serversEvent driven servers Lazy threaded servers

1-KQueue Kernel event notification mechanism. Supported by FreeBSD Kernel. Events queued in a kernel queue, and delivered to user by kernel calls. Events usually correspond to AIO completions, or socket reads/writes. Background

2-AIO Asynchronous I/O mainly used for disk reads/writes. Issue disk request and return immediately without blocking for results. On completion an event is sent to KQueue.

3-Servers Architectures: a- Multi-threaded Servers  Kernel thread per request executing the request handler.  A thread blocking on I/O doesn’t block the server.  Ex: Apache, MySql. Request Handler A B C Function Calls

Multi-threaded Servers (Cont.) Advantages: + Relatively easy to develop. Disadvantages: - Not good performance. Thread scheduling. Context switching. - Doesn’t scale. Under heavy load, many threads would be created exhausting kernel’s memory, crashing the server.

 Single thread (event loop).  AIO operations.  I/O completions / Requests (events) put in Event Queue.  Continuations.  Ex:Flash web server (slightly different architecture). + High performance. + Scalable/Robust. - Hard to write. b- Event Driven Servers Event Loop A1 B1 C1 A2 B2 C2 Events From Kernel “Blocking” operation Event Queue (KQueue)

Lazy Threading Similar design to event driven but no continuations. Threads yield control on fixed points (I/O).  If request handler doesn’t “block” –Run handler to completion then use same thread to handle next event.  Else –Suspend current thread, create another user thread to handle next event.

Wrappers / Thread Suspension IO_Wrapper(..) { uc = save_user_context(..); /* save the current user thread context to be able to resume it later */ aio_func(..); /* non-blocking I/O call */ stack=allocate_stack(); switch_thread(event_loop,stack); /* suspend current thread and create a new thread running the event loop using the newly allocated stack */. } Wrappers around “blocking” operations to create the blocking illusion. Uses AIO. Saves current stack instead of unwinding it. Creates a user thread by jumping to the event loop and using a new stack.

Thread Resumption Event_loop() {. e = get_event(..); /* read new event from the kernel’s kqueue */ if e is completion of aio_func(..) run_thread(uc); /* dispose current thread and resume the IO_Wrapper from where it has stopped */. } Restores registers and jumps back to wrapper as if blocking has finished. Current thread is disposed as it’s useless. Wrapper’s thread eventually returns to the event loop after handling its request.

ServLib Library for fast server development. Provides an infrastructure for building lazy-threaded servers. Hides all the lazy threading details from the server developer. Used to upgrade existing servers, or build new servers.

How to use ServLib Extract the event handler code from the old server/some library or write your own. Initialize ServLib with : –request handler function. –listening port number. Change all blocking calls in the request handler to use the wrappers exported by ServLib.

Experimentation Implementing then comparing the performance of 3 versions of a database server (from sqlite library). And of a similar 3 versions of a web server (from mini_httpd). –A multi-threaded version, –An event driven version and –A lazy threaded version. Use FreeBSD 4.6

Summary Yes NoHigh Performance No YesThread / request? Yes (user) NoYes (kernel) >1 thread NoN/AYesArbitrary thread yield YesNoYes“Easy” to build Yes NoScalable Lazy- Threaded Event Driven Multi- Threaded

Questions?