Processes, Threads and Virtualization

Slides:



Advertisements
Similar presentations
Chapter 4 Threads Patricia Roy Manatee Community College, Venice, FL ©2008, Prentice Hall Operating Systems: Internals and Design Principles, 6/E William.
Advertisements

Threads, SMP, and Microkernels
Processes: Code Migration Chapter 3 Will Cameron CSC 8530 Dr. Schragger.
Threads, SMP, and Microkernels Chapter 4. Process Resource ownership - process is allocated a virtual address space to hold the process image Scheduling/execution-
Chapter 5 Threads os5.
Computer Systems/Operating Systems - Class 8
Describe the concept of lightweight process (LWP) and the advantages to using LWPs Lightweight process (LWP) lies in a hybrid form of user-level & kernel-level.
Computer Science Lecture 6, page 1 CS677: Distributed OS Processes and Threads Processes and their scheduling Multiprocessor scheduling Threads Distributed.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 5: Threads Overview Multithreading Models Threading Issues Pthreads Solaris.
Tanenbaum & Van Steen, Distributed Systems: Principles and Paradigms, 2e, (c) 2007 Prentice-Hall, Inc. All rights reserved DISTRIBUTED SYSTEMS.
Threads Clients Servers Code Migration Software Agents Summary
EECS122 - UCB 1 CS 194: Distributed Systems Processes, Threads, Code Migration Computer Science Division Department of Electrical Engineering and Computer.
3.5 Interprocess Communication Many operating systems provide mechanisms for interprocess communication (IPC) –Processes must communicate with one another.
3.5 Interprocess Communication
Processes After today’s lecture, you are asked to know The basic concept of thread and process. What are the advantages of using multi-threaded client.
1 Chapter 4 Threads Threads: Resource ownership and execution.
Processes After today’s lecture, you are asked to know The basic concept of thread and process. What are the advantages of using multi-threaded client.
A. Frank - P. Weisberg Operating Systems Introduction to Tasks/Threads.
16: Distributed Systems1 DISTRIBUTED SYSTEM STRUCTURES NETWORK OPERATING SYSTEMS The users are aware of the physical structure of the network. Each site.
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.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 4: Multithreaded Programming.
Processes.
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.
Tanenbaum & Van Steen, Distributed Systems: Principles and Paradigms, 2e, (c) 2007 Prentice-Hall, Inc. All rights reserved DISTRIBUTED.
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.
Chapter 6 Operating System Support. This chapter describes how middleware is supported by the operating system facilities at the nodes of a distributed.
Chapter 34 Java Technology for Active Web Documents methods used to provide continuous Web updates to browser – Server push – Active documents.
Processes Chapter 3. Table of Contents Multithreading Clients and Servers Code Migration Software Agents (special topic)
Processes and Threads Processes have two characteristics: – Resource ownership - process includes a virtual address space to hold the process image – Scheduling/execution.
Tanenbaum & Van Steen, Distributed Systems: Principles and Paradigms, 2e, (c) 2007 Prentice-Hall, Inc. All rights reserved DISTRIBUTED SYSTEMS.
Copyright © George Coulouris, Jean Dollimore, Tim Kindberg This material is made available for private study and for direct.
CE Operating Systems Lecture 3 Overview of OS functions and structure.
DISTRIBUTED SYSTEMS Principles and Paradigms Second Edition ANDREW S
Threads G.Anuradha (Reference : William Stallings)
OPERATING SYSTEM SUPPORT DISTRIBUTED SYSTEMS CHAPTER 6 Lawrence Heyman July 8, 2002.
Processes. Processes and threads Process forms a building block in distributed systems Processes granularity is not sufficient for distributed systems.
Distributed Systems Principles and Paradigms Chapter 03 Processes 00 – 1.
Computer Science Lecture 7, page 1 CS677: Distributed OS Multiprocessor Scheduling Will consider only shared memory multiprocessor Salient features: –One.
1 Threads, SMP, and Microkernels Chapter Multithreading Operating system supports multiple threads of execution within a single process MS-DOS.
CS533 - Concepts of Operating Systems 1 The Mach System Presented by Catherine Vilhauer.
Tanenbaum & Van Steen, Distributed Systems: Principles and Paradigms, 2e, (c) 2007 Prentice-Hall, Inc. All rights reserved DISTRIBUTED SYSTEMS.
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: Threads. 4.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts – 7 th edition, Jan 23, 2005 Chapter 4: Threads Overview Multithreading.
M. Accetta, R. Baron, W. Bolosky, D. Golub, R. Rashid, A. Tevanian, and M. Young MACH: A New Kernel Foundation for UNIX Development Presenter: Wei-Lwun.
© Janice Regan, CMPT 300, May CMPT 300 Introduction to Operating Systems Operating Systems Processes and Threads.
Processes & Threads Introduction to Operating Systems: Module 5.
Acknowledgement: These slides are adapted from slides provided in Thißen & Spaniol's course Distributed Systems and Middleware, RWTH Aachen Processes Distributed.
Processes, Threads and Virtualization Chapter The role of processes in distributed systems.
Operating System Concepts
Lecturer 3: Processes multithreaded Operating System Concepts Process Concept Process Scheduling Operation on Processes Cooperating Processes Interprocess.
1 Chapter 2: Operating-System Structures Services Interface provided to users & programmers –System calls (programmer access) –User level access to system.
Contents 1.Overview 2.Multithreading Model 3.Thread Libraries 4.Threading Issues 5.Operating-system Example 2 OS Lab Sun Suk Kim.
Processes Chapter 3. Processes in Distributed Systems Processes and threads –Introduction to threads –Distinction between threads and processes Threads.
Silberschatz, Galvin and Gagne ©2009Operating System Concepts – 8 th Edition Chapter 4: Threads.
1 Chapter 5: Threads Overview Multithreading Models & Issues Read Chapter 5 pages
Processes and Threads Chapter 3 and 4 Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee Community College,
Introduction to Operating Systems Concepts
DISTRIBUTED SYSTEMS Principles and Paradigms Second Edition ANDREW S
CS 6560: Operating Systems Design
Processes and Threads Processes and their scheduling
Chapter 2 Processes and Threads Today 2.1 Processes 2.2 Threads
Chapter 4 Threads.
Advanced Operating Systems
Chapter 4: Threads.
Threads Chapter 4.
Multithreaded Programming
Prof. Leonardo Mostarda University of Camerino
Chapter 4: Threads.
Presentation transcript:

