Threads Clients Servers Code Migration Software Agents Summary CHAPTER 3 Processes Threads Clients Servers Code Migration Software Agents Summary
Process A program in execution An instance of a program running on a computer The entity that can be assigned to and executed on a processor A unit of activity characterized by the execution of a sequence of instructions, a current state, and an associated set of system instructions
Threads:Introduction Process : A program in execution OS create a number of virtual processors for running a different program Process Table : to keep track of VP Entries to CPU register value. Memory Maps Open Files Accounting Information Privileges etc Multiple Processes may be concurrently sharing the same resources.
Threads:Introduction Each time process is created- OS must create Independent address space Initializing memory segment Setting up a stack for temporary data Switching the CPU between two process require saving CPU Context, modify register in MMU and invalidate address translation cache in TLB. Both of them is expensive
Threads:Introduction Threads : execution of part of process on virtual processor lightweight process Contains only the minimum information to allow CPU to be shared by several thread. ie: mutex variable,
Thread Usage in Non-distributed Systems Single threaded process Whenever a blocking system call is executed- the whole process is blocked. Would be able to service only one client at a time. Run with two threads- Microsoft Excel Spreadsheet One handling interaction with the user One for updating the spreadsheet
Thread Usage in Non-distributed Systems Exploit parallelism in the case of multiprocessor system. Shared data is stored in shared memory Each CPU run different thread. Also useful in large application Collection of cooperating programs, each to be executed by a separate process. IPC in UNIX system
Process/Thread Usage in Nondistributed Systems Context switching as the result of IPC IPC drawback: communication between two process requires extensive context switching- kernel mode-user mode
Thread Implementation(1) Instead of using processes, an application can also be constructed by separate threads. Communication between threads is dealt by using shared data. Thread switching is done in user space. Threads are generally provided in the form of a thread package Operation to create, destroy & synchronization between them Divide the large application into parts that could be logically executed at the same time
Thread Implementation(2) Two approaches Construct the thread library – executed in user mode Kernel be aware of threads and schedule them User-level threads Cheap to create & destroy in term of operation to allocate MM Switching threads context can be done with a few instruction-synchronizing when entering a section of shared data Only the value of CPU register need to be changed No need to change memory map, TLB etc Drawback is – the invocation of blocking system call will block the entire process belonging to the threads –(i/o) Kernel-Level Threads Same as process – have to go through kernel itself
Combining kernel-level and user-level threads There can be several LWP per process run on kernel space System also user-level thread process run on user space Creating and destroying thread Synchronization Mutexes Condition Variable
Thread Implementation(3) Combining kernel-level and user-level threads. Thread table : keep track of the current set of threads – shared by LWP Lightweight Processes
Example: Java Thread Java threads may be created by: Extending Thread class Implementing the Runnable interface Java threads are managed by the JVM.
Multithreaded Client Hide Communication Latency initiate communication and do something else Eg: Web Browser web doc consist of HTML + image + icons the browser has to set up TCP/IP connection read incoming data + pass to display Setup tcp/ip… blocking operation Start display data while fetching it- text -- image
Multithreaded Servers (1) A multithreaded server organized in a dispatcher/worker model.
Clients User Interfaces Interact with a human and remote server. telnet X windows; Unix – % xhost + %setenv DISPLAY <hostname/address>
The basic organization of the X Window System
Client-Side Software for Distribution Transparency Client not only comprises of UI processing and data level are also executed in client side. A client has their own software must provide distribution transparency A client should not aware that it is communicating with a remote process in the server side. Replication?
Client-Side Software for Distribution Transparency Communication is handle by client middleware. – cache data A possible approach to transparent replication of a remote object using a client-side solution.
Servers: General Design Issues Server just listen for the request Ensure the request is served Wait for the next incoming request Servers is organized in several ways:- Iterative server Handles the request Return the response to the requesting client Concurrent server Pass the request to separate thread/process (not handle by itself) Wait for next incoming request E.g:multithreaded server
Servers: General Design Issues 3.7 Client-to-server binding using a daemon as in DCE Client-to-server binding using a superserver as in UNIX
Servers: another Design Issues Stateless server Ignore the information on the state of its client Can change the server state without informing the client Eg: Web Server Stateful server Maintains information on its clients Table containing (client, file)
Code Migration In Distributed System- entire process was moved from one machine to another Moving a running process is costly in term of performance So – Ship part of the client application to the server and send only the result across the network Improve performance More flexible
Migrating Code The principle of dynamically configuring a client to communicate to a server. The client first fetches the necessary software, and then invokes the server.
Models for Code Migration Process for code migration is divided into three segments; Code Segment The part that contains the set of instructions that make up the program that is being executed. Resource Segment Reference to external resource needed by the process ie. Printers, files, devices other pcs etc. Execution Segment store current execution state of a process, consisting of private data, the stack, and the program counter.
Models for Code Migration Alternatives for code migration.
Migration in Heterogeneous Systems 3-15 The principle of maintaining a migration stack to support migration of an execution segment in a heterogeneous environment
Software Agents Autonomous process capable of reacting to and initiating changes in, its environment, possibly in collaboration with users and other agents. Features: ability to act on its own – take initiative where appropriate i.e agent-based web crawler
Software Agents in Distributed Systems Property Common to all agents? Description Autonomous Yes Can act on its own Reactive Responds timely to changes in its environment Proactive Initiates actions that affects its environment Communicative Can exchange information with users and other agents Continuous No Has a relatively long lifespan Mobile Can migrate from one site to another Adaptive Capable of learning Some important properties by which different types of agents can be distinguished.
The general model of an agent platform (adapted from [fipa98-mgt]). Agent Technology The general model of an agent platform (adapted from [fipa98-mgt]).