High Concurrency · Code review · The high-concurrency-review execution flow in one diagram (with sequence chart)

724
HCr/high-concurrency-review·posted by winter·2 days agoInternals

The high-concurrency-review execution flow in one diagram (with sequence chart)

Some background first. Our setup is high-concurrency-review plus three downstream services, seven figures of daily requests, peaking around nine in the evening.

On trade-offs, my view is this: if nobody on the team owns this area long-term, do not introduce a second mechanism. With two coexistence you first have to work out which one is even in play when things break, and that costs far more than the performance you saved.

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".

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.

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.

422 comments

422 comments

· first 120 loaded
M
Sswoole_lee·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.

462
Kkernel_panic·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.

395
Lli_ming·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.

394
Cchen_dev·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".

347
Ttang_haoOP·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.

83
Rrase·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.

332
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.

323
Sslow_query·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".

319
Oops_wangOP·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.

2
KkiteOP·2 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.

257
Cchen_devOP·3 minutes 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.

236
Rrase·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.

414
Sslow_query·2 days ago

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

384
Aalice_devMod·2 days ago

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

156
Mmike_xu·2 days ago

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

59
Sslow_query·1 hour ago

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

50
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.

252
Zzhou_yi·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".

403
Sslow_query·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.

86
Sswoole_leeMod·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.

504
Ddev_zhou·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
Kkite·2 days ago

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

36
Kkernel_panic·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.

271
Zzhou_yi·1 hour 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.

1
Llinlin·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.

225
Zzhou_yiOP·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.

124
Rran_bo·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.

180
Oops_wang·2 days ago

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

160
Cchen_dev·2 days ago

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

153
KkiteMod·2 days ago

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

120
Kkite·3 minutes ago

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

95
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.

77
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.

265
Kkite·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.

135
Aalice_dev·2 days agoedited

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.

466
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.

3
Rrase·2 days ago

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

25
Sslow_query·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.

516
Aalice_dev·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.

262
Oops_wang·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.

77
Nnikic·3 minutes ago

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

15
Wwinter·5 hours ago

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

448
Sslow_query·2 days ago

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

360
Hhuang_ke·12 minutes agoedited

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

1
Oops_wang·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.

1
Hhuang_ke·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.

24
Wwinter·12 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.

240
Kkernel_panicOP·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.

72
Wwinter·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.

98
Ttang_hao·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.

19
Zzhou_yiOP·2 hours agoedited

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

21
Nnikic·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.

19
Bbob_chen·2 hours ago

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

449
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.

1
Ddev_zhou·12 minutes agoLevel 6

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.

8
Kkite·2 hours agoedited

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.

85
Hhuang_ke·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.

446
Sslow_query·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.

333
Aalice_dev·28 minutes 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".

397
Rran_bo·12 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.

101
Sslow_query·2 days ago

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

27
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.

161
Hhuang_keOP·5 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".

33
Sswoole_lee·2 days ago

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

4
Mmike_xu·2 days agoLevel 6

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

48
Zzhu_zongOP·just now

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

1
Ddev_zhou·3 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.

515
Ddev_zhou·2 days agoLevel 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.

13
Cchen_devMod·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.

81
Sswoole_lee·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.

76
Lli_ming·yesterday

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.

68
Rran_bo·2 days agoedited

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.

193
Sswoole_lee·2 days agoedited

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

293
Aalice_dev·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.

2
Zzhou_yi·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.

255
Bbob_chen·just now

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.

275
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
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.

246
Cchen_dev·2 days ago

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

199
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.

69
Lli_ming·5 hours 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.

170
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.

68
Ddev_zhouOP·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.

1
Sslow_query·1 hour 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.

60
Bbob_chen·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.

406
Rran_bo·2 hours ago

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

60
Rrase·2 days ago

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

338
Hhuang_ke·12 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.

56
Nnikic·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.

52
Oops_wang·1 hour 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.

43
Ttang_hao·2 days agoedited

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.

32
Zzhu_zong·2 days ago

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

27
Aalice_dev·just nowedited

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.

26
Kkernel_panic·2 days ago

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

23
Cchen_dev·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.

20
Ddev_zhou·just now

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.

121
Kkite·2 days ago

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

9
Hhuang_keOP·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.

25
Kkernel_panic·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.

341
Sslow_query·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.

16
Oops_wangOP·2 days ago

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

427
Lli_ming·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.

299
Sswoole_lee·28 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.

15
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.

337
Ddev_zhou·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.

13
Hhuang_ke·2 hours agoedited

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

311
Oops_wang·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".

241
Wwinter·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".

9
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.

9
Hhuang_ke·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.

8
Sswoole_lee·2 days ago

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

1
NnikicOP·2 days ago

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

19
Rrase·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.

375
Cchen_dev·2 days ago

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

4
Bbob_chen·2 days ago

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

4
Nnikic·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.

4
Sswoole_lee·2 days agoedited

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.

2
Rrase·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.

2
Ddev_zhou·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
Ddev_zhou·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

This is the post detail page /en/c/high-concurrency-review/post/p7. 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 →