Processes, Threads and Virtualization Chapter 3.1-3.2 The role of processes in distributed systems

Introduction To be efficient, a client/server system can use asynchronous communication to overlap communication latencies with local processing. Structure processes with multiple threads Virtual machines make it possible for multiple servers to execute securely on a single platform, and to migrate servers from one platform to another. Process migration?

3.1.1 Concurrency Transparency Traditionally, operating systems used the process concept to provide concurrency transparency to executing processes. Process isolation; virtual processors; hardware support Today, multithreading provides concurrency with less overhead (so better performance) Also less transparency – application must provide memory protection for threads.

Large Applications Early operating systems (e.g., UNIX) Supported large apps by supporting the development of several cooperating programs via fork( ) system call (Parent process forks multiple child processes) Rely on IPC mechanisms to exchange info Pipes, message queues, shared memory Overhead: numerous context switches Possible benefits of multiple threads v multiple programs (processes) Less communication overhead Easier to handle asynchronous events Easier to handle priority scheduling Good Posix thread tutorial: https://computing.llnl.gov/tutorials/pthreads/

Forking a New Process http://www.yolinux.com/TUTORIALS/ForkExecProcesses.html http://www.amparo.net/ce155/fork-ex.html

Thread Conceptually, one of (possibly several) concurrent execution paths contained in a process. If two processes want to share data or other resources, the OS must be involved. Overhead: system calls, mode switches, context switches, extra execution time. Two threads in a single process can share global data automatically – as easily as two functions in a single process OS protects processes from one another; not so for threads within a single process.

Threads – Revisited Multithreading is useful in the following kinds of situations: To allow a program to do I/O and computations at the “same” time: one thread blocks to wait for input, others can continue to execute To allow separate threads in a program to be distributed across several processors in a shared memory multiprocessor To allow a large application to be structured as cooperating threads, rather than cooperating processes (avoiding excess context switches) Multithreading also can simplify program development (divide-and-conquer) In a SMP, each thread can have a processor, shared data is stored in shared memory.

Overhead Due to Process Switching Restore CPU context Modify data in MMU registers . . . Save CPU context Modify data in MMU registers Invalidate TLB entries . . . Figure 3-1. Context switching as the result of IPC.

