ESP32 · Code review · I upgraded our production esp32-review and hit these 11 landmines

543
ESr/esp32-review·posted by tang_hao·yesterdayHelp

I upgraded our production esp32-review and hit these 11 landmines

Most esp32-review articles stop at "how to use it" and never cover "when not to use it". This is an attempt at the second half.

-- The query that broke: a full scan over 20M rows.
-- A composite index took P99 from 1.8s down to 42ms.
SELECT id, title, created_at
  FROM posts
 WHERE community_id = ?
   AND status = 1
 ORDER BY score DESC
 LIMIT 20;

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.

108 comments

108 comments

M
Aalice_dev·2 days agoedited

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

493
Oops_wang·5 hours ago

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

49
Sswoole_lee·2 days ago

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

490
Ttang_hao·2 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.

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

243
LlinlinOP·2 days ago

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

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

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

241
Mmike_xuOP·2 days ago

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

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

219
Kkernel_panic·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
Aalice_dev·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.

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

204
Sswoole_lee·yesterday

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

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

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

9
Ttang_haoOP·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
Ddev_zhou·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.

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

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

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

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

157
NnikicOP·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.

82
Zzhou_yiOP·5 hours 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
Wwinter·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".

30
Sslow_query·2 days agoedited

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

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

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

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

104
Lli_ming·2 days ago

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

102
Ddev_zhou·3 minutes ago

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

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

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

393
Sslow_query·5 hours 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
Oops_wang·just now

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

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

123
Zzhu_zongOP·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".

41
Rran_bo·yesterday

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.

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

359
Ddev_zhou·2 days ago

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

314
Ttang_hao·3 minutes agoLevel 6

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.

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

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

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

81
RraseOP·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".

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

187
Rran_boOP·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.

5
Ttang_hao·3 minutes ago

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

283
Mmike_xu·just nowedited

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

197
Ttang_hao·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".

492
Lli_ming·2 days agoLevel 6

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

67
Bbob_chen·2 days ago

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

303
Mmike_xu·28 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.

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

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

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

222
Wwinter·2 hours agoLevel 6

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

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

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

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

61
Ttang_hao·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".

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

1
Kkernel_panic·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".

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

35
Nnikic·2 days agoedited

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

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

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

18
Oops_wangOPMod·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.

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

31
Kkite·2 days ago

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

115
Ddev_zhou·2 days ago

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

15
Cchen_dev·3 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.

13
Cchen_dev·2 hours 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.

97
Mmike_xuMod·yesterday

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
Sslow_query·yesterdayedited

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

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

159
Oops_wang·2 days agoLevel 6

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.

510
Nnikic·2 days agoeditedLevel 6

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.

413
Nnikic·just nowedited

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

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

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

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

211
Sslow_query·2 days ago

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

183
Sslow_queryOP·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.

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

168
Zzhu_zong·2 days ago

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

14
Kkernel_panic·just now

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

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

6
Rran_bo·2 days ago

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

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

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

366
Ddev_zhou·2 days ago

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

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

1
Nnikic·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
Hhuang_ke·2 days ago

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

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

231
Ddev_zhouMod·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.

68
Mmike_xu·just now

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.

94
Sslow_query·2 days ago

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

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

13
Zzhou_yi·yesterday

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

22
Oops_wang·5 hours 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
Hhuang_ke·2 days ago

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

328
Sswoole_lee·2 days ago

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

1
Sswoole_lee·2 days ago

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

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

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

1

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