Presentation is loading. Please wait.

Presentation is loading. Please wait.

CSS490 Process Management

Similar presentations


Presentation on theme: "CSS490 Process Management"— Presentation transcript:

1 CSS490 Process Management
Textbook Ch8 Instructor: Munehiro Fukuda These slides were compiled from the course textbook, the reference books, and the instructor’s original materials. Hello! Everyone, My name is Shinya Kobayashi. Today, I am going to present our paper titled “Inter-Cluster Job Coordination Using Mobile Agents” on behalf of the first author, Munehiro Fukuda. Munehiro was hoping to show up and present the paper at AMS2001, however he got to wait in Japan until he will get an H1B visa. Since I received the presentation materials from him quite recently, please allow me to present this paper using this script. I can respond to your questions as far as I know, however you can also ask Munehiro by . His address is on the title page of our paper. (time 1:05) Winter, 2004 CSS490 Process Management

2 Processes Definition and Aspects
An environment to execute a program A process consists of: A CPU register set (including program counter) An dependent address space including Text (code) Data (global data) Stack (local variables) Heap (dynamic data) Files Communication resources (sockets) Threads and their synchronization facility text heap stack data 2N Address Space ID Process Control Block PC SP fd[64] TCB socket Winter, 2004 CSS490 Process Management

3 Processes Creation and Resource Sharing
A parent process creates child processes through fork( ). A child process overloads a new program on it through execve( ). Execution They run in concurrent. A parent may wait for the termination of a child through wait( ). Resource sharing Resource inherited by children: file descriptors, shared memory and system queues Resource not inherited by children: address space ID Parent’s PCB PC SP fd[64] TCB text heap stack data 2N Address Space Shared memory ID Child’s PCB PC SP fd[64] TCB text heap stack data 2N Address Space Shared memory copy shared shared socket shared Winter, 2004 CSS490 Process Management

4 Processes Creation and Copy-on-Write
Physical address space Upon creating a child process A virtual address space is allocated to a child. Corresponding physical memory is still mapped to its parent. Upon a write operation, physical memory is allocated to a child and data is copied. Parent’s virtual address space data data w Shared memory w data stack text Shared memory w Child’s virtual address space data w text Shared memory w stack stack text Winter, 2004 CSS490 Process Management

5 Processes Creation and Load Balancing
Transfer policy: Create a new process Locally Remotely → Location Policy Static: transfer processes to predefined destinations Adaptive:transfer processes to destinations based on run-time information Centralized load-sharing: A load manager take care of correcting info and migrating processes. Hierarchical load-sharing: A system consists of a tree structure where each node takes care of its child processes for load balancing Decentralized load-sharing Sender-initiated: A heavy-loaded node sends out a new process. Receiver-initiated: A light-loaded node advertises its existence. Winter, 2004 CSS490 Process Management

6 CSS490 Process Management
Threads data text Stack A Stack B Stack C heap o 2N ID Process Control Block fd[64] TCB Threads: The basic unit of CPU utilization Control of Program Process can have two or more parallel controls of program → multiple threads. Belong to the same process. No protection between threads. Advantages: Light creation Light context switch Suitable to parallel computing Natural form of resource sharing ID Thread A PC SP ID Thread B PC SP ID Thread C PC SP Winter, 2004 CSS490 Process Management

7 Client and Server with Threads
Can avoid a block on RPC by having two threads. Server: Assume: A request consists of 2ms processing and 4ms disk I/O. Single-threaded Server Needs 6ms for a request Can process 166 request/second If three threads pick up and work on a request in turn: Can overlap processing and I/O Can process 1000/4 =250 request/second. Client Server RPC Request queue thread Computation requests Winter, 2004 CSS490 Process Management

8 Multithreaded Clients Architecture
Why Multithreaded Clients Hide network latency Main Thread: Interacts with a client user Work on computation Dispatch a request to a child thread Child threads Sends a request to a given server through TCP or RPC. Waits for a response Forwards a response to the main. Client Main thread Child Threads User request Server 1 RPC or TCP Pick up request Server 2 RPC or TCP response request Server 3 RPC or TCP RPC or TCP request Server 4 Enqueue Winter, 2004 CSS490 Process Management

9 Multithreaded Clients Example
Web browser Web browser Requests and reads the main HTML file. For each <img src=“…”>, <object>, <applet>, etc., Spawns a child thread Child threads: Sets up an HTTP connection Reads each web part. Main thread Child Threads User Request the main HTML HTTP Server <html> Scan the file HTTP Spawn a thread Server img HTTP Spawn a thread Server applet Winter, 2004 CSS490 Process Management

