1 / 76

Processes

Processes. Chapter 3. Outline. Threads User-level vs. kenel-level Multithreaded clients and servers Clients Servers Stateless vs. stateful servers Code Migration Why and how Software Agents Types and properties. Why Threads?. Easier to build distributed applications

Télécharger la présentation

Processes

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

  2. Outline • Threads • User-level vs. kenel-level • Multithreaded clients and servers • Clients • Servers • Stateless vs. stateful servers • Code Migration • Why and how • Software Agents • Types and properties

  3. Why Threads? • Easier to build distributed applications • Better performance

  4. Benefits of Threads in Nondistributed Systems • A single-threaded process is blocked as a whole whenever a blocking system call is executed • Example: concurrent computation need of spreadsheet • One thread for interaction • One thread for calculation of dependencies of cells • Transparent parallelism on multiprocessor systems • Performance improvement in IPC • Process: extensive context switching needed • Thread: • Communication is through shared data • Thread switching sometimes is done entirely in user space • Software Engineering: many applications are easier to structure as a collection of cooperating threads. • Example: word processor – user input, spelling & grammer checking, document layout, etc.

  5. Thread Usage in Nondistributed Systems • Extensive context switching as the result of IPC space Change memory map in MMU Flushing TLB Process B

  6. Thread Implementation • User Level • Kernel Level

  7. Th0 Th 1 Th 2 Th n Run time system Kernel User space Kernel space User-Level Thread • The kernel knows only single-threaded processes.

  8. User-Level Thread • Advantages • User-level threads package can be implemented on an OS that does not support threads. e.g. UNIX. • Thread switching is an order of magnitudefaster than trapping to the kernel. • Cheap to create and destroy threads • Cheap to switch thread context • Only CPU registers • No need to do: memory maps, flushing the TLB, CPU accounting • Each process can have its own customized scheduling algorithm. • Scaling better: kernel threads require table space and stack space in the kernel. If number of threads increases  it can be a problem.

  9. User-Level Thread • Drawback • Invocation of a blocking system call will block the entire process

  10. Kernel-Level Thread • Creating or destroying threads through kernel calls • The kernel has one table per process. • One entry in the table per thread • Each thread: registers, state, priority, and other information • When a thread blocks, kernel may run a thread in the same or different process.

  11. Kernel-Level Thread • Advantage • Invocation of a block system call will not block the entire process • Drawback • Expensive thread operation: create, delete, synchronization, switching thread context • Thread recycling

  12. Light-Weight Process (LWP) • A hybrid form of user-level & kernel-level threads • Several kernel-level LWPs per process • A user-level thread package • operations for creating and destroying threads • Synchronization: mutex, condition variable • Context switch

  13. Light-Weight Process (LWP) • Fish and bear palm • Fast context switching between user-level threads: Performance • If a thread needs to block on a mutex or condition variable => Done in user space • Blocking system call: Programmability • Blocks only a LWP • Kernel switches to another LWP • Concurrency within the same process

  14. Thread Implementation • Combining kernel-level lightweight processes and user-level threads. A blocking system call only blocks a LWP

  15. LWP • Advantages • Cheap thread operations • A blocking system call does not suspend the entire process • Applications know only user-level threads, not LWPs • LWPs can be used in multiprocessor systems • Drawback • Expensive operations for LWPs: create and destroy

  16. Multithreaded Clients • Multithreads in web clients • Hide communication latencies • Display main HTML file first to users • Retrieve and display images later: several threads simultaneously • Connect to different replicas of servers • Round robin for load balance and parallelism

  17. Multithreaded Servers • 櫃臺小姐 • 美式:日子好過、沒效率 • 中式:高度效率、胃潰瘍 • 改良式?

  18. Single-Threaded File Server (美式) • Process • Single-threaded • While waiting for the disk, the server is idle, and does not process other requests • If the server is a dedicated machine  CPU is idle while server is waiting

  19. Big Finite-State Machine (中式) • Request comes in, the single thread checks it • If in cache  fine • otherwise  send a message to disk • must be non-blocking send() & receive() • RPC cannot be used • No blocking. The status of current request is recorded. Then get next message: • a new work  start the work • a reply from disk  relevant information is fetched from the table, and the reply processed • Simulating threads & their stacks the hard way

  20. Multithreaded Servers • A multithreaded server organized in a dispatcher/worker model.

  21. Multi-Threaded File Server • Dispatcher • reads incoming requests from system mailbox • Chooses a worker thread to service request • The worker thread • checks shared block cache • not in cache  sends a message to disk for the block (READ) • sleep waiting • scheduler is invoked and starts another thread (can be the dispatcher or another worker thread)

  22. File server process Dispatcher thread Worker thread Shared block cache mailbox Request for work arrives Dispatcher / Worker Model

  23. Multithreaded Servers Three ways to construct a server.

  24. Team model Team model • All threads can get and process their own requests • Sometimes, each thread is specialized to handle a particular kind of work. A job queue for each thread.

  25. Pipeline model Pipeline model • The first thread generates some data to be processed by next thread. • Good for e.g. producer - consumer problem (such as UNIX command lines)

  26. Multithreaded Servers • Threads: to retain the idea of sequential processes that make blocking system calls and still achieve parallelsim • Blocking system calls make programming easier • Parallelism improves performance

  27. Clients: The X-Window System • The basic organization of the X Window System X terminals

  28. Client-Side Software for Distribution Transparency • A possible approach to transparent replication of a remote object using a client-side solution.

  29. Server Design Issues • Two types of servers • Iterative server • Concurrent server • Port number (endpoint) • Well-known services: by Internet Assigned Numbers Authority (IANA) • Other services: clients have to look up • DCE: like a telephone operator • UNIX superserver • For passive processes • e.g., inetd daemon listens to a number of well-known ports

  30. Servers: General Design Issues • Client-to-server binding using a daemon as in DCE • Client-to-server binding using a superserver as in UNIX 3.7

  31. Server Design Issues • Communication interrupts: Out-of-band data • A separate control endpoint • The same connection • In TCP, when a server receives urgent data, the communication is interrupted. Then the server can inspect and handle the data.

  32. Server Design Issues • Stateless server • Does not keep information of its clients • Can change its own state without informing clients • E.g., a web server • Stateful server • Maintain information about its clients

  33. Stateful Servers • Example • File server: (client, file) • Advantage: improves the performance of read/write operations as perceived by clients • Drawback • If the server crashes, it has to recover its states • (client, file) table • Recovery is complicated

  34. Stateful Servers • Web server • Why stateful? • Using history information to direct a client to his favorite pages • How • Cookie at client site • Server table

  35. 誠品信義店 Types of Servers 專業旗艦店

  36. Object Servers • Object server • To support distributed objects • Acts as a place where objects live • Provides means to invoke local objects • Services are provided by objects (not by object servers) • Relatively easy to change services by simply adding and removing objects

  37. Reasons for Process Migration • Performance improvement • Load balancing: moving processes from heavily-loaded to lightly-loaded machines

  38. Reasons for Migrating Code • Performance • To minimize communication may be more important than to optimize computation • To process data close to where data reside • Operation on huge database • Filling forms on the client side • Parallel search in the web: mobile agents

  39. Reasons for Migrating Code • Flexibility • Dynamicallyconfigure distributed systems • Clients: software is moved in as necessary, and discarded when no longer needed • As long as interface are standardized, we can change the client-server protocol and its implementation at will • Disadvantages: security concern

  40. Reasons for Migrating Code • The client first fetches the necessary software, and then invokes the server.

  41. Models for Code Migration • A process consists of 3 segments • Code segment: instructions • Resource segment: files, printers, devices, …. • Execution segment: private data, stack, program counter, etc. • Mobility • Weak mobility • Strong mobility

  42. Weak Mobility • To transfer only code segment, and some initialization data • A transferred program is always started from its initial state. • Java applet • Benefit: simplicity

  43. Strong Mobility (Process Migration) • Transfer • Code segment • Execution segment • Characteristics • A running process can be stopped • Moved to another machine • Resume execution

  44. Sender vs. Receiver Initiated • Sender initiated • Uploading programs to servers: clients should have been registered and authenticated • E.g. sending a search program to Web database server to perform queries • Receiver initiated • E.g. Java applets • Simpler • No security concern on server side • Can be done anonymously

  45. Address Space to Execute • Execute at target process • Java applet: at browser’s address space • Benefit: no need to start a separate process, thus avoiding communication • Drawback: has to protect the target process against malicious code execution • Execute in a separate process

  46. Alternatives for code migration Fork and execute at a different machine

  47. Remote Cloning • Cloning yields an exact copy of the original process on a different machine • UNIX: by forking off a child process on a remote machine

  48. Migration and Local Resources • Resource segment migration is difficult • A process uses a local port • Process migration: requests a new port at the destination

  49. Binding Process Resource Machine

  50. Process to Resource Binding • Binding by identifier • Requires precisely the referenced resource • E.g., a process uses URL to refer to a Web site • Binding by value • Any resource which provides the same value can do • E.g., standard library • Binding by type • Any resource of the same specific type can do • E.g., monitor, printer

More Related