High Concurrency · Code review · After reading the high-concurrency-review core source I finally understand the trade-offs

2.3K
HCr/high-concurrency-review·posted by alice_dev·just nowAnnouncement

After reading the high-concurrency-review core source I finally understand the trade-offs

It took me two weeks of on-and-off digging and plenty of wrong turns. Writing the process down as it happened so the next person spends less time.

Worth noting: the official docs do cover this, just in a very inconspicuous spot. I only found it reading the source comments, where the author explains the reasoning — roughly "so that it degrades into predictable behaviour in extreme cases".

We also fixed monitoring along the way: replaced average-based alerts with percentiles and split them per endpoint. False alerts dropped by about seventy percent and the on-call rotation visibly cheered up.

One last trap: in container environments remember to adjust the memory-related parameters in step. Otherwise the host limit and the process expectation disagree, and the symptom is intermittent, unreproducible failure.

What genuinely surprised me was the tail. The average looked great while P99 jumped by an order of magnitude past some threshold. The cause was not high-concurrency-review itself but our upstream connection reuse — the load test traffic was too clean and hid the long-tail requests.

1190 comments

1190 comments

· first 120 loaded
M
Ttang_hao·2 days ago

Can you give a minimal reproduction? I ran it locally for ten minutes and could not reproduce on macOS with the latest version.

508
Oops_wang·2 days ago

Can you give a minimal reproduction? I ran it locally for ten minutes and could not reproduce on macOS with the latest version.

161
Zzhou_yi·2 days ago

Worth learning from this debugging approach. We went straight at the logs and took a much longer route.

42
Sswoole_lee·2 days ago

I just read the high-concurrency-review source — the author actually explains the reasoning in a comment, roughly "so that it degrades into predictable behaviour in extreme cases".

488
Mmike_xu·2 days ago

One counter-example: below high-concurrency-review 7.4 the semantics of that code are different, so do not copy it verbatim. We got burned in staging and rolled back once.

71
Kkite·2 days ago

A question: what changes in a container with a 512Mi memory limit? That is how we run it in production.

342
Lli_mingMod·2 days ago

We have run this in production for two years without hitting it. That said, we never reached this scale, so our experience is not really evidence here.

456
Rran_bo·2 days ago

This is not a high-concurrency-review problem, it is a usage problem. The docs say this API is not thread-safe and you must lock around it yourself.

422
Aalice_dev·2 days ago

Thanks for sharing real numbers — far more useful than the articles that only cover concepts.

450
Ttang_hao·2 days ago

We have run this in production for two years without hitting it. That said, we never reached this scale, so our experience is not really evidence here.

439
Sswoole_lee·12 minutes ago

There is actually a simpler fix that needs no architecture change: move this check up to the gateway and the problem disappears. The cost is one extra lookup at the gateway.

425
Bbob_chen·2 days ago

Agreeing with the above. One addition: with this option enabled the GC count in your metrics doubles, so adjust the alert threshold at the same time or it will keep firing.

240
Aalice_dev·12 minutes ago

There is actually a simpler fix that needs no architecture change: move this check up to the gateway and the problem disappears. The cost is one extra lookup at the gateway.

386
Cchen_dev·2 days ago

Agreeing with the above. One addition: with this option enabled the GC count in your metrics doubles, so adjust the alert threshold at the same time or it will keep firing.

382
Zzhu_zong·3 minutes ago

Worth learning from this debugging approach. We went straight at the logs and took a much longer route.

377
Sslow_query·2 days ago

Has anyone run a controlled experiment? I did, reducing it to a single variable, and the difference was 4% — within noise. So I suspect the main cause is something else.

411
Bbob_chen·2 days ago

A question: what changes in a container with a 512Mi memory limit? That is how we run it in production.

325
Kkite·2 days ago

Has anyone run a controlled experiment? I did, reducing it to a single variable, and the difference was 4% — within noise. So I suspect the main cause is something else.

325
Lli_ming·2 days ago

A question: what changes in a container with a 512Mi memory limit? That is how we run it in production.

6
Rran_bo·3 minutes ago

Sharing our numbers, 8 cores 16GB, same scenario:

| Concurrency | P50 | P99 |
|---|---|---|
| 200 | 12ms | 88ms |
| 500 | 31ms | 340ms |

