Amir H. Payberah amir@sics · Introduction I Processor: provides aset of instructionsalong with the...

86
Processes Amir H. Payberah [email protected] Amirkabir University of Technology (Tehran Polytechnic) Based on slides by Maarten Van Steen Amir H. Payberah (Tehran Polytechnic) Processes 1393/12/4 1 / 47

Transcript of Amir H. Payberah amir@sics · Introduction I Processor: provides aset of instructionsalong with the...

Page 1: Amir H. Payberah amir@sics · Introduction I Processor: provides aset of instructionsalong with the capability of automaticallyexecuting a series of those instructions. I Thread:

Processes

Amir H. [email protected]

Amirkabir University of Technology(Tehran Polytechnic)

Based on slides by Maarten Van Steen

Amir H. Payberah (Tehran Polytechnic) Processes 1393/12/4 1 / 47

Page 2: Amir H. Payberah amir@sics · Introduction I Processor: provides aset of instructionsalong with the capability of automaticallyexecuting a series of those instructions. I Thread:

Introduction

I Processor: provides a set of instructions along with the capabilityof automatically executing a series of those instructions.

I Thread: a minimal software processor in whose context a series ofinstructions can be executed.

I Process: a software processor in whose context one or more threadsmay be executed.

Amir H. Payberah (Tehran Polytechnic) Processes 1393/12/4 2 / 47

Page 3: Amir H. Payberah amir@sics · Introduction I Processor: provides aset of instructionsalong with the capability of automaticallyexecuting a series of those instructions. I Thread:

Introduction

I Processor: provides a set of instructions along with the capabilityof automatically executing a series of those instructions.

I Thread: a minimal software processor in whose context a series ofinstructions can be executed.

I Process: a software processor in whose context one or more threadsmay be executed.

Amir H. Payberah (Tehran Polytechnic) Processes 1393/12/4 2 / 47

Page 4: Amir H. Payberah amir@sics · Introduction I Processor: provides aset of instructionsalong with the capability of automaticallyexecuting a series of those instructions. I Thread:

Introduction

I Processor: provides a set of instructions along with the capabilityof automatically executing a series of those instructions.

I Thread: a minimal software processor in whose context a series ofinstructions can be executed.

I Process: a software processor in whose context one or more threadsmay be executed.

Amir H. Payberah (Tehran Polytechnic) Processes 1393/12/4 2 / 47

Page 5: Amir H. Payberah amir@sics · Introduction I Processor: provides aset of instructionsalong with the capability of automaticallyexecuting a series of those instructions. I Thread:

Context

I Processor context: the minimal collection of values stored in the reg-isters of a processor used for the execution of a series of instructions(e.g., stack pointer, addressing registers, program counter).

I Thread context: the minimal collection of values stored in registersand memory, used for the execution of a series of instructions.

I Process context: the minimal collection of values stored in registersand memory, used for the execution of a thread.

Amir H. Payberah (Tehran Polytechnic) Processes 1393/12/4 3 / 47

Page 6: Amir H. Payberah amir@sics · Introduction I Processor: provides aset of instructionsalong with the capability of automaticallyexecuting a series of those instructions. I Thread:

Context

I Processor context: the minimal collection of values stored in the reg-isters of a processor used for the execution of a series of instructions(e.g., stack pointer, addressing registers, program counter).

I Thread context: the minimal collection of values stored in registersand memory, used for the execution of a series of instructions.

I Process context: the minimal collection of values stored in registersand memory, used for the execution of a thread.

Amir H. Payberah (Tehran Polytechnic) Processes 1393/12/4 3 / 47

Page 7: Amir H. Payberah amir@sics · Introduction I Processor: provides aset of instructionsalong with the capability of automaticallyexecuting a series of those instructions. I Thread:

Context

I Processor context: the minimal collection of values stored in the reg-isters of a processor used for the execution of a series of instructions(e.g., stack pointer, addressing registers, program counter).

I Thread context: the minimal collection of values stored in registersand memory, used for the execution of a series of instructions.

I Process context: the minimal collection of values stored in registersand memory, used for the execution of a thread.

Amir H. Payberah (Tehran Polytechnic) Processes 1393/12/4 3 / 47

Page 8: Amir H. Payberah amir@sics · Introduction I Processor: provides aset of instructionsalong with the capability of automaticallyexecuting a series of those instructions. I Thread:

Context Switching

I Threads share the same address space. Thread context switchingcan be done entirely independent of the operating system (OS).

I Process switching is generally more expensive as it involves gettingthe OS in the loop, i.e., trapping to the kernel.

I Creating and destroying threads is much cheaper than doing so forprocesses.

Amir H. Payberah (Tehran Polytechnic) Processes 1393/12/4 4 / 47

Page 9: Amir H. Payberah amir@sics · Introduction I Processor: provides aset of instructionsalong with the capability of automaticallyexecuting a series of those instructions. I Thread:

Context Switching

I Threads share the same address space. Thread context switchingcan be done entirely independent of the operating system (OS).

I Process switching is generally more expensive as it involves gettingthe OS in the loop, i.e., trapping to the kernel.

I Creating and destroying threads is much cheaper than doing so forprocesses.

Amir H. Payberah (Tehran Polytechnic) Processes 1393/12/4 4 / 47

Page 10: Amir H. Payberah amir@sics · Introduction I Processor: provides aset of instructionsalong with the capability of automaticallyexecuting a series of those instructions. I Thread:

Context Switching

I Threads share the same address space. Thread context switchingcan be done entirely independent of the operating system (OS).

I Process switching is generally more expensive as it involves gettingthe OS in the loop, i.e., trapping to the kernel.

I Creating and destroying threads is much cheaper than doing so forprocesses.