Threads POSIX: http://www.yolinux.com/TUTORIALS/LinuxTutorialPosixThreads.html#CREATIONTERMINATION Thread discussion: http://www.cs.cf.ac.uk/Dave/C/node29.html Java Thread Tutorial: http://download.oracle.com/javase/tutorial/essential/concurrency/procthread.html

Thread Implementation Kernel-level Support multiprocessing Independently schedulable by OS Can continue to run if one thread blocks on a system call. User-level Less overhead than k-level; faster execution Light weight processes (LWP) Example: in Sun’s Solaris OS Scheduler activations Research based

Kernel-level Threads The kernel is aware of the threads and schedules them independently as if they were processes. One thread may block for I/O, or some other event, while other threads in the process continue to run. Most of the previously mentioned uses of threads assume this kind. A kernel-level thread in a user process does not have kernel privileges.

User-level Threads User-level threads are created by calling functions in a user-level library. The process that uses user-level threads appears (to the OS) to be a single threaded process so there is no way to distribute the threads in a multiprocessor or block only part of the process. The advantage here is that they are even more efficient than kernel threads – no mode switches are involved in thread creation or switching.

Hybrid Threads –Lightweight Processes (LWP) LWP is similar to a kernel-level thread: It runs in the context of a regular process The process can have several LWPs created by the kernel in response to a system call. User level threads are created by calls to the user-level thread package. The thread package also has a scheduling algorithm for threads, runnable by LWPs.

Thread Implementation Figure 3-2. Combining kernel-level lightweight processes and user-level threads.

Hybrid threads – LWP The OS schedules an LWP which uses the thread scheduler to decide which thread to run. Thread synchronization and context switching are done at the user level; LWP is not involved and continues to run. If a thread makes a blocking system call control passes to the OS (mode switch) The OS can schedule another LWP or let the existing LWP continue to execute, in which case it will look for another thread to run.

Hybrid threads – LWP Solaris is a system that uses a variation of the hybrid approach. Solaris implementation has evolved somewhat over time Processes have LWP and user-level threads (1-1 correspondence). The LWP is bound to a kernel level thread which is schedulable as an independent entity. Separates the process of thread creation from thread scheduling.

Advantages of the hybrid approach Most thread operations (create, destroy, synchronize) are done at the user level Blocking system calls need not block the whole process Applications only deal with user-level threads LWPs can be scheduled in parallel on the separate processing elements of a multiprocessor.

Scheduler Activations Another approach to combining benefits of u-level and k-level threads When a thread blocks on a system call, the kernel executes an upcall to a thread scheduler in user space which selects another runnable thread Violates the principles of layered software

Threads in Distributed Systems Threads gain much of their power by sharing an address space But … no sharing in distributed systems However, multithreading can be used to improve the performance of individual nodes in a distributed system. A process, running on a single machine; e.g., a client or a server, can be multithreaded to improve performance

Multithreaded Clients Main advantage: hide network latency Addresses problems such as delays in downloading documents from web servers in a WAN Hide latency by starting several threads One to download text (display as it arrives) Others to download photographs, figures, etc. All threads execute simple blocking system calls; easy to program this model Browser displays results as they arrive.

Multithreaded Clients Even better: if servers are replicated, the multiple threads may be sent to separate sites. Result: data can be downloaded in several parallel streams, improving performance even more. Designate a thread in the client to handle and display each incoming data stream.

Multithreaded Servers Improve performance, provide better structuring Consider what a file server does: Wait for a request Execute request (may require blocking I/O) Send reply to client Several models for programming the server Single threaded Multi-threaded Finite-state machine

Threads in Distributed Systems - Servers A single-threaded (iterative) server processes one request at a time – other requests must wait. Possible solution: create (fork) a new server process for a new request. This approach creates performance problems (servers must share file system information) Creating a new server thread is much more efficient. Processing is overlapped and shared data structures can be accessed without extra context switches.

Multithreaded Servers Figure 3-3. A multithreaded server organized in a dispatcher/worker model.

Finite-state machine The file server is single threaded but doesn’t block for I/O operations Instead, save state of current request, switch to a new task – client request or disk reply. Outline of operation: Get request, process until blocking I/O is needed Save state of current request, start I/O, get next task If task = completed I/O, resume process waiting on that I/O using saved state, else service a new request if there is one.

