1 / 28

Processes - outline

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

Download Presentation

Processes - outline

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. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Processes - outline • Process & thread basics • Multi-threaded clients • Server basics • Server design issues • Code Migration 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 Distributed Systems - Comp 655

  3. 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

  4. 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

  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(); } } Distributed Systems - Comp 655

  6. Possible output java ThreadExample hey whats up hey [1] whats [1] up [1] hey [2] whats [2] up [2] … Distributed Systems - Comp 655

  7. 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

  8. The most expensive operations Context switching 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 Distributed Systems - Comp 655

  10. 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

  11. Processes - outline • Process & thread basics • Multi-threaded clients • Server basics • Server design issues • Code Migration Distributed Systems - Comp 655

  12. 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

  13. Processes - outline • Process & thread basics • Multi-threaded clients • Server basics • Server design issues • Code Migration Distributed Systems - Comp 655

  14. Multi-threaded server Distributed Systems - Comp 655

  15. Multi-threaded server – plan 1 Distributed Systems - Comp 655

  16. 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

  17. Multi-threaded server – plan 1 synchronization Distributed Systems - Comp 655

  18. Multi-threaded server – plan 2 Compared to plan 1, no synchronization, but more overhead for starting and stopping threads Distributed Systems - Comp 655

  19. Processes - outline • Process & thread basics • Multi-threaded clients • Server basics • Server design issues • Code Migration Distributed Systems - Comp 655

  20. 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

  21. Binding a Client to a Server(aka how to find it) 2-15 Distributed Systems - Comp 655

  22. The super-server Distributed Systems - Comp 655

  23. 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

  24. Stateful vs stateless servers • Stateless server forgets everything after each request has been processed • 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

  25. Object creation 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

  26. For example, 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

  27. Code Migration • What it is: moving programs across a network on demand Distributed Systems - Comp 655

  28. Why migrate code? • Performance improvement • Flexibility • Simplified administration Distributed Systems - Comp 655

More Related