Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Why does running the processes on different CPUs slow down the printing speed? #1

Open
joshuakimDwan opened this issue Mar 12, 2024 · 2 comments
Labels
solved Question solved

Comments

@joshuakimDwan
Copy link

joshuakimDwan commented Mar 12, 2024

I've been experimenting with the abstr3_proc_sched program as per the instructions provided in the course materials. Initially, I ran ./abstr3_proc_sched 3 to observe its behavior, specifically the rate at which it prints output. As expected, the program's execution seemed to slow down, which led me to explore how pinning processes to different CPUs would affect performance.

My assumption was that running ./abstr3_proc_sched 3 concurrently with different target CPUs (e.g., ./abstr3_proc_sched 3 and ./abstr3_proc_sched 4) wouldn't slow down the output printing speed as much, since each process would have a dedicated CPU. However, the results didn't entirely meet my expectations.

Here are the details of my experiments:

Case 1: Single Instance Execution
I executed time ./abstr3_proc_sched 3 and terminated the process after the 30th print statement. The time measurements were as follows:

...
[ 2336 pinned to:  3 running on:  3]       29
[ 2336 pinned to:  3 running on:  3]       30
^C

real	0m14.019s
user	0m13.980s
sys	0m0.035s

Case 2: Concurrent Execution on the Same CPU
Next, I ran two instances of time ./abstr3_proc_sched 3 simultaneously, stopping both after the 30th print statement. The observed times were:

[ 2336 pinned to:  3 running on:  3]       29
[ 2336 pinned to:  3 running on:  3]       30
^C

real	0m26.709s
user	0m26.473s
sys	0m0.234s

Case 3: Concurrent Execution on Different CPUs
Finally, I executed time ./abstr3_proc_sched 3 and ./abstr3_proc_sched 4 together, again terminating after the 30th print statement. The timing results were:

...
[ 2336 pinned to:  3 running on:  3]       29
[ 2336 pinned to:  3 running on:  3]       30
^C

real	0m27.642s
user	0m13.942s
sys	0m0.047s

My environment:

Operating System: [macOS Ventura 13.4]
- Virtual Machine OS: [Ubuntu 20.04.6 LTS (GNU/Linux 5.4.0-173-generic x86_64)]
Hardware:
- CPU: [Apple M1]
- Cores/Threads: [8 Cores, 8 Threads]
- RAM: [16GB]

From these experiments, I noticed that even when running processes on separate CPUs, the printing speed didn't improve as much as I anticipated, particularly in terms of real time.

Question: Why does running the processes on different CPUs slow down the printing speed?

@kwonsw055
Copy link
Collaborator

This actually happens due to the UTM environment.
In the UTM emulation environment, the CPUs visible on the VM are virtual and do not have a one-to-one relation with the physical cores by default.

If you select "Force Multicore" in the VM editing options, UTM will try to utilize the system's multiple cores.
screenshot

Then, time ./abstr3_proc_sched 3 shows the (almost) same time regardless of the presence of ./abstr3_proc_sched 4.
abstr3

Also, if you run the same experiments on a VirtualBox (which uses virtualization) or on a native machine, it will show the expected results.

@kwonsw055 kwonsw055 added the solved Question solved label Mar 13, 2024
@joshuakimDwan
Copy link
Author

It worked well. Thank you so much!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
solved Question solved
Development

No branches or pull requests

2 participants