Amir H. Payberah (Tehran Polytechnic) Processes 1393/12/4 4 / 47

Page 11: Amir H. Payberah amir@sics · Introduction I Processor: provides aset of instructionsalong with the capability of automaticallyexecuting a series of those instructions. I Thread:

Threads and Operating Systems (1/4)

I Question: should an OS kernel provide threads, or should they beimplemented as user-level packages?

Lightweight process

Thread

Kernel space

User space

LWP executing a thread

Thread state

Amir H. Payberah (Tehran Polytechnic) Processes 1393/12/4 5 / 47

Page 12: Amir H. Payberah amir@sics · Introduction I Processor: provides aset of instructionsalong with the capability of automaticallyexecuting a series of those instructions. I Thread:

Threads and Operating Systems (2/4)

I User-space solution.

• All operations can be completely handled within a single process ⇒implementations can be extremely efficient.

• All services provided by the kernel are done on behalf of the processin which a thread resides ⇒ if the kernel decides to block a thread,the entire process will be blocked.

• Threads are used when there are lots of external events: threadsblock on a per-event basis.

Lightweight process

Thread

Kernel space

User space

LWP executing a thread

Thread state

Amir H. Payberah (Tehran Polytechnic) Processes 1393/12/4 6 / 47

Page 13: Amir H. Payberah amir@sics · Introduction I Processor: provides aset of instructionsalong with the capability of automaticallyexecuting a series of those instructions. I Thread:

Threads and Operating Systems (2/4)

I User-space solution.

• All operations can be completely handled within a single process ⇒implementations can be extremely efficient.

• All services provided by the kernel are done on behalf of the processin which a thread resides ⇒ if the kernel decides to block a thread,the entire process will be blocked.

• Threads are used when there are lots of external events: threadsblock on a per-event basis.

Lightweight process

Thread

Kernel space

User space

LWP executing a thread

Thread state

Amir H. Payberah (Tehran Polytechnic) Processes 1393/12/4 6 / 47

Page 14: Amir H. Payberah amir@sics · Introduction I Processor: provides aset of instructionsalong with the capability of automaticallyexecuting a series of those instructions. I Thread:

Threads and Operating Systems (2/4)

I User-space solution.

• All operations can be completely handled within a single process ⇒implementations can be extremely efficient.

• All services provided by the kernel are done on behalf of the processin which a thread resides ⇒ if the kernel decides to block a thread,the entire process will be blocked.

• Threads are used when there are lots of external events: threadsblock on a per-event basis.

Lightweight process

Thread

Kernel space

User space

LWP executing a thread

Thread state

Amir H. Payberah (Tehran Polytechnic) Processes 1393/12/4 6 / 47

Page 15: Amir H. Payberah amir@sics · Introduction I Processor: provides aset of instructionsalong with the capability of automaticallyexecuting a series of those instructions. I Thread:

Threads and Operating Systems (2/4)

I User-space solution.

• All operations can be completely handled within a single process ⇒implementations can be extremely efficient.

• All services provided by the kernel are done on behalf of the processin which a thread resides ⇒ if the kernel decides to block a thread,the entire process will be blocked.

• Threads are used when there are lots of external events: threadsblock on a per-event basis.

Lightweight process

Thread

Kernel space

User space

LWP executing a thread

Thread state

Amir H. Payberah (Tehran Polytechnic) Processes 1393/12/4 6 / 47

Page 16: Amir H. Payberah amir@sics · Introduction I Processor: provides aset of instructionsalong with the capability of automaticallyexecuting a series of those instructions. I Thread:

Threads and Operating Systems (3/4)

I Kernel solution: the kernel contains the implementation of a threadpackage. This means that all operations return as system calls.

• Operations that block a thread are no longer a problem: the kernelschedules another available thread within the same process.

• Handling external events is simple: the kernel schedules the threadassociated with the event.

• The big problem is the loss of efficiency due to the fact that eachthread operation requires a trap to the kernel.

Lightweight process

Thread

Kernel space

User space

LWP executing a thread

Thread state

Amir H. Payberah (Tehran Polytechnic) Processes 1393/12/4 7 / 47

Page 17: Amir H. Payberah amir@sics · Introduction I Processor: provides aset of instructionsalong with the capability of automaticallyexecuting a series of those instructions. I Thread:

Threads and Operating Systems (3/4)

I Kernel solution: the kernel contains the implementation of a threadpackage. This means that all operations return as system calls.

• Operations that block a thread are no longer a problem: the kernelschedules another available thread within the same process.

• Handling external events is simple: the kernel schedules the threadassociated with the event.

• The big problem is the loss of efficiency due to the fact that eachthread operation requires a trap to the kernel.

Lightweight process

Thread

Kernel space

User space

LWP executing a thread

Thread state

Amir H. Payberah (Tehran Polytechnic) Processes 1393/12/4 7 / 47

Page 18: Amir H. Payberah amir@sics · Introduction I Processor: provides aset of instructionsalong with the capability of automaticallyexecuting a series of those instructions. I Thread:

Threads and Operating Systems (3/4)

I Kernel solution: the kernel contains the implementation of a threadpackage. This means that all operations return as system calls.

• Operations that block a thread are no longer a problem: the kernelschedules another available thread within the same process.

• Handling external events is simple: the kernel schedules the threadassociated with the event.

• The big problem is the loss of efficiency due to the fact that eachthread operation requires a trap to the kernel.

Lightweight process

Thread

Kernel space

User space

LWP executing a thread

Thread state

Amir H. Payberah (Tehran Polytechnic) Processes 1393/12/4 7 / 47

Page 19: Amir H. Payberah amir@sics · Introduction I Processor: provides aset of instructionsalong with the capability of automaticallyexecuting a series of those instructions. I Thread:

Threads and Operating Systems (3/4)