10 Multithreaded Servers Architecture
Dispatcher-worker model The worker pool (a) Per-request threads (b) Per-connection threads (c) Team model Per-object threads (d) Pipeline model (e) (a) (b) Pick up a request Spawn for each request accept queue accept (c) (d) Session Remote object (e) request accept accept Spawn for each session request Remote object process request Remote object response Winter, 2004 CSS490 Process Management

11 Multithreaded Servers Example
Object Server Instantiates remote objects Associates each with an independent thread Let a thread maintain and protect its object Requests Accepted at request dispatcher Forwarded to an object wrapper including objects residing under the same policy Picked up by the destination thread file A stub Per-object thread file B file C Object wrapper req que Request dispatcher cgi 1 cgi 2 cgi 3 Server Client requests Thread Group Daemon thread may Server for per-object threads Winter, 2004 CSS490 Process Management

12 Threads v.s. Multiple Processes
Maybe, we can implement a server of multiple processes? Server consisting of Threads Multiple Processes Creation Light overhead Heavy overhead Context switch Cheap Expensive Remote object sharing Easy Needs shared memory Priority Easy to change Not quite dynamically changeable Protection Vulnerable Safe Winter, 2004 CSS490 Process Management

13 Thread Implementation Library and Class
Functions Java Pthread Solaris Thread Create a new thread wew Thread( ) pthread_create( ) thr_create( ) Terminate myself destroy( ) pthread_exit( ) thr_exit( ) Wait for a given thread to be terminated join( ) pthread_join( ) thr_join( ) Terminate a given thread stop( ) pthread_kill( ) thr_kill( ) Get my thread object currentThread( ) pthread_self( ) thr_self( ) Relinquish CPU and put myself in a ready queue yield( ) thr_yield( ) Suspend a given thread suspend( ) thr_suspend( ) Resume a give thread resume( ) thr_continue( ) Get my current running priority getPriority( ) pthread_getschedparam( ) thr_getprio( ) Change my current running priority setPriority( ) pthread_setschedparam( ) thr_setprio( ) Wait for another thread to signal me wait( ) pthread_cond_wait( ) cond_wait( ) Signal another thread waiting for me signal( ) pthread_cond_signal( ) cond_signal( ) Winter, 2004 CSS490 Process Management

14 Thread Implementation C++ Example
#include <iostream> #include <string> using namespace std; #include <pthread.h> #include <unistd.h> void* thread_func( void *param ) { for ( int i = 0; i < 5; i++ ) { sleep( 2 ); cout << "I'm a slave: " << *( (string *)param ) << endl; } return NULL; void main( int argc, char *argv[] ) { pthread_t child; string arg; cout << "enter message: "; cin >> arg; pthread_create( &child, NULL, thread_func, (void *)&arg ); for ( int i = 0; i < 10; i++ ) { sleep( 1 ); cout << "I'm a master: " << arg << endl; pthread_join( child, NULL ); cout << "Master synched with slave" << endl; Compilation and Execution Source Code $ g++ thread.cpp -lpthread $ a.out enter message: hello! I'm a master: hello! I'm a slave: hello! Master synched with slave $ Winter, 2004 CSS490 Process Management

15 Thread Implementation Java Example
MyThread.java public class MyThread { public static void main( String args[] ) { String arg = args[0]; ThreadFunc child = new ThreadFunc( arg ); child.start( ); for ( int i = 0; i < 10; i++ ) { try { Thread.sleep( 1000 ); } catch ( InterruptedException e ) { }; System.out.println( "I'm a master: " + arg ); } child.join( ); System.out.println( "Master synched with slave" ); public class ThreadFunc extends Thread { public ThreadFunc( String param ) { this.param = param; public void run( ) { for ( int i = 0; i < 5; i++ ) { Thread.sleep( 2000 ); System.out.println( "I'm a slave: " + param ); String param; Compilation and Execution $ ls MyThread.java ThreadFunc.java $ javac MyThread.java $ java MyThread hello! I'm a master: hello! I'm a slave: hello! Master synched with slave $ ThreadFunc.java Winter, 2004 CSS490 Process Management

16 Exercises (No turn-in)
Why is the copy-on-write technique so effective? Why can threads perform their context switch faster than processes? What are the thread groups? What are the daemon threads? How can those contribute to the multithreaded server? If you comment out the following statement from the C++ code on Slide 14, what change will you observer in the execution? pthread_join( child, NULL ); If you comment out the following statement from the Java code on Slide 15, what change will you observe in the execution? child.join( ); Winter, 2004 CSS490 Process Management


Download ppt "CSS490 Process Management"

Similar presentations


Ads by Google