P99 clearly collapses at 500 concurrency, which lines up with your knee point.

321
Mmike_xu·2 days ago

Agreeing with the above. One addition: with this option enabled the GC count in your metrics doubles, so adjust the alert threshold at the same time or it will keep firing.

286
Wwinter·yesterdayedited

Agreeing with the above. One addition: with this option enabled the GC count in your metrics doubles, so adjust the alert threshold at the same time or it will keep firing.

231
Hhuang_ke·2 days ago

There is actually a simpler fix that needs no architecture change: move this check up to the gateway and the problem disappears. The cost is one extra lookup at the gateway.

1
Ttang_hao·2 days ago

I see point 3 differently. The trade-off depends on your read/write ratio: read-heavy with little writing means caching actually widens the inconsistency window.

210
Mmike_xu·2 days ago

I see point 3 differently. The trade-off depends on your read/write ratio: read-heavy with little writing means caching actually widens the inconsistency window.

207
Zzhu_zong·2 days agoedited

This is not a high-concurrency-review problem, it is a usage problem. The docs say this API is not thread-safe and you must lock around it yourself.

21
Bbob_chen·2 days ago

I see point 3 differently. The trade-off depends on your read/write ratio: read-heavy with little writing means caching actually widens the inconsistency window.

205
Wwinter·2 days ago

A question: what changes in a container with a 512Mi memory limit? That is how we run it in production.

205
Zzhou_yi·2 days ago

This is not a high-concurrency-review problem, it is a usage problem. The docs say this API is not thread-safe and you must lock around it yourself.

201
Ddev_zhou·2 days ago

This matches what we see in production. We only hit it past 3k QPS; the earlier load tests showed nothing — the test traffic was too clean, with no long-tail requests.

197
Ddev_zhou·2 days ago

This matches what we see in production. We only hit it past 3k QPS; the earlier load tests showed nothing — the test traffic was too clean, with no long-tail requests.

11
Lli_ming·2 days ago

Can you give a minimal reproduction? I ran it locally for ten minutes and could not reproduce on macOS with the latest version.

71
Sswoole_lee·2 days ago

Saved. I am reworking this area this week — this saves a lot of wrong turns.

188
Aalice_dev·2 days ago

I see point 3 differently. The trade-off depends on your read/write ratio: read-heavy with little writing means caching actually widens the inconsistency window.

144
Zzhou_yi·2 days ago

Saved. I am reworking this area this week — this saves a lot of wrong turns.

138
Rran_bo·2 days ago

Sharing our numbers, 8 cores 16GB, same scenario:

| Concurrency | P50 | P99 |
|---|---|---|
| 200 | 12ms | 88ms |
| 500 | 31ms | 340ms |

P99 clearly collapses at 500 concurrency, which lines up with your knee point.

133
Nnikic·12 minutes ago

Sharing our numbers, 8 cores 16GB, same scenario:

| Concurrency | P50 | P99 |
|---|---|---|
| 200 | 12ms | 88ms |
| 500 | 31ms | 340ms |

P99 clearly collapses at 500 concurrency, which lines up with your knee point.

132
Lli_ming·2 days agoedited

A question: what changes in a container with a 512Mi memory limit? That is how we run it in production.

426
Zzhu_zongOP·2 days ago

We have run this in production for two years without hitting it. That said, we never reached this scale, so our experience is not really evidence here.

1
Kkernel_panicMod·2 hours ago

I just read the high-concurrency-review source — the author actually explains the reasoning in a comment, roughly "so that it degrades into predictable behaviour in extreme cases".

4
Ttang_hao·2 days ago

This is not a high-concurrency-review problem, it is a usage problem. The docs say this API is not thread-safe and you must lock around it yourself.

127
Zzhu_zongOP·3 minutes ago

Saved. I am reworking this area this week — this saves a lot of wrong turns.

41
KkiteMod·2 days ago

I just read the high-concurrency-review source — the author actually explains the reasoning in a comment, roughly "so that it degrades into predictable behaviour in extreme cases".

92
Zzhou_yi·2 days agoedited

I see point 3 differently. The trade-off depends on your read/write ratio: read-heavy with little writing means caching actually widens the inconsistency window.

75
Mmike_xu·2 days ago

One counter-example: below high-concurrency-review 7.4 the semantics of that code are different, so do not copy it verbatim. We got burned in staging and rolled back once.

