Skip to content

Commit 3a80d6f

Browse files
committed
Add glossary entries for CPU-bound and I/O-bound and link to them
1 parent 114f465 commit 3a80d6f

11 files changed

Lines changed: 42 additions & 16 deletions

‎Doc/glossary.rst‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,17 @@ Glossary
372372
:keyword:`async with` keywords. These were introduced
373373
by :pep:`492`.
374374

375+
CPU-bound
376+
Describes a task that spends most of its time computing, which keeps a
377+
CPU core busy. If each task keeps a core busy on its own, running the
378+
tasks :term:`concurrently <concurrency>` on one core does not finish the
379+
work sooner, because the tasks still have to take turns using that core.
380+
Running independent tasks in :term:`parallel <parallelism>` on several
381+
cores can finish it sooner, although the cores do the same amount of work
382+
in total. For example, if sorting a large list takes one second, sorting
383+
three of them takes about three seconds on one core and can take as
384+
little as one second on three cores. See also :term:`I/O-bound`.
385+
375386
CPython
376387
The canonical implementation of the Python programming language, as
377388
distributed on `python.org <https://www.python.org>`_. The term "CPython"
@@ -767,6 +778,15 @@ Glossary
767778
compare unequal (except with themselves), and their hash value is derived
768779
from their :func:`id`.
769780

781+
I/O-bound
782+
Describes a task that spends most of its time waiting for input or
783+
output, such as a network response or a disk read, and little of it using
784+
the CPU. While one I/O-bound task waits, the program can work on
785+
another, so running such tasks :term:`concurrently <concurrency>` lets
786+
their waits overlap, even on a single CPU core. For example, three
787+
downloads that each take one second can finish in about one second when
788+
run concurrently, instead of three. See also :term:`CPU-bound`.
789+
770790
IDLE
771791
An Integrated Development and Learning Environment for Python.
772792
:ref:`idle` is a basic editor and interpreter environment

‎Doc/library/asyncio-dev.rst‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ code in a different process.
120120
Running Blocking Code
121121
=====================
122122

123-
Blocking (CPU-bound) code should not be called directly. For example,
123+
Blocking (:term:`CPU-bound`) code should not be called directly. For example,
124124
if a function performs a CPU-intensive calculation for 1 second,
125125
all concurrent asyncio Tasks and IO operations would be delayed
126126
by 1 second.

‎Doc/library/asyncio-llapi-index.rst‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ See also the main documentation section about the
102102
:class: full-width-table
103103

104104
* - ``await`` :meth:`loop.run_in_executor`
105-
- Run a CPU-bound or other blocking function in
105+
- Run a :term:`CPU-bound` or other blocking function in
106106
a :mod:`concurrent.futures` executor.
107107

108108
* - :meth:`loop.set_default_executor`

‎Doc/library/asyncio-task.rst‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1061,13 +1061,14 @@ Running in threads
10611061
Return a coroutine that can be awaited to get the eventual result of *func*.
10621062

10631063
This coroutine function is primarily intended to be used for executing
1064-
IO-bound functions/methods that would otherwise block the event loop if
1064+
:term:`I/O-bound` functions/methods that would otherwise block
1065+
the event loop if
10651066
they were run in the main thread. For example::
10661067

10671068
def blocking_io():
10681069
print(f"start blocking_io at {time.strftime('%X')}")
10691070
# Note that time.sleep() can be replaced with any blocking
1070-
# IO-bound operation, such as file operations.
1071+
# I/O-bound operation, such as file operations.
10711072
time.sleep(1)
10721073
print(f"blocking_io complete at {time.strftime('%X')}")
10731074

@@ -1098,9 +1099,10 @@ Running in threads
10981099
.. note::
10991100

11001101
Due to the :term:`GIL`, ``asyncio.to_thread()`` can typically only be used
1101-
to make IO-bound functions non-blocking. However, for extension modules
1102+
to make I/O-bound functions non-blocking. However, for extension modules
11021103
that release the GIL or alternative Python implementations that don't
1103-
have one, ``asyncio.to_thread()`` can also be used for CPU-bound functions.
1104+
have one, ``asyncio.to_thread()`` can also be used for
1105+
:term:`CPU-bound` functions.
11041106

11051107
.. versionadded:: 3.9
11061108

‎Doc/library/asyncio-threading.rst‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ asyncio and free-threaded Python
77

88
asyncio uses an event loop as a scheduler to enable highly efficient
99
concurrency by switching between tasks to allow non-blocking I/O
10-
operations. This results in better performance for I/O-bound use
11-
cases. It also allows off-loading CPU-bound work to a thread or
10+
operations. This results in better performance for :term:`I/O-bound` use
11+
cases. It also allows off-loading :term:`CPU-bound` work to a thread or
1212
process pool, but that is still limited by the :term:`global
1313
interpreter lock` in CPython.
1414

‎Doc/library/asyncio.rst‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ asyncio is used as a foundation for multiple Python asynchronous
2626
frameworks that provide high-performance network and web-servers,
2727
database connection libraries, distributed task queues, etc.
2828

29-
asyncio is often a perfect fit for IO-bound and high-level
29+
asyncio is often a perfect fit for :term:`I/O-bound` and high-level
3030
**structured** network code.
3131

3232
.. seealso::

‎Doc/library/concurrency.rst‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ Concurrent Execution
66

77
The modules described in this chapter provide support for concurrent
88
execution of code. The appropriate choice of tool will depend on the
9-
task to be executed (CPU bound vs IO bound) and preferred style of
9+
task to be executed (:term:`CPU-bound` vs :term:`I/O-bound`) and
10+
preferred style of
1011
development (event driven cooperative multitasking vs preemptive
1112
multitasking). Here's an overview:
1213

‎Doc/library/concurrent.futures.rst‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -221,8 +221,8 @@ And::
221221

222222
.. versionchanged:: 3.8
223223
Default value of *max_workers* is changed to ``min(32, os.cpu_count() + 4)``.
224-
This default value preserves at least 5 workers for I/O bound tasks.
225-
It utilizes at most 32 CPU cores for CPU bound tasks which release the GIL.
224+
This default value preserves at least 5 workers for :term:`I/O-bound` tasks.
225+
It utilizes at most 32 CPU cores for :term:`CPU-bound` tasks which release the GIL.
226226
And it avoids using very large resources implicitly on many-core machines.
227227

228228
ThreadPoolExecutor now reuses idle worker threads before starting

‎Doc/library/functools.rst‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,8 @@ The :mod:`!functools` module defines the following functions:
149149
lru_cache(maxsize=128, typed=False)
150150

151151
Decorator to wrap a function with a memoizing callable that saves up to the
152-
*maxsize* most recent calls. It can save time when an expensive or I/O bound
152+
*maxsize* most recent calls. It can save time when an
153+
expensive or :term:`I/O-bound`
153154
function is periodically called with the same arguments.
154155

155156
The cache is threadsafe so that the wrapped function can be used in

‎Doc/library/profiling.sampling.rst‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -779,7 +779,8 @@ hotspot---actively using the CPU. Optimization should focus on algorithmic
779779
improvements or more efficient code.
780780

781781
If a function is high in wall-clock mode but low or absent in CPU mode, it is
782-
I/O-bound or waiting. The function spends most of its time waiting for network,
782+
:term:`I/O-bound` or waiting. The function spends most of its time
783+
waiting for network,
783784
disk, locks, or sleep. CPU optimization won't help here; consider async I/O,
784785
connection pooling, or reducing wait time instead.
785786

0 commit comments

Comments
 (0)