I Kernel solution: the kernel contains the implementation of a threadpackage. This means that all operations return as system calls.

• Operations that block a thread are no longer a problem: the kernelschedules another available thread within the same process.

• Handling external events is simple: the kernel schedules the threadassociated with the event.

• The big problem is the loss of efficiency due to the fact that eachthread operation requires a trap to the kernel.

Lightweight process

Thread

Kernel space

User space

LWP executing a thread

Thread state

Amir H. Payberah (Tehran Polytechnic) Processes 1393/12/4 7 / 47

Page 20: Amir H. Payberah amir@sics · Introduction I Processor: provides aset of instructionsalong with the capability of automaticallyexecuting a series of those instructions. I Thread:

Threads and Operating Systems (4/4)

I Conclusion• Try to mix user-level and kernel-level threads into a single concept.

Lightweight process

Thread

Kernel space

User space

LWP executing a thread

Thread state

Amir H. Payberah (Tehran Polytechnic) Processes 1393/12/4 8 / 47

Page 21: Amir H. Payberah amir@sics · Introduction I Processor: provides aset of instructionsalong with the capability of automaticallyexecuting a series of those instructions. I Thread:

Threads and Distributed Systems (1/4)

I Multithreaded web client: hiding network latencies.

• Web browser scans an incoming HTML page, and finds that morefiles need to be fetched.

• Each file is fetched by a separate thread, each doing a (blocking)HTTP request.

• As files come in, the browser displays them.

Amir H. Payberah (Tehran Polytechnic) Processes 1393/12/4 9 / 47

Page 22: Amir H. Payberah amir@sics · Introduction I Processor: provides aset of instructionsalong with the capability of automaticallyexecuting a series of those instructions. I Thread:

Threads and Distributed Systems (1/4)

I Multithreaded web client: hiding network latencies.

• Web browser scans an incoming HTML page, and finds that morefiles need to be fetched.

• Each file is fetched by a separate thread, each doing a (blocking)HTTP request.

• As files come in, the browser displays them.

Amir H. Payberah (Tehran Polytechnic) Processes 1393/12/4 9 / 47

Page 23: Amir H. Payberah amir@sics · Introduction I Processor: provides aset of instructionsalong with the capability of automaticallyexecuting a series of those instructions. I Thread:

Threads and Distributed Systems (2/4)

I Multiple request-response calls to other machines (RPC).

• A client does several calls at the same time, each one by a differentthread.

• It then waits until all results have been returned.

• Note: if calls are to different servers, we may have a linear speed-up.

Amir H. Payberah (Tehran Polytechnic) Processes 1393/12/4 10 / 47

Page 24: Amir H. Payberah amir@sics · Introduction I Processor: provides aset of instructionsalong with the capability of automaticallyexecuting a series of those instructions. I Thread:

Threads and Distributed Systems (2/4)

I Multiple request-response calls to other machines (RPC).

• A client does several calls at the same time, each one by a differentthread.

• It then waits until all results have been returned.

• Note: if calls are to different servers, we may have a linear speed-up.

Amir H. Payberah (Tehran Polytechnic) Processes 1393/12/4 10 / 47

Page 25: Amir H. Payberah amir@sics · Introduction I Processor: provides aset of instructionsalong with the capability of automaticallyexecuting a series of those instructions. I Thread:

Threads and Distributed Systems (3/4)

I Improve performance

• Starting a thread is much cheaper than starting a new process.

• Having a single-threaded server prohibits simple scale-up to a multi-processor system.

• As with clients: hide network latency by reacting to next requestwhile previous one is being replied.

Amir H. Payberah (Tehran Polytechnic) Processes 1393/12/4 11 / 47

Page 26: Amir H. Payberah amir@sics · Introduction I Processor: provides aset of instructionsalong with the capability of automaticallyexecuting a series of those instructions. I Thread:

Threads and Distributed Systems (3/4)

I Improve performance

• Starting a thread is much cheaper than starting a new process.

• Having a single-threaded server prohibits simple scale-up to a multi-processor system.

• As with clients: hide network latency by reacting to next requestwhile previous one is being replied.

Amir H. Payberah (Tehran Polytechnic) Processes 1393/12/4 11 / 47

Page 27: Amir H. Payberah amir@sics · Introduction I Processor: provides aset of instructionsalong with the capability of automaticallyexecuting a series of those instructions. I Thread:

Threads and Distributed Systems (4/4)

I Better structure

• Most servers have high I/O demands. Using simple, well-understoodblocking calls simplifies the overall structure.

• Multithreaded programs tend to be smaller and easier to understanddue to simplified flow of control.

Amir H. Payberah (Tehran Polytechnic) Processes 1393/12/4 12 / 47

Page 28: Amir H. Payberah amir@sics · Introduction I Processor: provides aset of instructionsalong with the capability of automaticallyexecuting a series of those instructions. I Thread:

Clients

Amir H. Payberah (Tehran Polytechnic) Processes 1393/12/4 13 / 47

Page 29: Amir H. Payberah amir@sics · Introduction I Processor: provides aset of instructionsalong with the capability of automaticallyexecuting a series of those instructions. I Thread:

Clients

I A major part of client-side software is focused on (graphical) userinterfaces.

X kernel

Device drivers

Application

Xlib

Xlib interface

X protocol

Terminal (includes displaykeyboard, mouse, etc.)

Application serverApplication server User's terminal

Local OS

Window manager

Xlib

Local OS

I User interface is application-aware:• 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)

Amir H. Payberah (Tehran Polytechnic) Processes 1393/12/4 14 / 47

Page 30: Amir H. Payberah amir@sics · Introduction I Processor: provides aset of instructionsalong with the capability of automaticallyexecuting a series of those instructions. I Thread:

Clients