125
Kkernel_panicMod·2 days ago

Sharing our numbers, 8 cores 16GB, same scenario:

| Concurrency | P50 | P99 |
|---|---|---|
| 200 | 12ms | 88ms |
| 500 | 31ms | 340ms |

P99 clearly collapses at 500 concurrency, which lines up with your knee point.

268
Rrase·just nowedited

Thanks for sharing real numbers — far more useful than the articles that only cover concepts.

29
Cchen_dev·2 days agoedited

Worth learning from this debugging approach. We went straight at the logs and took a much longer route.

334
Lli_mingMod·2 days ago

This matches what we see in production. We only hit it past 3k QPS; the earlier load tests showed nothing — the test traffic was too clean, with no long-tail requests.

343
Zzhou_yi·just now

Thanks for sharing real numbers — far more useful than the articles that only cover concepts.

53
Sslow_query·1 hour agoLevel 6

There is actually a simpler fix that needs no architecture change: move this check up to the gateway and the problem disappears. The cost is one extra lookup at the gateway.

139
Sslow_queryOP·2 days ago

This is not a high-concurrency-review problem, it is a usage problem. The docs say this API is not thread-safe and you must lock around it yourself.

6
Ttang_hao·28 minutes ago

We have run this in production for two years without hitting it. That said, we never reached this scale, so our experience is not really evidence here.

32
Rrase·yesterday

Sharing our numbers, 8 cores 16GB, same scenario:

| Concurrency | P50 | P99 |
|---|---|---|
| 200 | 12ms | 88ms |
| 500 | 31ms | 340ms |

P99 clearly collapses at 500 concurrency, which lines up with your knee point.

137
Nnikic·2 days ago

Can you give a minimal reproduction? I ran it locally for ten minutes and could not reproduce on macOS with the latest version.

158
Kkernel_panic·5 hours ago

Worth learning from this debugging approach. We went straight at the logs and took a much longer route.

27
Mmike_xu·2 days ago

Agreeing with the above. One addition: with this option enabled the GC count in your metrics doubles, so adjust the alert threshold at the same time or it will keep firing.

245
Sslow_query·2 days ago

One counter-example: below high-concurrency-review 7.4 the semantics of that code are different, so do not copy it verbatim. We got burned in staging and rolled back once.

138
Sswoole_lee·5 hours ago

One counter-example: below high-concurrency-review 7.4 the semantics of that code are different, so do not copy it verbatim. We got burned in staging and rolled back once.

86
Kkernel_panic·2 days ago

Agreeing with the above. One addition: with this option enabled the GC count in your metrics doubles, so adjust the alert threshold at the same time or it will keep firing.

12
Ddev_zhou·28 minutes agoLevel 6

One counter-example: below high-concurrency-review 7.4 the semantics of that code are different, so do not copy it verbatim. We got burned in staging and rolled back once.

208
Kkite·2 days ago

I see point 3 differently. The trade-off depends on your read/write ratio: read-heavy with little writing means caching actually widens the inconsistency window.

1
Sswoole_lee·2 days ago

We have run this in production for two years without hitting it. That said, we never reached this scale, so our experience is not really evidence here.

75
Mmike_xu·yesterday

This is not a high-concurrency-review problem, it is a usage problem. The docs say this API is not thread-safe and you must lock around it yourself.

35
Bbob_chen·2 days agoedited

Has anyone run a controlled experiment? I did, reducing it to a single variable, and the difference was 4% — within noise. So I suspect the main cause is something else.

425
Nnikic·1 hour ago

Saved. I am reworking this area this week — this saves a lot of wrong turns.

128
Rran_bo·2 days ago

Worth learning from this debugging approach. We went straight at the logs and took a much longer route.

322
Hhuang_ke·2 days agoLevel 6

We have run this in production for two years without hitting it. That said, we never reached this scale, so our experience is not really evidence here.

327
Kkite·2 days agoLevel 6

There is actually a simpler fix that needs no architecture change: move this check up to the gateway and the problem disappears. The cost is one extra lookup at the gateway.

15
Nnikic·2 days ago

A question: what changes in a container with a 512Mi memory limit? That is how we run it in production.

4
Mmike_xu·just nowedited

