Multiprocess vs. Multithread Architecture
Table of Content
- Multiprocess vs. Multithread Architecture
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
- How many virtual CPUs does the virtual machine have?
- How much do the user times change as the number of processes increase?
- How much do the elapsed time change as the number of processes increase?
- Do we observe a speed-up due to parallelism when we increase the number of processes to exceed the number of CPUs?
- 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
- How many virtual CPUs does the virtual machine have?
- How much do the user times change as the number of processes increase?
- How much do the elapsed time change as the number of processes increase?
- Do we observe a speed-up due to parallelism when we increase the number of processes to exceed the number of CPUs?
- What about the accuracy of the estimated \(\pi\)?
- 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
- Can you view the threads of the server at the Linux system?
- Can you kill a child thread?
- What happens to the server process when you kill the child thread?
- Can you view the child processes of the server at the Linux system?
- Can you kill a child process?
- What happens to the server process when you kill the child process?
- The two implementations appears to be identical from the perspective of functionality, what are the advantage and the disadvantage of each?