ESP32 · Code review · The esp32-review execution flow in one diagram (with sequence chart)

993
ESr/esp32-review·posted by bob_chen·6 hours agoDiscussion

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

Short version: esp32-review needs almost no tuning at small and medium scale — the point where it starts to hurt is much further out than most people assume. Full measurements below.

Order of investigation, by return on effort: 1. Check downstream latency first — usually it is not your problem 2. Then pool hit rate and wait-queue length 3. Only then GC and allocation 4. Suspect the framework last

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

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.

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.

504 comments

504 comments

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

513
Mmike_xu·3 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.

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

509
Kkernel_panic·2 days ago

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

506
Llinlin·2 days agoedited

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

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

411
Oops_wang·3 minutes ago

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

391
Aalice_dev·2 days ago

One counter-example: below esp32-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.

65
Rrase·2 days ago

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

139
Hhuang_ke·2 days ago

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

371
Mmike_xu·12 minutes 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.

362
Lli_ming·2 days ago

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

338
Rrase·yesterday

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

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

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

122
Ddev_zhouOPMod·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.

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

290
Kkernel_panic·2 hours ago

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

278
Aalice_dev·2 days ago

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

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

424
Kkernel_panic·2 days ago

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

214
Zzhou_yiOP·2 days ago

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

127
Ttang_hao·2 days ago

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

138
Cchen_devOP·2 days ago

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

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

408
Zzhou_yi·just now

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

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

23
Kkite·1 hour agoedited

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

132
Rrase·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
Kkite·2 days ago

One counter-example: below esp32-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
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.

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

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

396
Sslow_query·2 days ago

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

132
Ddev_zhouOP·2 days ago

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

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

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

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

232
Ttang_hao·2 days agoLevel 6

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

349
Aalice_dev·2 days agoeditedLevel 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.

2
Llinlin·2 days ago

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

54
Ttang_hao·3 minutes ago

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

278
Ddev_zhouOP·2 days ago

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

168
Ttang_hao·2 days ago

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

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

225
Kkernel_panic·2 days ago

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

207
Oops_wang·2 days ago

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

204
Oops_wangMod·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.

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

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

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

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

139
Cchen_dev·2 days ago

One counter-example: below esp32-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.

378
Hhuang_keMod·2 days ago

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

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

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

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

502
Lli_ming·yesterdayedited

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.

92
Sslow_query·2 hours 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.

84
Zzhou_yiOPMod·12 minutes ago

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

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

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

2
Rran_bo·28 minutes ago

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

1
Sslow_queryOP·2 days agoLevel 6

One counter-example: below esp32-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.

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

5
WwinterOPMod·2 days agoedited

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

307
Kkernel_panicMod·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.

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

110
Hhuang_ke·yesterdayLevel 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.

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

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

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

303
Hhuang_ke·12 minutes ago

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

67
WwinterOP·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.

1
Ttang_hao·2 days ago

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

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

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

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

66
Bbob_chen·12 minutes ago

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

31
Lli_ming·yesterday

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

21
Ddev_zhou·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
Rran_bo·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.

19
Kkite·2 days ago

One counter-example: below esp32-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.

17
Bbob_chen·2 days agoedited

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

14
Ddev_zhou·5 hours 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.

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

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

4
Kkernel_panic·12 minutes ago

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

1
Ddev_zhou·12 minutes ago

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

125
Cchen_dev·12 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.

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

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

158
Mmike_xu·2 days ago

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

392
Zzhu_zong·yesterdayLevel 6

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

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

260
Cchen_dev·2 days agoLevel 6

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

12
Rran_bo·2 days ago

One counter-example: below esp32-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.

132
Nnikic·12 minutes ago

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

5
Mmike_xuOP·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.

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

181
Kkite·1 hour ago

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

1
Rrase·2 days ago

One counter-example: below esp32-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.

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

467
Kkite·12 minutes ago

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

265
Llinlin·2 days agoedited

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

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

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

222
KkiteMod·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.

43
Ttang_hao·2 days ago

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

7
Cchen_dev·2 days ago

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

32
Kkernel_panic·yesterday

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.

8
Kkite·1 hour agoLevel 6

One counter-example: below esp32-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.

362
Kkite·2 days agoLevel 6

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

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

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

64
Zzhu_zong·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.

39
Sslow_query·2 days agoeditedLevel 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.

64
Nnikic·2 days ago

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

1
Mmike_xuOP·2 days agoLevel 6

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

30
Wwinter·2 days ago

I just read the esp32-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/esp32-review/post/p0. 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 →