Skip to content

Commit 379bc7c

Browse files
committed
Add new section about performance in multithreading
1 parent ef91601 commit 379bc7c

File tree

5 files changed

+25
-0
lines changed

5 files changed

+25
-0
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ Simple and easy to understand code examples for most of the Concurrent APIs prov
1717
- [Thread Signalling](./src/com/codecafe/concurrency/threadsignalling)
1818
- [Daemon Threads](./notes/daemon-threads.md) - [[code](./src/com/codecafe/concurrency/thread/daemonthreads/Main.java)]
1919

20+
#### [Performance in Multithreading](./notes/performance-in-multithreading.md)
21+
- Latency
22+
- Throughput
23+
2024
#### Thread synchronization and locks
2125
- [The `synchronized` keyword](./src/com/codecafe/concurrency/_synchronized)
2226
- [Locks](./src/com/codecafe/concurrency/locks)

images/latency_1.png

5.67 KB
Loading

images/latency_2.png

7.92 KB
Loading

images/latency_3.png

7.97 KB
Loading
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Performance in Multithreading
2+
3+
There are two main criteria for performance in multithreaded applications:
4+
5+
1. **Latency** - The time to completion of a task. Measured in _time_ units.
6+
2. **Throughput** - The amount of tasks completed in a given period. Measured in _tasks/time_ unit.
7+
8+
## Latency
9+
10+
Suppose we have a single task which can be completed by a single thread sequentially within time T
11+
12+
![Latency](../images/latency_1.png)
13+
14+
We can first break the task into multiple independent tasks
15+
16+
![Latency](../images/latency_2.png)
17+
18+
Then we can schedule these sub-tasks to run in parallel to each other in different threads,
19+
and theoretically we want to achieve the latency of `T/N` (N = number of sub-tasks).
20+
21+
![Latency](../images/latency_3.png)

0 commit comments

Comments
 (0)