Commit 05ca192
authored
feat: Add loom Support. (#159)
Motivation:
Add Loom support.
refs: #90 , again
Modification:
1. add `handlerExecutor()` and some helper methods for virtual threads.
2. some documents.
Result:
Virtual threads supported.
`wrk` is needed to run the benchmark
- miniAppWithSleep 100ms : ↑2300%
- todoDb: ~↓6%
- staticFiles: ~↓6%
```shell
./mill --no-build-lock benchmark.runBenchmarks
```
Results of same 4 Carrier/Platform threads:
```scala
[1] staticFilesWithLoom result with (platform threads):
[1] Running 30s test @ http://localhost:8080/
[1] 4 threads and 100 connections
[1] Thread Stats Avg Stdev Max +/- Stdev
[1] Latency 1.23ms 436.88us 28.64ms 98.91%
[1] Req/Sec 20.54k 1.08k 22.69k 93.44%
[1] 2461250 requests in 30.10s, 342.70MB read
[1] Requests/sec: 81766.27
[1] Transfer/sec: 11.38MB
[1]
[1] staticFilesWithLoom result with (virtual threads):
[1] Running 30s test @ http://localhost:8080/
[1] 4 threads and 100 connections
[1] Thread Stats Avg Stdev Max +/- Stdev
[1] Latency 4.41ms 14.69ms 157.91ms 95.15%
[1] Req/Sec 19.00k 4.29k 22.09k 88.63%
[1] 2266289 requests in 30.02s, 315.55MB read
[1] Requests/sec: 75488.32
[1] Transfer/sec: 10.51MB
[1]
[1] todoDbWithLoom result with (platform threads):
[1] Running 30s test @ http://localhost:8080/
[1] 4 threads and 100 connections
[1] Thread Stats Avg Stdev Max +/- Stdev
[1] Latency 1.22ms 172.42us 11.67ms 96.46%
[1] Req/Sec 20.62k 1.29k 42.72k 93.01%
[1] 2466143 requests in 30.10s, 395.12MB read
[1] Non-2xx or 3xx responses: 2466143
[1] Requests/sec: 81929.40
[1] Transfer/sec: 13.13MB
[1]
[1] todoDbWithLoom result with (virtual threads):
[1] Running 30s test @ http://localhost:8080/
[1] 4 threads and 100 connections
[1] Thread Stats Avg Stdev Max +/- Stdev
[1] Latency 3.97ms 13.20ms 160.29ms 95.28%
[1] Req/Sec 19.21k 3.68k 22.32k 89.41%
[1] 2284539 requests in 30.03s, 366.02MB read
[1] Non-2xx or 3xx responses: 2284539
[1] Requests/sec: 76072.80
[1] Transfer/sec: 12.19MB
[1]
[1] minimalApplicationWithLoom result with (platform threads):
[1] Running 30s test @ http://localhost:8080/
[1] 4 threads and 100 connections
[1] Thread Stats Avg Stdev Max +/- Stdev
[1] Latency 1.05s 575.57ms 1.99s 57.89%
[1] Req/Sec 10.05 3.94 30.00 81.66%
[1] 1152 requests in 30.03s, 172.12KB read
[1] Socket errors: connect 0, read 0, write 0, timeout 1076
[1] Requests/sec: 38.36
[1] Transfer/sec: 5.73KB
[1]
[1]
[1] minimalApplicationWithLoom result with (virtual threads):
[1] Running 30s test @ http://localhost:8080/
[1] 4 threads and 100 connections
[1] Thread Stats Avg Stdev Max +/- Stdev
[1] Latency 106.11ms 2.74ms 126.59ms 77.47%
[1] Req/Sec 239.19 36.74 252.00 92.68%
[1] 28100 requests in 30.03s, 4.10MB read
[1] Requests/sec: 935.74
[1] Transfer/sec: 139.81KB
```
Some design choices:
1. Using MethodHandle/Reflect to make it compile on Java 8 too.
2. Using MethodHandle to name the virtual threads that are needed, JPMS
code can be added to open the can by default, but that is a little
over-killed, so better with an explicitly `--add-opens
java.base/java.lang=ALL-UNNAMED`
3. Add a virtualize or screen method to create a virtual thread executor
from a **platform** thread pool, this is useful, especially if you want
to limit the underlying queue size, FJP is unbounded.
4. Users can override the `handleExecutor` directly too.1 parent 5257192 commit 05ca192
File tree
18 files changed
+780
-42
lines changed- .github/workflows
- cask/src/cask
- internal
- main
- docs/pages
- example
- minimalApplicationWithLoom
- app
- src
- test/src
- staticFiles2
- staticFilesWithLoom
- app
- resources/cask
- src
- test/src
- staticFiles
- todoDbWithLoom
- app
- src
- test/src
18 files changed
+780
-42
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
19 | | - | |
| 19 | + | |
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
| |||
27 | 27 | | |
28 | 28 | | |
29 | 29 | | |
30 | | - | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
31 | 35 | | |
32 | 36 | | |
33 | 37 | | |
34 | 38 | | |
35 | 39 | | |
36 | 40 | | |
37 | | - | |
| 41 | + | |
38 | 42 | | |
39 | 43 | | |
40 | 44 | | |
| |||
45 | 49 | | |
46 | 50 | | |
47 | 51 | | |
48 | | - | |
49 | | - | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
50 | 59 | | |
51 | 60 | | |
52 | 61 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
85 | 85 | | |
86 | 86 | | |
87 | 87 | | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
88 | 171 | | |
89 | 172 | | |
90 | 173 | | |
| |||
111 | 194 | | |
112 | 195 | | |
113 | 196 | | |
| 197 | + | |
114 | 198 | | |
115 | 199 | | |
116 | 200 | | |
| 201 | + | |
117 | 202 | | |
118 | 203 | | |
119 | 204 | | |
120 | 205 | | |
| 206 | + | |
121 | 207 | | |
122 | 208 | | |
123 | 209 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
4 | | - | |
5 | 4 | | |
6 | 5 | | |
7 | 6 | | |
8 | | - | |
| 7 | + | |
| 8 | + | |
9 | 9 | | |
10 | 10 | | |
| 11 | + | |
| 12 | + | |
11 | 13 | | |
12 | 14 | | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
13 | 109 | | |
14 | 110 | | |
15 | 111 | | |
16 | 112 | | |
17 | 113 | | |
| 114 | + | |
18 | 115 | | |
19 | | - | |
20 | | - | |
21 | | - | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
22 | 119 | | |
23 | 120 | | |
24 | 121 | | |
| |||
47 | 144 | | |
48 | 145 | | |
49 | 146 | | |
50 | | - | |
51 | | - | |
| 147 | + | |
| 148 | + | |
52 | 149 | | |
53 | 150 | | |
54 | 151 | | |
55 | 152 | | |
56 | 153 | | |
57 | 154 | | |
58 | 155 | | |
| 156 | + | |
59 | 157 | | |
60 | 158 | | |
61 | 159 | | |
62 | 160 | | |
63 | 161 | | |
64 | | - | |
65 | | - | |
66 | | - | |
67 | | - | |
68 | | - | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
69 | 167 | | |
70 | 168 | | |
71 | 169 | | |
72 | | - | |
| 170 | + | |
73 | 171 | | |
74 | 172 | | |
75 | 173 | | |
| |||
81 | 179 | | |
82 | 180 | | |
83 | 181 | | |
84 | | - | |
| 182 | + | |
85 | 183 | | |
86 | 184 | | |
87 | 185 | | |
| |||
96 | 194 | | |
97 | 195 | | |
98 | 196 | | |
| 197 | + | |
99 | 198 | | |
100 | 199 | | |
101 | 200 | | |
102 | 201 | | |
103 | 202 | | |
104 | 203 | | |
105 | 204 | | |
106 | | - | |
| 205 | + | |
107 | 206 | | |
108 | | - | |
| 207 | + | |
109 | 208 | | |
110 | 209 | | |
111 | 210 | | |
112 | | - | |
| 211 | + | |
113 | 212 | | |
114 | 213 | | |
115 | 214 | | |
116 | 215 | | |
117 | 216 | | |
118 | 217 | | |
119 | 218 | | |
| 219 | + | |
120 | 220 | | |
121 | 221 | | |
122 | 222 | | |
123 | | - | |
124 | | - | |
125 | | - | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
126 | 226 | | |
127 | 227 | | |
128 | 228 | | |
0 commit comments