3.2: Virtualization Multiprogrammed operating systems provide the illusion of simultaneous execution through resource virtualization Use software to make it look like concurrent processes are executing simultaneously Virtual machine technology creates separate virtual machines, capable of supporting multiple instances of different operating systems.

Benefits Hardware changes faster than software Suppose you want to run an existing application and the OS that supports it on a new computer: the VMM layer makes it possible to do so. Compromised systems (internal failure or external attack) are isolated. Run multiple different operating systems at the same time

Role of Virtualization in Distributed Systems Portability of virtual machines supports moving (or copying) servers to new computers Multiple servers can safely share a single computer Portability and security (isolation) are the critical characteristics.

Interfaces Offered by Computer Systems* Unprivileged machine instructions: available to any program Privileged instructions: hardware interface for the OS/other privileged software System calls: interface to the operating system for applications & library functions API: An OS interface through library function calls from applications.

Two Ways to Virtualize* Process Virtual Machine: program is compiled to intermediate code, executed by a runtime system Virtual Machine Monitor: software layer mimics the instruction set; supports an OS and its applications

Processes in a Distributed System Chapter 3.3, 3.4, 3.5 Clients, Servers, and Code Migration

Another Distributed System Definition “Distributed computing systems are networked computer systems in which the different components of a software application program run on different computers on a network, but all of the distributed components work cooperatively as if all were running on the same machine.” http://faculty.bus.olemiss.edu/breithel/final%20backup%20of%20bus620%20summer%202000%20from%20mba%20server/frankie_gulledge/corba/corba_overview.htm Client and server components run on different or same machine (usually different)

3.3: Client Side Software Manages user interface Parts of the processing and data (maybe) Support for distribution transparency Access transparency: Client side stubs hide communication and hardware details. Location, migration, and relocation transparency rely on naming systems, among other techniques Failure transparency (e.g., client middleware can make multiple attempts to connect to a server)

Client-Side Software for Replication Transparency Figure 3-10. Transparent replication of a server using a client-side solution. Here, the client application is shielded from replication issues by client-side software that takes a single request and turns it into multiple requests; takes multiple responses and turn them into a single response.

3.4: Servers Processes that implement a service for a collection of clients Passive: servers wait until a request arrives Server Design: Iterative servers: handles one request at a time, returns response to client Concurrent servers: act as a central receiving point Multithreaded servers versus forking a new process

Contacting the Server Client requests are sent to an end point, or port, at the server machine. How are port numbers located? Global: e.g; 21 for FTP requests and 80 for HTTP Or, contact a daemon on a server machine that runs multiple services. For services that don’t need to run continuously, superservers can listen to several ports, create servers as needed. For example, in the Xen scenario, with many unpopular servers sharing a single computer via virtual machines.

Stateful versus Stateless Some servers keep no information about clients (Stateless) Example: a web server which honors HTTP requests doesn’t need to remember which clients have contacted it. Stateful servers retain information about clients and their current state, e.g., updating file X. Loss of state may lead to permanent loss of information.

Server Clusters A server cluster is a collection of machines, connected through a network, where each machine runs one or more services. Often clustered on a LAN Three tiered structure is common Client requests are routed to one of the servers through a front-end switch

Server Clusters (1) Figure 3-12. The general organization of a three-tiered server cluster.

Three tiered server cluster Tier 1: the switch (access/replication transparency) Tier 2: the servers Some server clusters may need special compute-intensive machines in this tier to process data Tier 3: data-processing servers, e.g. file servers and database servers For other applications, the major part of the workload may be here

Server Clusters In some clusters, all server machines run the same services In others, different machines provide different services May benefit from load balancing One proposed use for virtual machines

3.5 - Code Migration: Overview Instead of distributed system communication based on passing data, why not pass code instead? Load balancing Reduce communication overhead Parallelism; e.g., mobile agents for web searches Flexibility – configure system architectures dynamically Code migration v process migration Process migration may require moving the entire process state; can the overhead be justified? Early DS’s focused on process migration & tried to provide it transparently

Client-Server Examples Example 1: (Send Client code to Server) Server manages a huge database. If a client application needs to perform many database operations, it may be better to ship part of the client application to the server and send only the results across the network. Example 2: (Send Server code to Client) In many interactive DB applications, clients need to fill in forms that are subsequently translated into a series of DB operations. Reduce network traffic, improve service. Security issues?

