Processes Chapter 3. Table of Contents Multithreading Clients and Servers Code Migration Software...
-
Upload
doris-jefferson -
Category
Documents
-
view
231 -
download
0
Transcript of Processes Chapter 3. Table of Contents Multithreading Clients and Servers Code Migration Software...
![Page 1: Processes Chapter 3. Table of Contents Multithreading Clients and Servers Code Migration Software Agents (special topic)](https://reader035.fdocuments.net/reader035/viewer/2022062719/56649ec75503460f94bd2db9/html5/thumbnails/1.jpg)
Processes
Chapter 3
![Page 2: Processes Chapter 3. Table of Contents Multithreading Clients and Servers Code Migration Software Agents (special topic)](https://reader035.fdocuments.net/reader035/viewer/2022062719/56649ec75503460f94bd2db9/html5/thumbnails/2.jpg)
Table of Contents
• Multithreading
• Clients and Servers
• Code Migration
• Software Agents (special topic)
![Page 3: Processes Chapter 3. Table of Contents Multithreading Clients and Servers Code Migration Software Agents (special topic)](https://reader035.fdocuments.net/reader035/viewer/2022062719/56649ec75503460f94bd2db9/html5/thumbnails/3.jpg)
3.1 Multithreading
• Process vs. Thread– A process is often defined as a program in
execution.
– A thread is a sequence of instructions that can be executed in parallel with other threads.
– Threads are like lightweight processes.
![Page 4: Processes Chapter 3. Table of Contents Multithreading Clients and Servers Code Migration Software Agents (special topic)](https://reader035.fdocuments.net/reader035/viewer/2022062719/56649ec75503460f94bd2db9/html5/thumbnails/4.jpg)
3.1 Multithreading
• Process vs. Thread– Multiple threads within a single process
share the state information, memory and other resources directly, but they are able to execute independently
– Threads collaborate with each other -- processes compete.
– ……
![Page 5: Processes Chapter 3. Table of Contents Multithreading Clients and Servers Code Migration Software Agents (special topic)](https://reader035.fdocuments.net/reader035/viewer/2022062719/56649ec75503460f94bd2db9/html5/thumbnails/5.jpg)
3.1 Multithreading
• Why Multithreading?– Allows to perform more than one task at a
time.
– Increases the performance of programs.
![Page 6: Processes Chapter 3. Table of Contents Multithreading Clients and Servers Code Migration Software Agents (special topic)](https://reader035.fdocuments.net/reader035/viewer/2022062719/56649ec75503460f94bd2db9/html5/thumbnails/6.jpg)
3.1 Multithreading
• When Multithreading?– A multiprocessor computer works by using
the multiple processors to handle threads simultaneously (multiprocessing).
– A program that spends a great deal of time waiting for outside events (time slicing).
![Page 7: Processes Chapter 3. Table of Contents Multithreading Clients and Servers Code Migration Software Agents (special topic)](https://reader035.fdocuments.net/reader035/viewer/2022062719/56649ec75503460f94bd2db9/html5/thumbnails/7.jpg)
Threads in Nondistributed Systems
• Interprocess communication (IPC)– Pipes, Message queues, Shared memory
segments, Semaphore, Signal
– Heavy context switching• user -> kernel mode• switch in kernel• kernel -> user mode
![Page 8: Processes Chapter 3. Table of Contents Multithreading Clients and Servers Code Migration Software Agents (special topic)](https://reader035.fdocuments.net/reader035/viewer/2022062719/56649ec75503460f94bd2db9/html5/thumbnails/8.jpg)
Threads in Nondistributed Systems
Context switching as the result of IPC
![Page 9: Processes Chapter 3. Table of Contents Multithreading Clients and Servers Code Migration Software Agents (special topic)](https://reader035.fdocuments.net/reader035/viewer/2022062719/56649ec75503460f94bd2db9/html5/thumbnails/9.jpg)
Threads in Nondistributed Systems
• Multithreads (in a process)– Communicate by using shared data
– User space switching mostly
– Don’t bother the kernel => Efficient
![Page 10: Processes Chapter 3. Table of Contents Multithreading Clients and Servers Code Migration Software Agents (special topic)](https://reader035.fdocuments.net/reader035/viewer/2022062719/56649ec75503460f94bd2db9/html5/thumbnails/10.jpg)
Thread Implementation
Combining kernel-level lightweight processes and user-level threads.
![Page 11: Processes Chapter 3. Table of Contents Multithreading Clients and Servers Code Migration Software Agents (special topic)](https://reader035.fdocuments.net/reader035/viewer/2022062719/56649ec75503460f94bd2db9/html5/thumbnails/11.jpg)
Threads in Distributed Systems
• The usage of threads– allows blocking system calls without
blocking the entire process in which the thread is running.
– Multiple threads maintain multiple logical connections at the same time.
![Page 12: Processes Chapter 3. Table of Contents Multithreading Clients and Servers Code Migration Software Agents (special topic)](https://reader035.fdocuments.net/reader035/viewer/2022062719/56649ec75503460f94bd2db9/html5/thumbnails/12.jpg)
Threads in Distributed Systems
• Multithreaded Clients– Example: web browser
• Main HTML file• More connections simultaneously for images,
…
– Web servers are replicated• Request is forwarded• Connections to replicas• Transfer data in parallel
![Page 13: Processes Chapter 3. Table of Contents Multithreading Clients and Servers Code Migration Software Agents (special topic)](https://reader035.fdocuments.net/reader035/viewer/2022062719/56649ec75503460f94bd2db9/html5/thumbnails/13.jpg)
Threads in Distributed Systems
• Multithreaded Servers– Single-threaded process
– Finite-state machine
– Threads
![Page 14: Processes Chapter 3. Table of Contents Multithreading Clients and Servers Code Migration Software Agents (special topic)](https://reader035.fdocuments.net/reader035/viewer/2022062719/56649ec75503460f94bd2db9/html5/thumbnails/14.jpg)
Single-threaded process
• The server– Receive a request– Execute it (either locally or remotely) Loop– Reply the result
No other request is allowed when handling the current request.
Simple, easy, … but inefficient
![Page 15: Processes Chapter 3. Table of Contents Multithreading Clients and Servers Code Migration Software Agents (special topic)](https://reader035.fdocuments.net/reader035/viewer/2022062719/56649ec75503460f94bd2db9/html5/thumbnails/15.jpg)
Finite-state machine• The server
– Received messages are recorded in a table– Fetch a message
• new work? Start it• Result of previous work? Reply it
Nonblocking calls to send and receive
![Page 16: Processes Chapter 3. Table of Contents Multithreading Clients and Servers Code Migration Software Agents (special topic)](https://reader035.fdocuments.net/reader035/viewer/2022062719/56649ec75503460f94bd2db9/html5/thumbnails/16.jpg)
Threads• The server
– Receive a request– Dispatch to a free worker thread
A multithreaded server organized in a dispatcher/worker model.
![Page 17: Processes Chapter 3. Table of Contents Multithreading Clients and Servers Code Migration Software Agents (special topic)](https://reader035.fdocuments.net/reader035/viewer/2022062719/56649ec75503460f94bd2db9/html5/thumbnails/17.jpg)
Three ways to construct a server
• Blocking calls: Easy
• Parallelism: Efficient, high performance
Model Characteristics
Threads Parallelism, blocking system calls
Single-threaded process No parallelism, blocking system calls
Finite-state machine Parallelism, nonblocking system calls
![Page 18: Processes Chapter 3. Table of Contents Multithreading Clients and Servers Code Migration Software Agents (special topic)](https://reader035.fdocuments.net/reader035/viewer/2022062719/56649ec75503460f94bd2db9/html5/thumbnails/18.jpg)
3.2 Clients
• Task– Interface: interact with a human user
and a remote server.
– Partial computation
– Implementation of Transparency
– ……
![Page 19: Processes Chapter 3. Table of Contents Multithreading Clients and Servers Code Migration Software Agents (special topic)](https://reader035.fdocuments.net/reader035/viewer/2022062719/56649ec75503460f94bd2db9/html5/thumbnails/19.jpg)
Distribution Transparency
A client should not be aware that it is communicating with remote
processes.
![Page 20: Processes Chapter 3. Table of Contents Multithreading Clients and Servers Code Migration Software Agents (special topic)](https://reader035.fdocuments.net/reader035/viewer/2022062719/56649ec75503460f94bd2db9/html5/thumbnails/20.jpg)
Distribution Transparency
Different forms of transparency in a distributed system.
(from chapter one)
Transparency Description
AccessHide differences in data representation and how a resource is accessed
Location Hide where a resource is located
Migration Hide that a resource may move to another location
RelocationHide that a resource may be moved to another location while in use
Replication Hide that a resource is replicated
ConcurrencyHide that a resource may be shared by several competitive users
Failure Hide the failure and recovery of a resource
PersistenceHide whether a (software) resource is in memory or on disk
![Page 21: Processes Chapter 3. Table of Contents Multithreading Clients and Servers Code Migration Software Agents (special topic)](https://reader035.fdocuments.net/reader035/viewer/2022062719/56649ec75503460f94bd2db9/html5/thumbnails/21.jpg)
Distribution Transparency (1)
• Access transparency – A client stub is generated from an interface
definition of what the server has to offer.
– The client stub:• provides the same interface as available at the
server.• handles the communication between two sides.
![Page 22: Processes Chapter 3. Table of Contents Multithreading Clients and Servers Code Migration Software Agents (special topic)](https://reader035.fdocuments.net/reader035/viewer/2022062719/56649ec75503460f94bd2db9/html5/thumbnails/22.jpg)
Distribution Transparency (2)
• Location | Migration | Relocation transparency
– Naming system
– Bind and rebind the server
– Temporarily out of service (maybe)
![Page 23: Processes Chapter 3. Table of Contents Multithreading Clients and Servers Code Migration Software Agents (special topic)](https://reader035.fdocuments.net/reader035/viewer/2022062719/56649ec75503460f94bd2db9/html5/thumbnails/23.jpg)
Distribution Transparency (3)
• Replication transparency – Forward a request to each replica
– Collect all responses
– Pick a single return value
Safe but inefficient
![Page 24: Processes Chapter 3. Table of Contents Multithreading Clients and Servers Code Migration Software Agents (special topic)](https://reader035.fdocuments.net/reader035/viewer/2022062719/56649ec75503460f94bd2db9/html5/thumbnails/24.jpg)
Client-Side Software for Distribution Transparency
A possible approach to transparent replication of a remote object using a client-side solution.
![Page 25: Processes Chapter 3. Table of Contents Multithreading Clients and Servers Code Migration Software Agents (special topic)](https://reader035.fdocuments.net/reader035/viewer/2022062719/56649ec75503460f94bd2db9/html5/thumbnails/25.jpg)
Distribution Transparency (4)
• Failure transparency
– Repeat to build the connection
– Try another server
– Pick the data from its own cache
![Page 26: Processes Chapter 3. Table of Contents Multithreading Clients and Servers Code Migration Software Agents (special topic)](https://reader035.fdocuments.net/reader035/viewer/2022062719/56649ec75503460f94bd2db9/html5/thumbnails/26.jpg)
Distribution Transparency (5)
• Concurrency transparency – Server’s job mostly
– Intermediate servers
• Persistence Transparency– Server’s job totally
![Page 27: Processes Chapter 3. Table of Contents Multithreading Clients and Servers Code Migration Software Agents (special topic)](https://reader035.fdocuments.net/reader035/viewer/2022062719/56649ec75503460f94bd2db9/html5/thumbnails/27.jpg)
3.3 Servers
• Definition– A server is a process implementing a
specific service on behalf of a collection of clients
• Organization– Waits for an incoming request from a client
– Handle the request
– Reply the result to the client
![Page 28: Processes Chapter 3. Table of Contents Multithreading Clients and Servers Code Migration Software Agents (special topic)](https://reader035.fdocuments.net/reader035/viewer/2022062719/56649ec75503460f94bd2db9/html5/thumbnails/28.jpg)
3.3 Servers
• Type– Iterative server
• Handle the request by itself
– Concurrent server• Forward to other available process (or thread)• Fork a new process (or thread) to handle the
request
![Page 29: Processes Chapter 3. Table of Contents Multithreading Clients and Servers Code Migration Software Agents (special topic)](https://reader035.fdocuments.net/reader035/viewer/2022062719/56649ec75503460f94bd2db9/html5/thumbnails/29.jpg)
3.3 Servers
– Stateless server• Does not keep information on the state of its
clients, for example, a web server.
– Stateful server• Maintain information on its clients• Better services, better performance• Drawback: recover the client information
sometimes– Hybrid solution
• cookie
![Page 30: Processes Chapter 3. Table of Contents Multithreading Clients and Servers Code Migration Software Agents (special topic)](https://reader035.fdocuments.net/reader035/viewer/2022062719/56649ec75503460f94bd2db9/html5/thumbnails/30.jpg)
3.3 Servers
• Endpoint or port– Preassign endpoint for well-known
services globally: FTP:21, HTTP:80
– (Server, port) pair in a special daemon – Superserver
• Listen to some endpoints• Fork a server process to handle the incoming
request
![Page 31: Processes Chapter 3. Table of Contents Multithreading Clients and Servers Code Migration Software Agents (special topic)](https://reader035.fdocuments.net/reader035/viewer/2022062719/56649ec75503460f94bd2db9/html5/thumbnails/31.jpg)
Servers: General Design Issues
3.7
a) Client-to-server binding using a daemon as in DCEb) Client-to-server binding using a superserver as in UNIX
![Page 32: Processes Chapter 3. Table of Contents Multithreading Clients and Servers Code Migration Software Agents (special topic)](https://reader035.fdocuments.net/reader035/viewer/2022062719/56649ec75503460f94bd2db9/html5/thumbnails/32.jpg)
3.3 Servers
• Special Case: Object servers– Definition: A server to support (contain)
distributed objects• No service directly from the server, but
implemented by the objects in the server• Server’s job: invoke local objects based on
incoming requests• Positive: easy to change services by just
updating objects
![Page 33: Processes Chapter 3. Table of Contents Multithreading Clients and Servers Code Migration Software Agents (special topic)](https://reader035.fdocuments.net/reader035/viewer/2022062719/56649ec75503460f94bd2db9/html5/thumbnails/33.jpg)
3.3 Servers
– Object• Data: represents the state• Code: method implementation
– Object Adapter• Activation policies: the way how to invoke an
object• Object adapter: a mechanism to group objects
based on the above policy and dispatch requests to different objects
![Page 34: Processes Chapter 3. Table of Contents Multithreading Clients and Servers Code Migration Software Agents (special topic)](https://reader035.fdocuments.net/reader035/viewer/2022062719/56649ec75503460f94bd2db9/html5/thumbnails/34.jpg)
Object Adapter (Omitted)
Organization of an object server supporting different activation policies.
![Page 35: Processes Chapter 3. Table of Contents Multithreading Clients and Servers Code Migration Software Agents (special topic)](https://reader035.fdocuments.net/reader035/viewer/2022062719/56649ec75503460f94bd2db9/html5/thumbnails/35.jpg)
3.4 Code Migration
• What is code migration?– In a distributed system, programs (code)
can be transferred among different machines, sometimes even while they are be executed.
• Why code migration? – Performance, always
• Why not code migration?– Security, always
![Page 36: Processes Chapter 3. Table of Contents Multithreading Clients and Servers Code Migration Software Agents (special topic)](https://reader035.fdocuments.net/reader035/viewer/2022062719/56649ec75503460f94bd2db9/html5/thumbnails/36.jpg)
Reasons for Migrating Code
• Basic idea of process migration– Overall system performance can be
improved if processes are moved from heavily-loaded to lightly-loaded machines.
• Related stuff– Communication cost
– Heterogeneity
– Security
– Error recovery
![Page 37: Processes Chapter 3. Table of Contents Multithreading Clients and Servers Code Migration Software Agents (special topic)](https://reader035.fdocuments.net/reader035/viewer/2022062719/56649ec75503460f94bd2db9/html5/thumbnails/37.jpg)
Examples
• Clients => Servers– A program in the client containing a lot of
query operations for the database residing in a server.
• Servers => Clients– Network installation: OS…– Java applets
A tradeoff between the cost of communication and the execution of program
![Page 38: Processes Chapter 3. Table of Contents Multithreading Clients and Servers Code Migration Software Agents (special topic)](https://reader035.fdocuments.net/reader035/viewer/2022062719/56649ec75503460f94bd2db9/html5/thumbnails/38.jpg)
Examples
The principle of dynamically configuring a client to communicate to a server. The client first fetches the necessary software, and then invokes the server.
•Code migrated from the third party
![Page 39: Processes Chapter 3. Table of Contents Multithreading Clients and Servers Code Migration Software Agents (special topic)](https://reader035.fdocuments.net/reader035/viewer/2022062719/56649ec75503460f94bd2db9/html5/thumbnails/39.jpg)
Models for Code Migration
• Fugetta’s framework (1998)– Code segment
• Instructions of a program
– Resource segment• References to external resources: printer,
devices, other processes, …
– Execution segment• Current execution state of a process: private
data, stack, program counter.
![Page 40: Processes Chapter 3. Table of Contents Multithreading Clients and Servers Code Migration Software Agents (special topic)](https://reader035.fdocuments.net/reader035/viewer/2022062719/56649ec75503460f94bd2db9/html5/thumbnails/40.jpg)
Models for Code Migration
• Mobility– Weak mobility: only transfer the code
segment as well as some initialization data• Transferred programs are always started from
the very beginning.• Simple
– Strong mobility: transfer not only the code segment, but also the execution segment • Running process is stopped => move to other
machine => resume execution• Flexible but hard to be implemented
![Page 41: Processes Chapter 3. Table of Contents Multithreading Clients and Servers Code Migration Software Agents (special topic)](https://reader035.fdocuments.net/reader035/viewer/2022062719/56649ec75503460f94bd2db9/html5/thumbnails/41.jpg)
Models for Code Migration
• Initiator– Sender-initiated: a migration is initiated
from a the machine where the code currently resides or is being executed.
– Receiver-initiated: the target machine initiates the migration, for example, Java applet.
![Page 42: Processes Chapter 3. Table of Contents Multithreading Clients and Servers Code Migration Software Agents (special topic)](https://reader035.fdocuments.net/reader035/viewer/2022062719/56649ec75503460f94bd2db9/html5/thumbnails/42.jpg)
Models for Code Migration
• Migration in client/server model– Client => Server
• Access to the server’s resource
• security problem
– Server => Client• Improve the client-side performance
![Page 43: Processes Chapter 3. Table of Contents Multithreading Clients and Servers Code Migration Software Agents (special topic)](https://reader035.fdocuments.net/reader035/viewer/2022062719/56649ec75503460f94bd2db9/html5/thumbnails/43.jpg)
Models for Code Migration
• How to execute the migrated code in weak mobility?– By target process
• Avoid communication, efficient • Once again, security problem
– Start a new process• IPC
![Page 44: Processes Chapter 3. Table of Contents Multithreading Clients and Servers Code Migration Software Agents (special topic)](https://reader035.fdocuments.net/reader035/viewer/2022062719/56649ec75503460f94bd2db9/html5/thumbnails/44.jpg)
Models for Code Migration
• How to execute the migrated code in strong mobility?– Migrate process
– Clone process
• In UNIX, remote cloning is done by fork off a child process and let it run in the remote machine.
• Simple
![Page 45: Processes Chapter 3. Table of Contents Multithreading Clients and Servers Code Migration Software Agents (special topic)](https://reader035.fdocuments.net/reader035/viewer/2022062719/56649ec75503460f94bd2db9/html5/thumbnails/45.jpg)
Models for Code Migration
Alternatives for code migration.
![Page 46: Processes Chapter 3. Table of Contents Multithreading Clients and Servers Code Migration Software Agents (special topic)](https://reader035.fdocuments.net/reader035/viewer/2022062719/56649ec75503460f94bd2db9/html5/thumbnails/46.jpg)
Models for Code Migration
• Migration and Local resource– The resource segment in Fugetta’s
framework
– How to bind a resource to a process?
– What kind of resources a process may use?
![Page 47: Processes Chapter 3. Table of Contents Multithreading Clients and Servers Code Migration Software Agents (special topic)](https://reader035.fdocuments.net/reader035/viewer/2022062719/56649ec75503460f94bd2db9/html5/thumbnails/47.jpg)
Models for Code Migration
• Process-resource Binding– By identifier
• URL to a server by its internet address
• reference to local communication endpoint
– By value• Library code
– By type• Monitors, printers, …
![Page 48: Processes Chapter 3. Table of Contents Multithreading Clients and Servers Code Migration Software Agents (special topic)](https://reader035.fdocuments.net/reader035/viewer/2022062719/56649ec75503460f94bd2db9/html5/thumbnails/48.jpg)
Models for Code Migration
• Resource-machine binding– Unattached
• Typically (data) files associated with the migrated program
• Easy to move
– Fastened• Local databases and complete web sites• Reluctant to move
– Fixed• Local devices, local communication endpoint• Impossible to move
![Page 49: Processes Chapter 3. Table of Contents Multithreading Clients and Servers Code Migration Software Agents (special topic)](https://reader035.fdocuments.net/reader035/viewer/2022062719/56649ec75503460f94bd2db9/html5/thumbnails/49.jpg)
Migration and Local Resources
Actions to be taken with respect to the references to local resources when migrating code to another machine.
Unattached Fastened Fixed
By identifier
By value
By type
MV (or GR)
CP ( or MV, GR)
RB (or GR, CP)
GR (or MV)
GR (or CP)
RB (or GR, CP)
GR
GR
RB (or GR)
Resource-to machine binding
Process-to-resource
binding
GR: Establish a global systemwide reference
MV: Move the resource
CP: Copy the value of the resource
RB: Rebind process to locally available resource
![Page 50: Processes Chapter 3. Table of Contents Multithreading Clients and Servers Code Migration Software Agents (special topic)](https://reader035.fdocuments.net/reader035/viewer/2022062719/56649ec75503460f94bd2db9/html5/thumbnails/50.jpg)
Migration in Heterogeneous Systems
• So far, we always assume that the migrated code can be easily executed at the target machine.
• Homogeneous system: same architecture, same data representation, same compiler, same platform…
• Heterogeneous system
![Page 51: Processes Chapter 3. Table of Contents Multithreading Clients and Servers Code Migration Software Agents (special topic)](https://reader035.fdocuments.net/reader035/viewer/2022062719/56649ec75503460f94bd2db9/html5/thumbnails/51.jpg)
Migration in Heterogeneous Systems
• Weak mobility– Transfer the code– Compile it in the target machine– Execute it
• Strong mobility– Nightmare– How to deal with the platform-dependent
runtime information?– Migration stack solution: difficult with
more restriction
![Page 52: Processes Chapter 3. Table of Contents Multithreading Clients and Servers Code Migration Software Agents (special topic)](https://reader035.fdocuments.net/reader035/viewer/2022062719/56649ec75503460f94bd2db9/html5/thumbnails/52.jpg)
Migration in Heterogeneous Systems
The principle of maintaining a migration stack to support migration of an execution segment in a heterogeneous environment
3-15
![Page 53: Processes Chapter 3. Table of Contents Multithreading Clients and Servers Code Migration Software Agents (special topic)](https://reader035.fdocuments.net/reader035/viewer/2022062719/56649ec75503460f94bd2db9/html5/thumbnails/53.jpg)
Migration in Heterogeneous Systems
• Virtual machine: a charming solution– Source code in scripting languages
– Intermediate machine-independent code generated by compilers• Java Bytecode• JVM
![Page 54: Processes Chapter 3. Table of Contents Multithreading Clients and Servers Code Migration Software Agents (special topic)](https://reader035.fdocuments.net/reader035/viewer/2022062719/56649ec75503460f94bd2db9/html5/thumbnails/54.jpg)
Homework #1 due 11/26, 2pm
• Problem 3 in chapter 3, page 180– In the text, we described a multithreaded file
server, showing why it is better than a single-threaded server and a finite-state machine server. Are there any circumstances in which a single-threaded server might be better? Give an example.
• Problem 14 in chapter 3, page 181– Is a server that maintains a TCP/IP connection to
a client stateful or stateless?
• In general, what’s the benefit of code migration? What’s the difficulty of doing so?
![Page 55: Processes Chapter 3. Table of Contents Multithreading Clients and Servers Code Migration Software Agents (special topic)](https://reader035.fdocuments.net/reader035/viewer/2022062719/56649ec75503460f94bd2db9/html5/thumbnails/55.jpg)
Invited Talk
软件 agent 技术曹 春 博士
南大软件新技术国家重点实验室