I A major part of client-side software is focused on (graphical) userinterfaces.

X kernel

Device drivers

Application

Xlib

Xlib interface

X protocol

Terminal (includes displaykeyboard, mouse, etc.)

Application serverApplication server User's terminal

Local OS

Window manager

Xlib

Local OS

I User interface is application-aware:• 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)

Amir H. Payberah (Tehran Polytechnic) Processes 1393/12/4 14 / 47

Page 31: Amir H. Payberah amir@sics · Introduction I Processor: provides aset of instructionsalong with the capability of automaticallyexecuting a series of those instructions. I Thread:

Client-Side Software

I Generally tailored for distribution transparency.

I Access transparency: client-side stubs for RPCs

I Location/migration transparency: let client-side software keep trackof actual location

I Replication transparency: multiple invocations handled by clientstub.

Client machine

Replicated request

Server 1 Server 2 Server 3

Client side handles request replication

Client appl.

Server appl

Server appl

Server appl

I Failure transparency: can often be placed only at client (we’re tryingto mask server and communication failures).

Amir H. Payberah (Tehran Polytechnic) Processes 1393/12/4 15 / 47

Page 32: Amir H. Payberah amir@sics · Introduction I Processor: provides aset of instructionsalong with the capability of automaticallyexecuting a series of those instructions. I Thread:

Client-Side Software

I Generally tailored for distribution transparency.

I Access transparency: client-side stubs for RPCs

I Location/migration transparency: let client-side software keep trackof actual location

I Replication transparency: multiple invocations handled by clientstub.

Client machine

Replicated request

Server 1 Server 2 Server 3

Client side handles request replication

Client appl.

Server appl

Server appl

Server appl

I Failure transparency: can often be placed only at client (we’re tryingto mask server and communication failures).

Amir H. Payberah (Tehran Polytechnic) Processes 1393/12/4 15 / 47

Page 33: Amir H. Payberah amir@sics · Introduction I Processor: provides aset of instructionsalong with the capability of automaticallyexecuting a series of those instructions. I Thread:

Client-Side Software

I Generally tailored for distribution transparency.

I Access transparency: client-side stubs for RPCs

I Location/migration transparency: let client-side software keep trackof actual location

I Replication transparency: multiple invocations handled by clientstub.

Client machine

Replicated request

Server 1 Server 2 Server 3

Client side handles request replication

Client appl.

Server appl

Server appl

Server appl

I Failure transparency: can often be placed only at client (we’re tryingto mask server and communication failures).

Amir H. Payberah (Tehran Polytechnic) Processes 1393/12/4 15 / 47

Page 34: Amir H. Payberah amir@sics · Introduction I Processor: provides aset of instructionsalong with the capability of automaticallyexecuting a series of those instructions. I Thread:

Client-Side Software

I Generally tailored for distribution transparency.

I Access transparency: client-side stubs for RPCs

I Location/migration transparency: let client-side software keep trackof actual location

I Replication transparency: multiple invocations handled by clientstub.

Client machine

Replicated request

Server 1 Server 2 Server 3

Client side handles request replication

Client appl.

Server appl

Server appl

Server appl

I Failure transparency: can often be placed only at client (we’re tryingto mask server and communication failures).

Amir H. Payberah (Tehran Polytechnic) Processes 1393/12/4 15 / 47

Page 35: Amir H. Payberah amir@sics · Introduction I Processor: provides aset of instructionsalong with the capability of automaticallyexecuting a series of those instructions. I Thread:

Client-Side Software

I Generally tailored for distribution transparency.

I Access transparency: client-side stubs for RPCs

I Location/migration transparency: let client-side software keep trackof actual location

I Replication transparency: multiple invocations handled by clientstub.

Client machine

Replicated request

Server 1 Server 2 Server 3

Client side handles request replication

Client appl.

Server appl

Server appl

Server appl

I Failure transparency: can often be placed only at client (we’re tryingto mask server and communication failures).

Amir H. Payberah (Tehran Polytechnic) Processes 1393/12/4 15 / 47

Page 36: Amir H. Payberah amir@sics · Introduction I Processor: provides aset of instructionsalong with the capability of automaticallyexecuting a series of those instructions. I Thread:

Servers

Amir H. Payberah (Tehran Polytechnic) Processes 1393/12/4 16 / 47

Page 37: Amir H. Payberah amir@sics · Introduction I Processor: provides aset of instructionsalong with the capability of automaticallyexecuting a series of those instructions. I Thread:

Servers

I A server is a process that waits for incoming service requests at aspecific transport address (port). In practice, there is a one-to-onemapping between a port and a service.

ftp-data 20 File Transfer [Default Data]

ftp 21 File Transfer [Control]

telnet 23 Telnet

smtp 25 Simple Mail Transfer

login 49 Login Host Protocol

sunrpc 111 SUN RPC (portmapper)

courier 530 Xerox RPC

Amir H. Payberah (Tehran Polytechnic) Processes 1393/12/4 17 / 47

Page 38: Amir H. Payberah amir@sics · Introduction I Processor: provides aset of instructionsalong with the capability of automaticallyexecuting a series of those instructions. I Thread:

Types of Servers

I Superservers: servers that listen to several ports, i.e., provide severalindependent services. In practice, when a service request comes in,they start a subprocess to handle the request.

I Iterative vs. concurrent servers: iterative servers can handle only oneclient at a time, in contrast to concurrent servers.

Amir H. Payberah (Tehran Polytechnic) Processes 1393/12/4 18 / 47

Page 39: Amir H. Payberah amir@sics · Introduction I Processor: provides aset of instructionsalong with the capability of automaticallyexecuting a series of those instructions. I Thread:

Types of Servers