Examples Mobile agents: independent code modules that can migrate from node to node in a network and interact with local hosts; e.g. to conduct a search at several sites in parallel Dynamic configuration of DS: Instead of pre-installing client-side software to support remote server access, download it dynamically from the server when it is needed.

Code Migration Figure 3-17. The principle of dynamically configuring a client to communicate to a server. The client first fetches the necessary software, and then invokes the server.

A Model for Code Migration (1) as described in Fuggetta et. al. 1998 Three components of a process: Code segment: the executable instructions Resource segment: references to external resources (files, printers, other processes, etc.) Execution segment: contains the current state Private data, stack, program counter, other registers, etc. – data that will be saved during a context switch.

A Model for Code Migration (2) Weak mobility: transfer the code segment and possibly some initialization data. Process can only migrate before it begins to run, or perhaps at a few intermediate points. Requirements: portable code Example: Java applets Strong mobility: transfer code segment and execution segment. Processes can migrate after they have already started to execute Much more difficult

A Model for Code Migration (3) Sender-initiated: initiated at the “home” of the migrating code e.g., upload code to a compute server; launch a mobile agent, send code to a DB Receiver-initiated: host machine downloads code to be executed locally e.g., applets, download client code, etc. If used for load balancing, sender-initiated migration lets busy sites send work elsewhere; receiver initiated lets idle machines volunteer to assume excess work.

Security in Code Migration Code executing remotely may have access to remote host’s resources, so it should be trusted. For example, code uploaded to a server might be able to corrupt its disk Question: should migrated code execute in the context of an existing process or as a separate process created at the target machine? Java applets execute in the context of the target machine’s browser Efficiency (no need to create new address space) versus potential for mistakes or security violations in the executing process.

Cloning v Process Migration* Cloned processes can be created by a fork instruction (as in UNIX) and executed at a remote site Migration by cloning improves distribution transparency because it is based on a familiar programming model UNIX has a clone() function that connects to a remote host, copies the process over, executes a fork() & exec() to start it. http://linuxgazette.net/issue51/vrenios.html

Models for Code Migration* Figure 3-18. Alternatives for code migration.

Resource Migration* Resources are bound to processes By identifier: resource reference that identifies a particular object; e.g. a URL, an IP address, local port numbers. By value: reference to a resource that can be replaced by another resource with the same “value”, for example, a standard library. By type: reference to a resource by a type; e.g., a printer or a monitor Code migration cannot change (weaken) the way processes are bound to resources.

Resource Migration* How resources are bound to machines: Unattached: easy to move; my own files Fastened: harder/more expensive to move; a large DB or a Web site Fixed: can’t be moved; local devices Global references: meaningful across the system Rather than move fastened or fixed resources, try to establish a global reference

Migration and Local Resources* Figure 3-19. Actions to be taken with respect to the references to local resources when migrating code to another machine.

Migration in Heterogeneous Systems Different computers, different operating systems – migrated code is not compatible Can be addressed by providing process virtual machines: Directly interpret the migrated code at the host site (as with scripting languages) Interpret intermediate code generated by a compiler (as with Java)

Migrating Virtual Machines A virtual machine encapsulates an entire computing environment. If properly implemented, the VM provides strong mobility since local resources may be part of the migrated environment “Freeze” an environment (temporarily stop executing processes) & move entire state to another machine e.g. In a server cluster, migrated environments support maintenance activities such as replacing a machine.

Migration of Virtual Machines Example: real-time (“live”) migration of a virtualized operating system with all its running services among machines in a server cluster on a local area network. Presented in the paper “Live Migration of Virtual Machines”, Christopher Clark, et. al. Problems: Migrating the memory image (page tables, in-memory pages, etc.) Migrating bindings to local resources

Memory Migration in Virtual Machines Three possible approaches Pre-copy: push memory pages to the new machine and resend the ones that are later modified during the migration process. Stop-and-copy: pause the current virtual machine; migrate memory, and start the new virtual machine. Let the new virtual machine pull in new pages as needed, using demand paging Clark et.al use a combination of pre-copy and stop-and-copy; claim downtimes of 200ms or less.

Resource Migration in a Cluster Migrating local resource bindings is simplified in this example because we assume all machines are located on the same LAN. “Announce” new address to clients If data storage is located in a third tier, migration of file bindings is trivial.