Processes outline
Download
1 / 29

Processes - outline - PowerPoint PPT Presentation


  • 94 Views
  • Uploaded on

Processes - outline. Process & thread basics Multi-threaded clients Server basics Server design issues Code Migration. If you remember one thing…. Threads execute Processes don’t. A thread owns Id Program counter Scheduling priority Stack Local storage. A process owns Id

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about 'Processes - outline' - paulos


An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
Processes outline
Processes - outline

  • Process & thread basics

  • Multi-threaded clients

  • Server basics

  • Server design issues

  • Code Migration

Distributed Systems - Comp 655


If you remember one thing
If you remember one thing…

  • Threads execute

  • Processes don’t

  • A thread owns

  • Id

  • Program counter

  • Scheduling priority

  • Stack

  • Local storage

  • A process owns

  • Id

  • Thread table

  • Page tables

  • Authenticated identity

  • IO resources

Distributed Systems - Comp 655


Threads in java
Threads in Java

Threads are objects

  • … like almost everything in Java

  • To make one,

    • Define a class that

      • Extends java.lang.Thread, or

      • Implements java.lang.Runnable

    • At runtime, create and initialize an instance

    • Call the start method:

      • mythread.start(); or

      • new Thread(myrunnable).start();

Distributed Systems - Comp 655


Java thread example
Java thread example

public class Worker implements Runnable {

private long myInterval;

private int myReps;

public Worker(long interval, int repetitions) {

myInterval = interval;

myReps = repetitions;

}

public void run() {

String me = Thread.currentThread().getName();

for( int repsDone=1; repsDone<=myReps; repsDone++) {

System.out.println(me+" ["+(repsDone)+"]");

try{ Thread.sleep(myInterval); }

catch(Exception e) {}

}

}

}

Distributed Systems - Comp 655


Starting the thread example
Starting the thread example

Public static void main(String names[]) {

for( int i=0; i<names.length; i++ ) {

Worker w = new Worker(1000,7);

Thread t = new Thread(w);

t.setName(names[i]);

t.start();

}

}

Distributed Systems - Comp 655


Possible output
Possible output

java ThreadExample hey whats up

hey [1]

whats [1]

up [1]

hey [2]

whats [2]

up [2]

Distributed Systems - Comp 655


Why threads
Why threads?

  • Sometimes you have to block

    • usually for IO

  • Context switching (for processes) is expensive

  • Why is context switching expensive?

    • Memory management

  • Why do memory management?

    • Concurrency transparency

Distributed Systems - Comp 655


Context switching

The most expensive

operations

Context switching

Distributed Systems - Comp 655


Lightweight processes
Lightweight processes

  • User-level thread packages can do context switching for threads MUCH less expensively

  • BUT, if one thread makes a blocking system call, all threads block

  • Solutions:

    • Lightweight processes

    • Scheduler activations

Distributed Systems - Comp 655


Lightweight processes1
Lightweight processes

process

thread

table

  • Most thread switching is done in user space

  • LWP switching occurs only when a thread makes a blocking system call

  • Scheduling routine, thread table, and thread table mutexes are shared by LWPs and the user-level thread package

Distributed Systems - Comp 655



Processes outline1
Processes - outline

  • Process & thread basics

  • Multi-threaded clients

  • Server basics

  • Server design issues

  • Code Migration

Distributed Systems - Comp 655


Multi threaded clients
Multi-threaded clients

  • Typical web browser

    • Main thread gets the page you requested

    • Additional threads are dispatched to fetch images, frames, scripts, etc

  • User can start viewing before all the data has been received

  • Parallelism can shorten elapsed download time when web server is replicated

Distributed Systems - Comp 655


Processes outline2
Processes - outline

  • Process & thread basics

  • Multi-threaded clients

  • Server basics

  • Server design issues

  • Code Migration

Distributed Systems - Comp 655


Multi threaded server
Multi-threaded server

Distributed Systems - Comp 655


Multi threaded server plan 1
Multi-threaded server – plan 1

Distributed Systems - Comp 655


Threads may need synchronization
Threads may need synchronization

  • Why synchronize? (preview of week 6): concurrent access to shared resources

    • Concurrent writers can corrupt data

    • Concurrent reader and writer can confuse the reader

  • Example: workers de-queue and dispatcher en-queues

  • All operating systems (and some languages) provide synchronization primitives

  • When you design a multi-threaded program you have to have a synchronization plan/design/architecture

Distributed Systems - Comp 655


Multi threaded server plan 1 synchronization
Multi-threaded server – plan 1 synchronization

Distributed Systems - Comp 655


Multi threaded server plan 2
Multi-threaded server – plan 2

Compared to plan 1, no synchronization, but more overhead for starting and stopping threads

Distributed Systems - Comp 655


Processes outline3
Processes - outline

  • Process & thread basics

  • Multi-threaded clients

  • Server basics

  • Server design issues

  • Code Migration

Distributed Systems - Comp 655


Typical server design issues
Typical server design issues

  • How to find it

    • While minimizing use of well-known endpoints (why?)

  • How to interrupt it

  • Stateful vs stateless

  • Object activation policy

Distributed Systems - Comp 655


The super server
The super-server

Distributed Systems - Comp 655


The super server inetd
The super-server: inetd

Distributed Systems - Comp 655


Interrupting a server that is processing a long running request
Interrupting a server that is processing a long-running request

  • Major options

  • Abrupt termination

  • Out-of-band control messages (see below)

  • In-band control messages with priority

  • Response chunking with option to quit after each chunk

Client

Out-of-band control messages

Server

Regular (data) messages

Distributed Systems - Comp 655


Stateful vs stateless servers
Stateful vs stateless servers request

  • Stateless server forgets everything after each request has been processed. E.g. HTTP server

  • Stateful servers can have better performance and be less annoying

    BUT

  • At the cost (usually) of losing

    • Relocation transparency

    • Failure transparency

Distributed Systems - Comp 655


Object activation policy options

Object creation request

Per request

Fixed-size pool

Dynamic pool

Threading

Single

Fixed-size thread pool

Dynamic thread pool

Thread per object

Object activation policy options

An object adapter is an implementation of an activation policy.

Distributed Systems - Comp 655


Object adapters in an object server

For example, request

new object on a

new thread for

each request

For example,

single object on a

single thread handles

all requests

Object adapters in an object server

and two activation policies

Distributed Systems - Comp 655


Code migration
Code Migration request

  • What it is: moving programs across a network on demand

Distributed Systems - Comp 655


Why migrate code
Why migrate code? request

  • Performance improvement

  • Flexibility

  • Simplified administration

Distributed Systems - Comp 655


ad