I Superservers: servers that listen to several ports, i.e., provide severalindependent services. In practice, when a service request comes in,they start a subprocess to handle the request.

I Iterative vs. concurrent servers: iterative servers can handle only oneclient at a time, in contrast to concurrent servers.

Amir H. Payberah (Tehran Polytechnic) Processes 1393/12/4 18 / 47

Page 40: Amir H. Payberah amir@sics · Introduction I Processor: provides aset of instructionsalong with the capability of automaticallyexecuting a series of those instructions. I Thread:

Server and State (1/2)

I Stateless and stateful servers

I Stateless servers: never keep accurate information about the statusof a client after having handled a request:

• Don’t record whether a file has been opened (simply close it againafter access)

• Don’t promise to invalidate a client’s cache• Don’t keep track of your clients

I 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)

Amir H. Payberah (Tehran Polytechnic) Processes 1393/12/4 19 / 47

Page 41: Amir H. Payberah amir@sics · Introduction I Processor: provides aset of instructionsalong with the capability of automaticallyexecuting a series of those instructions. I Thread:

Server and State (1/2)

I Stateless and stateful servers

I Stateless servers: never keep accurate information about the statusof a client after having handled a request:

• Don’t record whether a file has been opened (simply close it againafter access)

• Don’t promise to invalidate a client’s cache• Don’t keep track of your clients

I 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)

Amir H. Payberah (Tehran Polytechnic) Processes 1393/12/4 19 / 47

Page 42: Amir H. Payberah amir@sics · Introduction I Processor: provides aset of instructionsalong with the capability of automaticallyexecuting a series of those instructions. I Thread:

Server and State (1/2)

I Stateless and stateful servers

I Stateless servers: never keep accurate information about the statusof a client after having handled a request:

• Don’t record whether a file has been opened (simply close it againafter access)

• Don’t promise to invalidate a client’s cache• Don’t keep track of your clients

I 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)

Amir H. Payberah (Tehran Polytechnic) Processes 1393/12/4 19 / 47

Page 43: Amir H. Payberah amir@sics · Introduction I Processor: provides aset of instructionsalong with the capability of automaticallyexecuting a series of those instructions. I Thread:

Server and State (1/2)

I Stateless and stateful servers

I Stateless servers: never keep accurate information about the statusof a client after having handled a request:

• Don’t record whether a file has been opened (simply close it againafter access)

• Don’t promise to invalidate a client’s cache• Don’t keep track of your clients

I 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)

Amir H. Payberah (Tehran Polytechnic) Processes 1393/12/4 19 / 47

Page 44: Amir H. Payberah amir@sics · Introduction I Processor: provides aset of instructionsalong with the capability of automaticallyexecuting a series of those instructions. I Thread:

Server and State (2/2)

I 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

I The performance of stateful servers can be extremely high, providedclients are allowed to keep local copies. As it turns out, reliability isnot a major problem.

Amir H. Payberah (Tehran Polytechnic) Processes 1393/12/4 20 / 47

Page 45: Amir H. Payberah amir@sics · Introduction I Processor: provides aset of instructionsalong with the capability of automaticallyexecuting a series of those instructions. I Thread:

Server and State (2/2)

I 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

I The performance of stateful servers can be extremely high, providedclients are allowed to keep local copies. As it turns out, reliability isnot a major problem.

Amir H. Payberah (Tehran Polytechnic) Processes 1393/12/4 20 / 47

Page 46: Amir H. Payberah amir@sics · Introduction I Processor: provides aset of instructionsalong with the capability of automaticallyexecuting a series of those instructions. I Thread:

Server and State (2/2)

I 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

I The performance of stateful servers can be extremely high, providedclients are allowed to keep local copies. As it turns out, reliability isnot a major problem.

Amir H. Payberah (Tehran Polytechnic) Processes 1393/12/4 20 / 47

Page 47: Amir H. Payberah amir@sics · Introduction I Processor: provides aset of instructionsalong with the capability of automaticallyexecuting a series of those instructions. I Thread:

Server Clusters (1/2)

I Three different tiers.

I The first tier is generally responsible for passing requests to an ap-propriate server.

Logical switch (possibly multiple)

Application/compute servers Distributed file/database

system

Client requests

Dispatched request

First tier Second tier Third tier

Amir H. Payberah (Tehran Polytechnic) Processes 1393/12/4 21 / 47

Page 48: Amir H. Payberah amir@sics · Introduction I Processor: provides aset of instructionsalong with the capability of automaticallyexecuting a series of those instructions. I Thread:

Server Clusters (2/2)

I Having the first tier handle all communication from/to the clustermay lead to a bottleneck.

I Solution: various, but one popular one is TCP-handoff

Switch Client

Server

Server

RequestRequest

(handed off)

ResponseLogically asingle TCPconnection

Amir H. Payberah (Tehran Polytechnic) Processes 1393/12/4 22 / 47

Page 49: Amir H. Payberah amir@sics · Introduction I Processor: provides aset of instructionsalong with the capability of automaticallyexecuting a series of those instructions. I Thread:

Server Clusters (2/2)

I Having the first tier handle all communication from/to the clustermay lead to a bottleneck.

I Solution: various, but one popular one is TCP-handoff

Switch Client

Server

Server

RequestRequest

(handed off)

ResponseLogically asingle TCPconnection

Amir H. Payberah (Tehran Polytechnic) Processes 1393/12/4 22 / 47

Page 50: Amir H. Payberah amir@sics · Introduction I Processor: provides aset of instructionsalong with the capability of automaticallyexecuting a series of those instructions. I Thread:

Example: Planet Lab (1/2)

I Different organizations contribute machines, which they subse-quently share for various experiments.

I Problem: we need to ensure that different distributed applicationsdo not get into each other’s way ⇒ virtualization