I see point 3 differently. The trade-off depends on your read/write ratio: read-heavy with little writing means caching actually widens the inconsistency window.

17
Mmike_xu·2 days ago

We have run this in production for two years without hitting it. That said, we never reached this scale, so our experience is not really evidence here.

92
LlinlinOP·28 minutes ago

This matches what we see in production. We only hit it past 3k QPS; the earlier load tests showed nothing — the test traffic was too clean, with no long-tail requests.

9
Kkernel_panicOP·28 minutes ago

One counter-example: below high-concurrency-review 7.4 the semantics of that code are different, so do not copy it verbatim. We got burned in staging and rolled back once.

458
Rrase·yesterday

We have run this in production for two years without hitting it. That said, we never reached this scale, so our experience is not really evidence here.

24
NnikicOP·2 days agoLevel 6

Sharing our numbers, 8 cores 16GB, same scenario:

| Concurrency | P50 | P99 |
|---|---|---|
| 200 | 12ms | 88ms |
| 500 | 31ms | 340ms |

P99 clearly collapses at 500 concurrency, which lines up with your knee point.

96
Rran_bo·2 days agoeditedLevel 6

I see point 3 differently. The trade-off depends on your read/write ratio: read-heavy with little writing means caching actually widens the inconsistency window.

29
Zzhou_yiMod·2 days agoedited

This is not a high-concurrency-review problem, it is a usage problem. The docs say this API is not thread-safe and you must lock around it yourself.

1
Lli_ming·12 minutes agoLevel 6

Thanks for sharing real numbers — far more useful than the articles that only cover concepts.

289
WwinterOP·2 days ago

I just read the high-concurrency-review source — the author actually explains the reasoning in a comment, roughly "so that it degrades into predictable behaviour in extreme cases".

4
Nnikic·2 days ago

Worth learning from this debugging approach. We went straight at the logs and took a much longer route.

138
Aalice_dev·2 days agoLevel 6

I just read the high-concurrency-review source — the author actually explains the reasoning in a comment, roughly "so that it degrades into predictable behaviour in extreme cases".

1
Sslow_query·2 days ago

This matches what we see in production. We only hit it past 3k QPS; the earlier load tests showed nothing — the test traffic was too clean, with no long-tail requests.

29
Hhuang_ke·2 days agoLevel 6

Saved. I am reworking this area this week — this saves a lot of wrong turns.

247
Aalice_dev·2 days agoLevel 6

This matches what we see in production. We only hit it past 3k QPS; the earlier load tests showed nothing — the test traffic was too clean, with no long-tail requests.

13
Kkite·2 days ago

Has anyone run a controlled experiment? I did, reducing it to a single variable, and the difference was 4% — within noise. So I suspect the main cause is something else.

54
Lli_ming·2 days ago

Has anyone run a controlled experiment? I did, reducing it to a single variable, and the difference was 4% — within noise. So I suspect the main cause is something else.

22
Sslow_query·2 days agoedited

Thanks for sharing real numbers — far more useful than the articles that only cover concepts.

247
Oops_wang·2 hours ago

Agreeing with the above. One addition: with this option enabled the GC count in your metrics doubles, so adjust the alert threshold at the same time or it will keep firing.

2
Ddev_zhou·5 hours ago

A question: what changes in a container with a 512Mi memory limit? That is how we run it in production.

98
Aalice_dev·28 minutes ago

This is not a high-concurrency-review problem, it is a usage problem. The docs say this API is not thread-safe and you must lock around it yourself.

43
Cchen_devOP·2 days ago

Has anyone run a controlled experiment? I did, reducing it to a single variable, and the difference was 4% — within noise. So I suspect the main cause is something else.

324
Ttang_hao·2 days agoLevel 6

I just read the high-concurrency-review source — the author actually explains the reasoning in a comment, roughly "so that it degrades into predictable behaviour in extreme cases".

440
Sslow_query·2 days agoLevel 6

Saved. I am reworking this area this week — this saves a lot of wrong turns.

322
LlinlinMod·2 days ago

There is actually a simpler fix that needs no architecture change: move this check up to the gateway and the problem disappears. The cost is one extra lookup at the gateway.

297
Kkernel_panic·2 days ago

Can you give a minimal reproduction? I ran it locally for ten minutes and could not reproduce on macOS with the latest version.

1
Ttang_hao·yesterday

