Presentation is loading. Please wait.

Presentation is loading. Please wait.

Distributed Systems - Comp 655

Similar presentations


Presentation on theme: "Distributed Systems - Comp 655"— Presentation transcript:

1 Distributed Systems - Comp 655
Processes - outline Process & thread basics Multi-threaded clients Server basics Server design issues Code Migration 11/13/2018 Distributed Systems - Comp 655

2 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 11/13/2018 Distributed Systems - Comp 655

3 Distributed Systems - Comp 655
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(); 11/13/2018 Distributed Systems - Comp 655

4 Distributed Systems - Comp 655
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) {} 11/13/2018 Distributed Systems - Comp 655

5 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(); } 11/13/2018 Distributed Systems - Comp 655

6 Distributed Systems - Comp 655
Possible output java ThreadExample hey whats up hey [1] whats [1] up [1] hey [2] whats [2] up [2] 11/13/2018 Distributed Systems - Comp 655

7 Distributed Systems - Comp 655
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 11/13/2018 Distributed Systems - Comp 655

8 Distributed Systems - Comp 655
Context switching The most expensive operations 11/13/2018 Distributed Systems - Comp 655

9 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 11/13/2018 Distributed Systems - Comp 655

10 Lightweight processes
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 11/13/2018 Distributed Systems - Comp 655

11 User threads multiplexed

12 Distributed Systems - Comp 655
Processes - outline Process & thread basics Multi-threaded clients Server basics Server design issues Code Migration 11/13/2018 Distributed Systems - Comp 655

13 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 11/13/2018 Distributed Systems - Comp 655

14 Distributed Systems - Comp 655
Processes - outline Process & thread basics Multi-threaded clients Server basics Server design issues Code Migration 11/13/2018 Distributed Systems - Comp 655

15 Multi-threaded server
Java RMI provides a dispatching thread for a Remote object, and a pool of threads to execute calls. 11/13/2018 Distributed Systems - Comp 655

16 Multi-threaded server – plan 1
Thread type Started by How many Responsibility Dispatcher Main 1 Listen for requests and queue them Worker Main or pool manager 7+ Dequeue a request, process it, send results to client, repeat Pool manager Watch size of request queue, and start new Workers if average queue size is too large 11/13/2018 Distributed Systems - Comp 655

17 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 11/13/2018 Distributed Systems - Comp 655

18 Multi-threaded server – plan 1 synchronization
Object to synch on Threads involved How it works Request queue Dispatcher, Workers Dispatcher locks object before queuing a request Dispatcher notifies one Worker after queuing a request When a running Worker has no request to process, it locks the queue, checks for requests; if found, dequeues it, unlocks queue, processes request If no requests are waiting, Worker waits on the queue 11/13/2018 Distributed Systems - Comp 655

19 Multi-threaded server – plan 2
Thread type Started by How many Responsibility Dispatcher Main 1 Listen for requests and start a Worker to handle each one Worker 1 per request Process a request, send results to client, end Compared to plan 1, no synchronization, but more overhead for starting and stopping threads 11/13/2018 Distributed Systems - Comp 655

20 Distributed Systems - Comp 655
Processes - outline Process & thread basics Multi-threaded clients Server basics Server design issues Code Migration 11/13/2018 Distributed Systems - Comp 655

21 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 11/13/2018 Distributed Systems - Comp 655

22 Distributed Systems - Comp 655
The super-server 11/13/2018 Distributed Systems - Comp 655

23 The super-server: inetd
11/13/2018 Distributed Systems - Comp 655

24 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 TCP Priority Data Transfer: "Urgent"  Out-of-band control messages Server Regular (data) messages 11/13/2018 Distributed Systems - Comp 655

25 Stateful vs stateless servers
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 11/13/2018 Distributed Systems - Comp 655

26 Object activation policy options
Object creation Per request Fixed-size pool Dynamic pool Threading Single Fixed-size thread pool Dynamic thread pool Thread per object An object adapter is an implementation of an activation policy. 11/13/2018 Distributed Systems - Comp 655

27 Object adapters in an object server
and two activation policies For example, new object on a new thread for each request For example, single object on a single thread handles all requests 11/13/2018 Distributed Systems - Comp 655

28 Distributed Systems - Comp 655
Code Migration What it is: moving programs across a network on demand 11/13/2018 Distributed Systems - Comp 655

29 Distributed Systems - Comp 655
Why migrate code? Performance improvement Flexibility Simplified administration 11/13/2018 Distributed Systems - Comp 655


Download ppt "Distributed Systems - Comp 655"

Similar presentations


Ads by Google