Commit 98f8d66
perf(cache): migrate H22 cache async commits to virtual threads (#35992)
## Proposed Changes
Migrates the **H22 cache async commit executor** from a fixed pool of 5
platform threads to **virtual threads**.
Async cache writes (`put`/`remove` against the embedded H2 store) are
I/O-bound, so they're a natural fit for virtual threads now that we're
on Java 25 — **JEP 491** means `synchronized` blocks in Hikari/H2 no
longer pin the carrier thread, so the classic "virtual threads + JDBC
pinning" concern does not apply.
### What changed (`H22Cache.java`)
- `spawnNewThreadPool()` now returns
`Executors.newThreadPerTaskExecutor(...)` with a named virtual-thread
factory (`H22-ASYNC-COMMIT-*`). Removed the Guava
`ThreadFactoryBuilder`, `ThreadPoolExecutor`, and `LinkedBlockingQueue`.
- A shared `submitAsync(Runnable)` helper now backs both `putAsync` and
`removeAsync`.
### Behavior preserved (not a behavior change)
| Concern | How it's handled |
|---|---|
| **Backpressure** | The real backpressure was always the up-front
`shouldAsync()` check, which falls back to a **synchronous commit on the
caller**. Unchanged. The old `CallerRunsPolicy` was effectively dead
code — the unbounded queue never rejected. |
| **Backlog metric** | A virtual-thread-per-task executor has no shared
queue, so `isAllocationWithinTolerance()` now reads an `AtomicInteger`
in-flight counter instead of `asyncTaskQueue.size()`. Same semantics;
the `@Ignore`d `H22CacheTest` still compiles. |
| **DB concurrency** | A `Semaphore` (sized by the existing
`cache_h22_async_threads` knob, default 5) acquired **inside** each task
caps how many commits hit the Hikari pool at once — preventing
connection-timeout storms and spurious shard rebuilds under burst load.
Virtual threads block cheaply on the semaphore. |
| **Shutdown** | In-flight counter is balanced on
`RejectedExecutionException` at shutdown; executor shutdown path
unchanged. |
The obsolete `cache.h22.async.caller.runs.policy` config is no longer
read.
## This fixes / relates to
Part of #35991 (Java 25 Performance Improvements) — first child PR.
## Testing
- `./mvnw compile -pl :dotcms-core` → **BUILD SUCCESS**.
- No integration suite run locally (per repo guidance). Reviewer note:
worth a sanity run of `H22CacheTest` and a write-heavy cache smoke test.
## Checklist
- [x] Compiles (`BUILD SUCCESS`)
- [x] No public API / behavior change intended
- [ ] Reviewer to confirm cache behavior under load
🤖 Generated with [Claude Code](https://claude.com/claude-code)
---------
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-authored-by: Scott Wicken <1562170+swicken@users.noreply.github.com>1 parent d27c1aa commit 98f8d66
1 file changed
Lines changed: 47 additions & 21 deletions
Lines changed: 47 additions & 21 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
14 | | - | |
15 | 14 | | |
16 | 15 | | |
17 | 16 | | |
| |||
34 | 33 | | |
35 | 34 | | |
36 | 35 | | |
37 | | - | |
| 36 | + | |
| 37 | + | |
38 | 38 | | |
39 | 39 | | |
40 | | - | |
41 | 40 | | |
42 | 41 | | |
| 42 | + | |
43 | 43 | | |
44 | 44 | | |
45 | 45 | | |
| |||
53 | 53 | | |
54 | 54 | | |
55 | 55 | | |
56 | | - | |
57 | | - | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
58 | 63 | | |
59 | 64 | | |
60 | 65 | | |
| |||
115 | 120 | | |
116 | 121 | | |
117 | 122 | | |
118 | | - | |
119 | | - | |
120 | | - | |
121 | | - | |
122 | | - | |
123 | | - | |
124 | | - | |
125 | | - | |
126 | | - | |
127 | | - | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
128 | 127 | | |
129 | 128 | | |
130 | 129 | | |
| |||
183 | 182 | | |
184 | 183 | | |
185 | 184 | | |
186 | | - | |
187 | | - | |
| 185 | + | |
188 | 186 | | |
189 | 187 | | |
190 | 188 | | |
191 | 189 | | |
192 | 190 | | |
193 | 191 | | |
194 | | - | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
195 | 222 | | |
196 | 223 | | |
197 | 224 | | |
| |||
291 | 318 | | |
292 | 319 | | |
293 | 320 | | |
294 | | - | |
| 321 | + | |
295 | 322 | | |
296 | 323 | | |
297 | 324 | | |
| |||
309 | 336 | | |
310 | 337 | | |
311 | 338 | | |
312 | | - | |
313 | | - | |
| 339 | + | |
314 | 340 | | |
315 | 341 | | |
316 | 342 | | |
| |||
0 commit comments