Multiprocess vs. Multithread Architecture

Table of Content

Experimental Environment

We use a Debian Linux system on an Oracle Virtual Machine as our experimental environment. To demonstrate the benefit of parallelism, the virtual machine should have at least two virtual CPUs.

Examine CPU Info

As a prerequisite to the experiments, let’s examine the CPU information at the virtual machine.

lscpu

Multiprocess \(\pi\) Estimator vs. Multithread \(\pi\) Estimator

Multiprocess \(\pi\) Estimator

The instructor developed a multiprocess \(\pi\) estimator via Monte Carlo Simulation that you can download from

https://github.com/huichen-cs/OSClassExamples/tree/master/process/multiprocess/simulationapp

To compile the program, use make

make 

Below is an example command to run the program:

./master 4 200000000 1 2 200000000 3 4 200000000 5 6 200000000 7 8

You can time the run using the command /usr/bin/time, e.g.,

/usr/bin/time ./master 4 200000000 1 2 200000000 3 4 200000000 5 6 200000000 7 8

If the system reports that /usr/bin/time is not found, install it, i.e.,

su -c "apt-get install time"

or

sudo apt-get intall time

Experiment 1 Observing Benefits of Parallelism via Multiprocess Programming

To observe the benefits to parallelism, we can estimate \(\pi\) with the same amount of “work”, however, with different number of CPUs, e.g., in the following runs:

# 1 Process 
/usr/bin/time ./master 1 800000000 1 2 
# 2 processes
/usr/bin/time ./master 2 400000000 1 2 400000000 3 4 
# 4 processes
/usr/bin/time ./master 4 200000000 1 2 200000000 3 4 200000000 5 6 200000000 7 8

For each run, observe both of the elapsed time and the user time as well as the estimate value of \(\pi\).

Questions
  1. How many virtual CPUs does the virtual machine have?
  2. How much do the user times change as the number of processes increase?
  3. How much do the elapsed time change as the number of processes increase?
  4. Do we observe a speed-up due to parallelism when we increase the number of processes to exceed the number of CPUs?
  5. What about the accuracy of the estimated \(\pi\)?

Multithread \(\pi\) Estimator

The instructor developed a multithread \(\pi\) estimator via Monte Carlo Simulation that you can download from

https://github.com/huichen-cs/OSClassExamples/tree/master/thread/pthread/piestimator

To compile the program, use make

make 

Below is an example command to run the program:

./piestimator 4 200000000 1 2 200000000 3 4 200000000 5 6 200000000 7 8

You can time the run using the command /usr/bin/time, e.g.,

/usr/bin/time ./piestimator 4 200000000 1 2 200000000 3 4 200000000 5 6 200000000 7 8

If the system reports that /usr/bin/time is not found, install it, i.e.,

su -c "apt-get install time"

or

sudo apt-get intall time

Experiment 2 Observing Benefits of Parallelism via Multithread Programming

To observe the benefits to parallelism, we can estimate \(\pi\) with the same amount of “work”, however, with different number of CPUs, e.g., in the following runs:

# 1 Process 
/usr/bin/time ./piestimator 1 800000000 1 2 
# 2 processes
/usr/bin/time ./piestimator 2 400000000 1 2 400000000 3 4 
# 4 processes
/usr/bin/time ./piestimator 4 200000000 1 2 200000000 3 4 200000000 5 6 200000000 7 8

For each run, observe both of the elapsed time and the user time as well as the estimate value of \(\pi\).

Questions
  1. How many virtual CPUs does the virtual machine have?
  2. How much do the user times change as the number of processes increase?
  3. How much do the elapsed time change as the number of processes increase?
  4. Do we observe a speed-up due to parallelism when we increase the number of processes to exceed the number of CPUs?
  5. What about the accuracy of the estimated \(\pi\)?
  6. Is there any difference between the observations here and the observations of running the multiprocess \(\pi\) estimator.

Multiprocess Echo Server vs. Multithread Echo Server

The instructor designed an application that consists of two executables, a server program and a client program. The server program echos back whatever the client sends to it. There are two implements, one with multiprocess and the other multithread.

You can find the multiprocess version at: https://github.com/huichen-cs/OSClassExamples/tree/master/ipc/socket/echo

and download the multithread version at: https://github.com/huichen-cs/OSClassExamples/tree/master/thread/pthread/echoserver

In either implementation, the application follows the multiprocess/multithread programming pattern discussed in class. Whenever a client connects to the server, the server creates a process/thread to handle the client’s request.

Running Multiprocess Echo Server and Client

Upon downloading the program, you can compile the code via

make

To the program, you will open two terminals. At one terminal, run the server, and the other the client, e.g.,

# run server
./echoserver
# run client
./echoclient

Running Multithread Echo Server and Client

The procedure is idential to that for multipleprocess server and client. Upon downloading the program, you can compile the code via

make

To the program, you will open two terminals. At one terminal, run the server, and the other the client, e.g.,

# run server
./echoserver
# run client
./echoclient

Questions

  1. Can you view the threads of the server at the Linux system?
  2. Can you kill a child thread?
  3. What happens to the server process when you kill the child thread?
  4. Can you view the child processes of the server at the Linux system?
  5. Can you kill a child process?
  6. What happens to the server process when you kill the child process?
  7. The two implementations appears to be identical from the perspective of functionality, what are the advantage and the disadvantage of each?