Amir H. Payberah (Tehran Polytechnic) Processes 1393/12/4 23 / 47

Page 51: Amir H. Payberah amir@sics · Introduction I Processor: provides aset of instructionsalong with the capability of automaticallyexecuting a series of those instructions. I Thread:

Example: Planet Lab (2/2)

I Vserver: Independent and protected environment with its own li-braries, server versions, and so on.

I Distributed applications are assigned a collection of vservers dis-tributed across multiple machines (slice).

Hardware

Linux enhanced operating system

Vserver

Process

Process

...

Vserver

Process

Process

...

Vserver

Process

Process

...

Vserver

Process

Process

...

Vserver

Process

Process

...

User-assigned virtual machines

Priviliged management virtual machines

Amir H. Payberah (Tehran Polytechnic) Processes 1393/12/4 24 / 47

Page 52: Amir H. Payberah amir@sics · Introduction I Processor: provides aset of instructionsalong with the capability of automaticallyexecuting a series of those instructions. I Thread:

Virtualization

Amir H. Payberah (Tehran Polytechnic) Processes 1393/12/4 25 / 47

Page 53: Amir H. Payberah amir@sics · Introduction I Processor: provides aset of instructionsalong with the capability of automaticallyexecuting a series of those instructions. I Thread:

Virtualization

I Technique for hiding the physical characterizes of computing re-sources from the way other systems, applications or end users inter-act with them.

I Offer a different interface.

I Virtualized interface is not necessarily simpler.

Amir H. Payberah (Tehran Polytechnic) Processes 1393/12/4 26 / 47

Page 54: Amir H. Payberah amir@sics · Introduction I Processor: provides aset of instructionsalong with the capability of automaticallyexecuting a series of those instructions. I Thread:

Different Types of Virtualization

I Process-level virtualization

I OS-level virtualization

I System-level virtualization

Amir H. Payberah (Tehran Polytechnic) Processes 1393/12/4 27 / 47

Page 55: Amir H. Payberah amir@sics · Introduction I Processor: provides aset of instructionsalong with the capability of automaticallyexecuting a series of those instructions. I Thread:

Process-Level Virtualization (1/2)

I Usually implemented on top of an OS.

I Application has to be written specifically for the VM.

I The virtual machine runs one application (one process).

Amir H. Payberah (Tehran Polytechnic) Processes 1393/12/4 28 / 47

Page 56: Amir H. Payberah amir@sics · Introduction I Processor: provides aset of instructionsalong with the capability of automaticallyexecuting a series of those instructions. I Thread:

Process-Level Virtualization (2/2)

Amir H. Payberah (Tehran Polytechnic) Processes 1393/12/4 29 / 47

Page 57: Amir H. Payberah amir@sics · Introduction I Processor: provides aset of instructionsalong with the capability of automaticallyexecuting a series of those instructions. I Thread:

OS-Level Virtualization (1/2)

I The virtual machine runs a set of userland processes.

I Userland domains are separated.

I Kernel is the same for all userland domains.

Amir H. Payberah (Tehran Polytechnic) Processes 1393/12/4 30 / 47

Page 58: Amir H. Payberah amir@sics · Introduction I Processor: provides aset of instructionsalong with the capability of automaticallyexecuting a series of those instructions. I Thread:

OS-Level Virtualization (2/2)

Amir H. Payberah (Tehran Polytechnic) Processes 1393/12/4 31 / 47

Page 59: Amir H. Payberah amir@sics · Introduction I Processor: provides aset of instructionsalong with the capability of automaticallyexecuting a series of those instructions. I Thread:

System-Level Virtualization (1/3)

I Emulates a computer similar to a real physical one.• With CPU(s), memory, disk(s), network interface(s), etc.

I The virtual machine runs a full OS.

Amir H. Payberah (Tehran Polytechnic) Processes 1393/12/4 32 / 47

Page 60: Amir H. Payberah amir@sics · Introduction I Processor: provides aset of instructionsalong with the capability of automaticallyexecuting a series of those instructions. I Thread:

System-Level Virtualization (2/3)

I Full virtualization vs. Paravirtualization.

I Full virtualization: the guest OS is not aware it is being virtualizedand requires no modification.

I Paravirtualization: the guest OS should be modified in order to beoperated in the virtual environment.

Amir H. Payberah (Tehran Polytechnic) Processes 1393/12/4 33 / 47

Page 61: Amir H. Payberah amir@sics · Introduction I Processor: provides aset of instructionsalong with the capability of automaticallyexecuting a series of those instructions. I Thread:

System-Level Virtualization (2/3)

I Full virtualization vs. Paravirtualization.

I Full virtualization: the guest OS is not aware it is being virtualizedand requires no modification.

I Paravirtualization: the guest OS should be modified in order to beoperated in the virtual environment.

Amir H. Payberah (Tehran Polytechnic) Processes 1393/12/4 33 / 47

Page 62: Amir H. Payberah amir@sics · Introduction I Processor: provides aset of instructionsalong with the capability of automaticallyexecuting a series of those instructions. I Thread:

System-Level Virtualization (2/3)

I Full virtualization vs. Paravirtualization.

I Full virtualization: the guest OS is not aware it is being virtualizedand requires no modification.

I Paravirtualization: the guest OS should be modified in order to beoperated in the virtual environment.

Amir H. Payberah (Tehran Polytechnic) Processes 1393/12/4 33 / 47

Page 63: Amir H. Payberah amir@sics · Introduction I Processor: provides aset of instructionsalong with the capability of automaticallyexecuting a series of those instructions. I Thread:

System-Level Virtualization (3/3)

Amir H. Payberah (Tehran Polytechnic) Processes 1393/12/4 34 / 47

Page 64: Amir H. Payberah amir@sics · Introduction I Processor: provides aset of instructionsalong with the capability of automaticallyexecuting a series of those instructions. I Thread:

Hypervisor

I In the system-level virtualization, virtual machines are managed byanother software layer.

I It is called hypervisor or Virtual Machine Manager (VMM).

I Two types of hypervisors:• Type 1: runs directly on hardware (Native/Bare-Metal)• Type 2: hosted on top of another operating system (Hosted)

Amir H. Payberah (Tehran Polytechnic) Processes 1393/12/4 35 / 47

Page 65: Amir H. Payberah amir@sics · Introduction I Processor: provides aset of instructionsalong with the capability of automaticallyexecuting a series of those instructions. I Thread:

Hypervisor

I In the system-level virtualization, virtual machines are managed byanother software layer.

I It is called hypervisor or Virtual Machine Manager (VMM).

I Two types of hypervisors:• Type 1: runs directly on hardware (Native/Bare-Metal)• Type 2: hosted on top of another operating system (Hosted)

Amir H. Payberah (Tehran Polytechnic) Processes 1393/12/4 35 / 47

Page 66: Amir H. Payberah amir@sics · Introduction I Processor: provides aset of instructionsalong with the capability of automaticallyexecuting a series of those instructions. I Thread:

Bare Metal Hypervisor

I Xen, ...

Amir H. Payberah (Tehran Polytechnic) Processes 1393/12/4 36 / 47

Page 67: Amir H. Payberah amir@sics · Introduction I Processor: provides aset of instructionsalong with the capability of automaticallyexecuting a series of those instructions. I Thread:

Hosted Hypervisor

I VMWare, KVM, Virtualbox, ...

Amir H. Payberah (Tehran Polytechnic) Processes 1393/12/4 37 / 47

Page 68: Amir H. Payberah amir@sics · Introduction I Processor: provides aset of instructionsalong with the capability of automaticallyexecuting a series of those instructions. I Thread:

Code Migration

Amir H. Payberah (Tehran Polytechnic) Processes 1393/12/4 38 / 47

Page 69: Amir H. Payberah amir@sics · Introduction I Processor: provides aset of instructionsalong with the capability of automaticallyexecuting a series of those instructions. I Thread:

Strong and Weak Mobility (1/2)

I Code segment: contains the actual code

I Data segment: contains the state

I Execution state: contains context of thread executing the object’scode

Amir H. Payberah (Tehran Polytechnic) Processes 1393/12/4 39 / 47

Page 70: Amir H. Payberah amir@sics · Introduction I Processor: provides aset of instructionsalong with the capability of automaticallyexecuting a series of those instructions. I Thread:

Strong and Weak Mobility (2/2)

I Weak mobility: move only code and data segment (and reboot ex-ecution):

• Relatively simple, especially if code is portable• Distinguish code shipping (push) from code fetching (pull)

I Strong mobility: move component, including execution state• Migration: move entire object from one machine to the other• Cloning: start a clone, and set it in the same execution state.

Amir H. Payberah (Tehran Polytechnic) Processes 1393/12/4 40 / 47

Page 71: Amir H. Payberah amir@sics · Introduction I Processor: provides aset of instructionsalong with the capability of automaticallyexecuting a series of those instructions. I Thread:

Strong and Weak Mobility (2/2)

I Weak mobility: move only code and data segment (and reboot ex-ecution):

• Relatively simple, especially if code is portable• Distinguish code shipping (push) from code fetching (pull)

I Strong mobility: move component, including execution state• Migration: move entire object from one machine to the other• Cloning: start a clone, and set it in the same execution state.

Amir H. Payberah (Tehran Polytechnic) Processes 1393/12/4 40 / 47

Page 72: Amir H. Payberah amir@sics · Introduction I Processor: provides aset of instructionsalong with the capability of automaticallyexecuting a series of those instructions. I Thread:

Managing Local Resources (1/2)

I Problem: an object uses local resources that may or may not beavailable at the target site.

I Resource types:

• Fixed: the resource cannot be migrated, such as local hardware.

• Fastened: the resource can, in principle, be migrated but only at highcost.

• Unattached: the resource can easily be moved along with the object(e.g., a cache).

Amir H. Payberah (Tehran Polytechnic) Processes 1393/12/4 41 / 47

Page 73: Amir H. Payberah amir@sics · Introduction I Processor: provides aset of instructionsalong with the capability of automaticallyexecuting a series of those instructions. I Thread:

Managing Local Resources (1/2)

I Problem: an object uses local resources that may or may not beavailable at the target site.

I Resource types:

• Fixed: the resource cannot be migrated, such as local hardware.

• Fastened: the resource can, in principle, be migrated but only at highcost.

• Unattached: the resource can easily be moved along with the object(e.g., a cache).

Amir H. Payberah (Tehran Polytechnic) Processes 1393/12/4 41 / 47

Page 74: Amir H. Payberah amir@sics · Introduction I Processor: provides aset of instructionsalong with the capability of automaticallyexecuting a series of those instructions. I Thread:

Managing Local Resources (1/2)

I Problem: an object uses local resources that may or may not beavailable at the target site.

I Resource types:

• Fixed: the resource cannot be migrated, such as local hardware.

• Fastened: the resource can, in principle, be migrated but only at highcost.

• Unattached: the resource can easily be moved along with the object(e.g., a cache).

Amir H. Payberah (Tehran Polytechnic) Processes 1393/12/4 41 / 47

Page 75: Amir H. Payberah amir@sics · Introduction I Processor: provides aset of instructionsalong with the capability of automaticallyexecuting a series of those instructions. I Thread:

Managing Local Resources (1/2)

I Problem: an object uses local resources that may or may not beavailable at the target site.

I Resource types:

• Fixed: the resource cannot be migrated, such as local hardware.