Thanks for sharing real numbers — far more useful than the articles that only cover concepts.

19
Nnikic·2 days ago

Saved. I am reworking this area this week — this saves a lot of wrong turns.

21
Zzhu_zong·2 days ago

I see point 3 differently. The trade-off depends on your read/write ratio: read-heavy with little writing means caching actually widens the inconsistency window.

23
Zzhou_yiMod·2 days ago

Thanks for sharing real numbers — far more useful than the articles that only cover concepts.

349
Nnikic·5 hours ago

This matches what we see in production. We only hit it past 3k QPS; the earlier load tests showed nothing — the test traffic was too clean, with no long-tail requests.

237
Lli_ming·3 minutes ago

Can you give a minimal reproduction? I ran it locally for ten minutes and could not reproduce on macOS with the latest version.

18
Cchen_dev·2 days ago

There is actually a simpler fix that needs no architecture change: move this check up to the gateway and the problem disappears. The cost is one extra lookup at the gateway.

420
Lli_ming·2 days ago

Has anyone run a controlled experiment? I did, reducing it to a single variable, and the difference was 4% — within noise. So I suspect the main cause is something else.

171
Aalice_dev·2 days ago

One counter-example: below high-concurrency-review 7.4 the semantics of that code are different, so do not copy it verbatim. We got burned in staging and rolled back once.

480
Aalice_dev·2 days ago

One counter-example: below high-concurrency-review 7.4 the semantics of that code are different, so do not copy it verbatim. We got burned in staging and rolled back once.

417
Sswoole_lee·2 days ago

I just read the high-concurrency-review source — the author actually explains the reasoning in a comment, roughly "so that it degrades into predictable behaviour in extreme cases".

165
Sslow_query·2 days ago

Sharing our numbers, 8 cores 16GB, same scenario:

| Concurrency | P50 | P99 |
|---|---|---|
| 200 | 12ms | 88ms |
| 500 | 31ms | 340ms |

P99 clearly collapses at 500 concurrency, which lines up with your knee point.

69
Sslow_queryMod·2 days agoLevel 6

Saved. I am reworking this area this week — this saves a lot of wrong turns.

183
Sslow_query·2 days agoeditedLevel 6

Agreeing with the above. One addition: with this option enabled the GC count in your metrics doubles, so adjust the alert threshold at the same time or it will keep firing.

1
Sslow_query·2 days ago

There is actually a simpler fix that needs no architecture change: move this check up to the gateway and the problem disappears. The cost is one extra lookup at the gateway.

149
Sswoole_lee·2 days ago

A question: what changes in a container with a 512Mi memory limit? That is how we run it in production.

32
Cchen_dev·2 days ago

Thanks for sharing real numbers — far more useful than the articles that only cover concepts.

8
Bbob_chen·28 minutes ago

Can you give a minimal reproduction? I ran it locally for ten minutes and could not reproduce on macOS with the latest version.

2
Sswoole_lee·2 days agoedited

This matches what we see in production. We only hit it past 3k QPS; the earlier load tests showed nothing — the test traffic was too clean, with no long-tail requests.

225
Lli_ming·2 days ago

Worth learning from this debugging approach. We went straight at the logs and took a much longer route.

1
Zzhou_yi·12 minutes ago

Can you give a minimal reproduction? I ran it locally for ten minutes and could not reproduce on macOS with the latest version.

1
Nnikic·2 days ago

Worth learning from this debugging approach. We went straight at the logs and took a much longer route.

1
Sslow_query·5 hours ago

Sharing our numbers, 8 cores 16GB, same scenario:

| Concurrency | P50 | P99 |
|---|---|---|
| 200 | 12ms | 88ms |
| 500 | 31ms | 340ms |

P99 clearly collapses at 500 concurrency, which lines up with your knee point.

1
Mmike_xu·2 days ago

I just read the high-concurrency-review source — the author actually explains the reasoning in a comment, roughly "so that it degrades into predictable behaviour in extreme cases".

1

This is the post detail page /en/c/high-concurrency-review/post/p5. Posts and comments are generated deterministically from a seeded PRNG, so the same post always renders the same content and the link can be shared, reloaded and indexed. In production this page reads MySQL for the post, Redis for hot-post caching, and fetches the whole comment tree in a single query on the path column.

See the database schema →