Processes: Hongfei Yan School of EECS, Peking University 3/16/2011
Processes: Hongfei Yan School of EECS, Peking University 3/16/2011
Processes: Hongfei Yan School of EECS, Peking University 3/16/2011
http://net.pku.edu.cn/~course/cs501/2011
Contents
Chapter 01: Introduction 02: Architectures 03: Processes 04: Communication 05: Naming 06: Synchronization 07: Consistency & Replication 08: Fault Tolerance 09: Security 10: Distributed Object-Based Systems 11: Distributed File Systems 12: Distributed Web-Based Systems 13: Distributed Coordination-Based Systems
2/N
03: Processes
3.1 Threads 3.2 Virtualization 3.3 Clients 3.4 Servers 3.5 Code Migration
3/N
3.1 Threads
3.1.1 Introduction to Threads 3.1.2 Threads in Distributed Systems
4/N
Basic ideas
We build virtual processors in software, on top of physical processors: Processor: Provides a set of instructions along with the capability of automatically executing a series of those instructions. Thread: A minimal software processor in whose context a series of instructions can be executed. Saving a thread context implies stopping the current execution and saving all the data needed to continue the execution at a later stage. Process: A software processor in whose context one or more threads may be executed. Executing a thread, means executing a series of instructions in the context of that thread.
5/N
Context Switching
Processor context: The minimal collection of values stored in the registers of a processor used for the execution of a series of instructions (e.g., stack pointer, addressing registers, program counter). Thread context: The minimal collection of values stored in registers and memory, used for the execution of a series of instructions (i.e., processor context, state). Process context: The minimal collection of values stored in registers and memory, used for the execution of a thread (i.e., thread context, but now also at least MMU register values).
6/N
Observation 1: Threads share the same address space. Do we need OS involvement? Observation 2: Process switching is generally more expensive. OS is involved.
e.g., trapping to the kernel.
Observation 3: Creating and destroying threads is cheaper than doing it for a process.
7/N
8/N
Conclusion: Try to mix user-level and kernel-level threads into a single concept.
7
10/N
Hybrid (Solaris)
Use two levels. Multiplex user threads on top of LWPs (kernel threads).
11/N
When a user-level thread does a syscall, the LWP blocks. Thread is bound to LWP. Kernel schedules another LWP. Context switches can occur at the userlevel. When no threads to schedule, a LWP may be removed. Note
This concept has been virtually abandoned its just either user-level or kernel-level threads.
12/N
13/N
Suppose there are ten images in a page. How should they be fetched?
Sequentially
fetch_sequential() { for (int i = 0; i < 10; i++) { int sockfd = ...; write(sockfd, "HTTP GET ..."); n = read_till_socket_closed(sockfd, jpeg[i], 100K); } }
Fetching Images
Concurrently
fetch_concurrent() { int thread_ids[10]; for (int i = 0; i < 10; i++) { thread_ids[i] = start_read_thread(urls[i], jpeg[i]); } for (int i = 0; i < 10; i++) { wait_for_thread(thread_ids[i]); } }
Which is faster?
14/N
A FSM implemented
Using a single process that awaits messages containing requests and performs the actions they specify, as in a server.
1. 2. 3. 4. Read any available input. Process the input chunk. Save state of that request. Loop.
16/N
Better structure:
Using simple blocking I/O calls is easier. Multithreaded programs tend to be simpler.
Multithreaded Servers
Multithreaded Servers
Three ways to construct a server.
Characteristics Parallelism, blocking system calls No parallelism, blocking system calls Parallelism, nonblocking system calls
19/N
3.2 Virtualization
3.2.1 The Role of Virtualization in Distributed Systems 3.2.2 Architectures of Virtual Machines
20/N
21/N
Virtualization
Observation: Virtualization is becoming increasingly important:
Hardware changes faster than software Ease of portability and code migration Isolation of failing or attacked components
A virtual machine can support individual processes or a complete system depending on the abstraction level where virtualization occurs. Some VMs support flexible hardware usage and software isolation, while others translate from one instruction set to another. [James and Ravi,2005] E. S. James and N. Ravi, "The Architecture of Virtual Machines," Computer, vol. 38, pp. 32-38, 2005.
22/N
(a) Abstraction provides a simplified interface to underlying resources. (b) Virtualization provides a different interface or different resources at the same abstraction level.
23/N
Virtualization
Originally developed by IBM. Virtualization is increasingly important.
Ease of portability. Isolation of failing or attacked components. Ease of running different configurations, versions, etc. Replicate whole web site to edge server.
Virtualization can take place at very different levels, strongly depending on the interfaces as offered by various systems components:
25/N
Process VM: A program is compiled to intermediate (portable) code, which is then executed by a runtime system. (Example: Java VM) VMM: A separate software layer mimics the instruction set of hardware: a complete OS and its apps can be supported. (Example: VMware, VirtualBox)
26/N
3.3 Clients
3.3.1 Networked User Interfaces 3.3.2 Client-Side Software for Distributed Systems
27/N
Create a reusable GUI toolkit that runs on the client. GUI can be directly manipulated by the server-side application code.
This is a thin-client approach.
28/N
Thick client
The protocol is application specific. For re-use, can be layered, but at the top, it is application-specific.
29/N
Thin-client
30/N
X Window System
The X Window System (commonly referred to as X or X11) is a network-transparent graphical windowing system based on a client/server model.
Primarily used on Unix and Unix-like systems such as Linux, versions of X are also available for many other operating systems. Although it was developed in 1984, X is not only still available but also is in fact the standard environment for Unix windowing systems.
31/N
Scalability problems of X
Too much bandwidth is needed.
By using compression techniques, bandwidth can be considerably reduced.
Compound documents
User interface is applicationaware => interapplication communication
drag-and-drop: move objects across the screen to invoke interaction with other applications in-place editing: integrate several applications at user-interface level (word processing + drawing facilities)
35/N
Client-Side Software
Often tailored for distribution transparency.
Access transparency: client-side stubs for RPCs. Location/migration transparency: Let clientside software keep track of actual location. Replication transparency: Multiple invocations handled by client-side stub. Failure transparency: Can often be placed only at client.
36/N
37/N
3.4 Servers
3.4.1 General Design Issues 3.4.2 Server Clusters 3.4.3 Managing Server Clusters
38/N
ftp-data 20 File Transfer [Default Data] ftp 21 File Transfer [Control] telnet 23 Telnet 24 any private mail system Smtp 25 Simple Mail Transfer login 49 Login Host Protocol Sunrpc 111 SUN RPC (portmapper) Courier 530 Xerox RPC
39/N
Superservers: Listen to multiple end points, then spawn the right server.
40/N
41/N
Out-of-Band Communication
Issue: Is it possible to interrupt a server once it has accepted (or is in the process of accepting) a service request? Solution 1: Use a separate port for urgent data (possibly per service request):
Server has a separate thread (or process) waiting for incoming urgent messages When urgent message comes in, associated request is put on
hold
Note: we require OS supports high-priority scheduling of specific threads or processes
connection
Urgent messages can be caught using OS signaling techniques
42/N
Stateless Servers
Never keep accurate information about the status of a client after having handled a request:
Dont record whether a file has been opened (simply close it again after access) Dont promise to invalidate a clients cache Dont keep track of your clients
Consequences:
Clients and servers are completely independent State inconsistencies due to client or server crashes are reduced Possible loss of performance
because, e.g., a server cannot anticipate client behavior (think of prefetching file blocks)
43/N
Stateful Servers
Keeps track of the status of its clients:
Record that a file has been opened, so that prefetching can be done Knows which data a client has cached, and allows clients to keep local copies of shared data
Observation: The performance of stateful servers can be extremely high, provided clients are allowed to keep local copies.
Session state vs. permanent state As it turns out, reliability is not a major problem.
44/N
Cookies
A small piece of data containing client-specific information that is of interest to the server Cookies and related things can serve two purposes:
They can be used to correlate the current client operation with a previous operation. They can be used to store state.
For example, you could put exactly what you were buying, and what step you were in, in the checkout process.
45/N
Server Clusters
Observation: Many server clusters are organized along three different tiers, to improve performance.
Typical organization below, into three tiers. 2 and 3 can be merged.
Crucial element: The first tier is generally responsible for passing requests to an appropriate server.
46/N
Request Handling
Observation: Having the first tier handle all communication from/to the cluster may lead to a bottleneck. Solution: Various, but one popular one is TCP-handoff:
47/N
Distributed Servers
We can be even more distributed.
But over a wide area network, the situation is too dynamic to use TCP handoff. Instead, use Mobile IP. Are the servers really moving around?
Mobile IP
A server has a home address (HoA), where it can always be contacted. It leaves a care-of address (CoA), where it actually is. Application still uses HoA.
48/N
49/N
Next step, provide a single management framework that will let you monitor the whole cluster, and distribute updates en masse.
Works for medium sized. What if you have a 5,000 nodes? Need continuous repair, essentially autonomic computing.
50/N
Example: PlanetLab
Essence: Different organizations contribute machines, which they subsequently share for various experiments. Problem: We need to ensure that different distributed applications do not get into each others way => virtualization
51/N
PlanetLab
Vserver: Independent and protected environment with its own libraries, server versions, and so on. Distributed applications are assigned a collection of vservers distributed across multiple machines (slice).
52/N
Monitoring tools available assume a very specific combination of hardware and software.
All tailored to be used within a single organization.
Programs from different slices but running on the same node should not interfere with each other.
53/N
Node manager
Separate vserver Task: create other vservers and control resource allocation No policy decisions
Slice creation service (SCS) runs on node, receives creation requests from some slice authority.
SCS contacts node manager. Node manager cannot be contacted directly. (Separation of mechanism from policy.)
To create a slice, a service provider will contact a slice authority and ask it to create a slice. Also have management authorities that monitor nodes, make sure running right software, etc.
54/N
3 4 Service provider
56/N
Approaches
Why code migration?
Moving from heavily loaded to lightly loaded. Also, to minimize communication costs. Moving code to data, rather than data to code. Late binding for a protocol. (Download it.)
57/N
The principle of dynamically configuring a client to communicate to a server. The client first fetches the necessary software, and then invokes the server.
58/N
Execution segment: store the current execution state of a process, consisting of private data, the stack, and the program counter
59/N
A Reference Model
60/N
Initiation
Sender-initiated migration Receiver-initiated migration
61/N
62/N
63/N
Fixed: the resource cannot be migrated, such as local hardware (bound to the machine)
E.g., a local communication end point
64/N
GR: Establish a global system-wide reference MV: Move the resource CP: Copy the value of the resource RB: Rebind the process to a locally available resource
66/N
Only solution: Make use of an abstract machine that is implemented on different platforms
67/N
Current Solustions
Interpreted languages running on a virtual machine
E.g., Java/JVM; scripting languages
68/N
69/N