You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: content/learning-paths/servers-and-cloud-computing/pinning-threads/using_taskset.md
+18-18Lines changed: 18 additions & 18 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -8,21 +8,21 @@ layout: learningpathall
8
8
9
9
## Create a single-threaded Python benchmark
10
10
11
-
Now that you have a program that utilizes all available CPU cores, you'll create a single-threaded program that's sensitive to execution variations. This simulates scenarios like a log ingesting process or a single-threaded consumer that needs to maintain a steady pace.
11
+
Create a single-threaded program that's sensitive to execution variations. This simulates scenarios like a log ingesting process or a single-threaded consumer that needs to maintain a steady pace.
12
12
13
13
Check that you have Python installed:
14
14
15
15
```bash
16
16
python --version
17
17
```
18
18
19
-
You should see the version of Python:
19
+
The output is similar to:
20
20
21
21
```output
22
22
Python 3.12.3
23
23
```
24
24
25
-
If Python isn't installed, use your Linux package manager to install it or refer to the[Python downloads page](https://www.python.org/downloads/).
25
+
If Python isn't installed, use your Linux package manager to install it or see the [Python downloads page](https://www.python.org/downloads/).
26
26
27
27
Next, create a virtual environment to install packages without interfering with system packages:
28
28
@@ -32,7 +32,7 @@ source venv/bin/activate
32
32
pip install matplotlib
33
33
```
34
34
35
-
Use an editor to create a file named `single_threaded_python_script.py` with the following code. This script repeatedly measures the execution time of a computational function and writes the results to `data.txt`. It then generates time-series graphs to illustrate the effects of thread pinning:
35
+
Create a file named `single_threaded_python_script.py` with the following code. This script measures the execution time of a computational function, writes results to `data.txt`, and generates time-series graphs to illustrate the effects of thread pinning:
The terminal output shows the execution time for `prog` under the three scenarios. The Python script also generates three files: `Free.jpg`, `Exclusive.jpg`, and `Shared.jpg`.
200
200
201
-
As the terminal output below shows, the `free-script.sh` scenario (where the Linux scheduler assigns threads to cores without restriction) completes `prog` the fastest at 5.8 seconds. The slowest execution occurs when the Python script has exclusive access to CPU 0, which is expected because you've constrained `prog` to fewer cores:
201
+
The terminal output shows the `free-script.sh` scenario (where the Linux scheduler assigns threads to cores without restriction) completes `prog` the fastest at 5.8 seconds. The slowest execution occurs when the Python script has exclusive access to CPU 0, which is expected because `prog` is constrained to fewer cores:
202
202
203
203
```output
204
204
Answer = 3.14159 5 iterations took 5838 milliseconds
@@ -210,21 +210,21 @@ However, this represents a trade-off with the Python script's performance.
210
210
211
211
### Free scenario results
212
212
213
-
Looking at `Free.jpg`, you can see periodic zones of high latency (3.5 ms) that likely occur when there's contention between `prog` and the Python script:
213
+
The `Free.jpg` graph shows periodic zones of high latency (3.5 ms) that likely occur when there's contention between `prog` and the Python script:
214
214
215
-

215
+

216
216
217
217
### Shared-pinned scenario results
218
218
219
-
When pinning the Python script to core 0 while `prog` remains free to use any cores, you observe similar behavior:
219
+
When pinning the Python script to core 0 while `prog` remains free to use any cores, the behavior is similar:
220
220
221
-

221
+

222
222
223
223
### Exclusive scenario results
224
224
225
-
When the Python script has exclusive access to core 0, you observe more consistent execution time around 0.49 ms because the script doesn't contend with any other demanding processes:
225
+
When the Python script has exclusive access to core 0, the execution time is more consistent around 0.49 ms because the script doesn't contend with any other demanding processes:
226
226
227
-

227
+

228
228
229
229
## Understanding the trade-offs
230
230
@@ -238,10 +238,10 @@ Multiple factors influence this behavior, including the Linux scheduler algorith
238
238
239
239
## What you've accomplished and what's next
240
240
241
-
In this section, you've:
241
+
In this section:
242
242
- Created a single-threaded Python benchmark that measures execution time variations
243
243
- Used `taskset` to pin processes to specific CPU cores
244
244
- Compared three thread pinning strategies: free, shared-pinned, and exclusive
245
245
- Analyzed the trade-offs between throughput and latency consistency
246
246
247
-
In the next section, you'll learn how to use source code modifications and environment variables to control thread affinity programmatically.
247
+
Next, you learn how to control thread affinity programmatically using source code modifications.
0 commit comments