• Fastened: the resource can, in principle, be migrated but only at highcost.

• Unattached: the resource can easily be moved along with the object(e.g., a cache).

Amir H. Payberah (Tehran Polytechnic) Processes 1393/12/4 41 / 47

Page 76: Amir H. Payberah amir@sics · Introduction I Processor: provides aset of instructionsalong with the capability of automaticallyexecuting a series of those instructions. I Thread:

Managing Local Resources (2/2)

I Object-to-resource binding:

• By identifier: the object requires a specific instance of a resource(e.g., a specific database).

• By value: the object requires the value of a resource (e.g., standardlibraries).

• By type: the object requires that only a type of resource is available(e.g., a color monitor).

Amir H. Payberah (Tehran Polytechnic) Processes 1393/12/4 42 / 47

Page 77: Amir H. Payberah amir@sics · Introduction I Processor: provides aset of instructionsalong with the capability of automaticallyexecuting a series of those instructions. I Thread:

Managing Local Resources (2/2)

I Object-to-resource binding:

• By identifier: the object requires a specific instance of a resource(e.g., a specific database).

• By value: the object requires the value of a resource (e.g., standardlibraries).

• By type: the object requires that only a type of resource is available(e.g., a color monitor).

Amir H. Payberah (Tehran Polytechnic) Processes 1393/12/4 42 / 47

Page 78: Amir H. Payberah amir@sics · Introduction I Processor: provides aset of instructionsalong with the capability of automaticallyexecuting a series of those instructions. I Thread:

Managing Local Resources (2/2)

I Object-to-resource binding:

• By identifier: the object requires a specific instance of a resource(e.g., a specific database).

• By value: the object requires the value of a resource (e.g., standardlibraries).

• By type: the object requires that only a type of resource is available(e.g., a color monitor).

Amir H. Payberah (Tehran Polytechnic) Processes 1393/12/4 42 / 47

Page 79: Amir H. Payberah amir@sics · Introduction I Processor: provides aset of instructionsalong with the capability of automaticallyexecuting a series of those instructions. I Thread:

Managing Local Resources (2/2)

I Object-to-resource binding:

• By identifier: the object requires a specific instance of a resource(e.g., a specific database).

• By value: the object requires the value of a resource (e.g., standardlibraries).

• By type: the object requires that only a type of resource is available(e.g., a color monitor).

Amir H. Payberah (Tehran Polytechnic) Processes 1393/12/4 42 / 47

Page 80: Amir H. Payberah amir@sics · Introduction I Processor: provides aset of instructionsalong with the capability of automaticallyexecuting a series of those instructions. I Thread:

Migration in Heterogeneous Systems

I The target machine may not be suitable to execute the migratedcode

I The definition of process/thread/processor context is highly depen-dent on local hardware, OS and runtime system.

I Only solution: make use of an abstract machine that is implementedon different platforms:

• Interpreted languages, effectively having their own VM• Virtual VM (as discussed previously)

Amir H. Payberah (Tehran Polytechnic) Processes 1393/12/4 43 / 47

Page 81: Amir H. Payberah amir@sics · Introduction I Processor: provides aset of instructionsalong with the capability of automaticallyexecuting a series of those instructions. I Thread:

Migration in Heterogeneous Systems

I The target machine may not be suitable to execute the migratedcode

I The definition of process/thread/processor context is highly depen-dent on local hardware, OS and runtime system.

I Only solution: make use of an abstract machine that is implementedon different platforms:

• Interpreted languages, effectively having their own VM• Virtual VM (as discussed previously)

Amir H. Payberah (Tehran Polytechnic) Processes 1393/12/4 43 / 47

Page 82: Amir H. Payberah amir@sics · Introduction I Processor: provides aset of instructionsalong with the capability of automaticallyexecuting a series of those instructions. I Thread:

Migration in Heterogeneous Systems

I The target machine may not be suitable to execute the migratedcode

I The definition of process/thread/processor context is highly depen-dent on local hardware, OS and runtime system.

I Only solution: make use of an abstract machine that is implementedon different platforms:

• Interpreted languages, effectively having their own VM• Virtual VM (as discussed previously)

Amir H. Payberah (Tehran Polytechnic) Processes 1393/12/4 43 / 47

Page 83: Amir H. Payberah amir@sics · Introduction I Processor: provides aset of instructionsalong with the capability of automaticallyexecuting a series of those instructions. I Thread:

Summary

Amir H. Payberah (Tehran Polytechnic) Processes 1393/12/4 44 / 47

Page 84: Amir H. Payberah amir@sics · Introduction I Processor: provides aset of instructionsalong with the capability of automaticallyexecuting a series of those instructions. I Thread:

Summary

I Process and Threads

I Threads in OS: user-level vs. kernel-level implementations

I Threads in distributed systems: improve performance

I Clients

I Servers: stateless vs. stateful, server clusters

I Virtualization: process level, OS level, and system level

I Code migration• Weak vs. strong mobility• Local resources: fixed, fastened, and unattached• Object-to-resource-binding: by id, by value, by type

Amir H. Payberah (Tehran Polytechnic) Processes 1393/12/4 45 / 47

Page 85: Amir H. Payberah amir@sics · Introduction I Processor: provides aset of instructionsalong with the capability of automaticallyexecuting a series of those instructions. I Thread:

Reading

I Chapter 3 of the Distributed Systems: Principles and Paradigms.

Amir H. Payberah (Tehran Polytechnic) Processes 1393/12/4 46 / 47

Page 86: Amir H. Payberah amir@sics · Introduction I Processor: provides aset of instructionsalong with the capability of automaticallyexecuting a series of those instructions. I Thread:

Questions?

Amir H. Payberah (Tehran Polytechnic) Processes 1393/12/4 47 / 47