Baking · Events · Why does baking-events use twice the memory of comparable tools?

1.0K
BAr/baking-events·posted by mike_xu·5 minutes agoDiscussion

Why does baking-events use twice the memory of comparable tools?

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.

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

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.

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.

535 comments

535 comments

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

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

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

56
Oops_wang·1 hour ago

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

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

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

440
Llinlin·2 days ago

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

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

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

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

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

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

431
Cchen_dev·2 days ago

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

33
Mmike_xu·2 days ago

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

409
Rrase·2 hours ago

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

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

318
Lli_ming·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
Mmike_xu·2 days ago

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

315
Ttang_hao·just now

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

314
Bbob_chen·12 minutes ago

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

422
Sslow_query·3 minutes agoedited

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

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

127
Oops_wang·2 days ago

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

506
Lli_ming·5 hours ago

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

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

418
Lli_mingMod·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.

120
Llinlin·3 minutes ago

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

69
Sslow_query·2 hours ago

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

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

67
Zzhou_yi·2 days agoeditedLevel 6

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

2
Sswoole_lee·2 days ago

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

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

57
Bbob_chen·2 days ago

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

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

81
Lli_mingMod·2 days ago

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

277
Llinlin·5 hours ago

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

68
Aalice_dev·2 days ago

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

9
Aalice_dev·2 days ago

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

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

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

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

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

52
Sswoole_lee·2 days ago

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

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

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

10
Oops_wang·12 minutes ago

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

302
Aalice_devOP·2 days ago

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

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

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

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

2
Sslow_query·2 days ago

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

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

292
Kkernel_panic·12 minutes ago

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

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

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

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

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

221
Rrase·12 minutes ago

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

217
Oops_wangOP·2 days ago

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

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

208
Zzhu_zongOP·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.

150
Rran_boOP·yesterday

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

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

161
Kkernel_panicMod·2 days ago

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

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

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

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

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

144
Rran_bo·2 days ago

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

140
Mmike_xu·2 days ago

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

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

108
Ddev_zhou·2 days agoedited

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

284
Sswoole_lee·2 days ago

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

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

34
Wwinter·12 minutes ago

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

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

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

1
Bbob_chen·2 days ago

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

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

68
Rran_bo·2 days ago

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

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

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

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

6
Llinlin·2 days ago

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

47
Oops_wang·2 days ago

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

44
Ddev_zhou·5 hours ago

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

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

22
Sswoole_lee·5 hours ago

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

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

429
Kkernel_panic·just nowedited

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

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

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

128
Mmike_xu·1 hour agoedited

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

9
Mmike_xu·2 days ago

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

7
Rran_bo·2 hours ago

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

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

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

18
Rrase·just nowedited

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

5
Mmike_xu·2 days ago

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

450
Ddev_zhou·2 days ago

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

5
Oops_wang·2 days ago

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

4
Mmike_xu·28 minutes ago

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

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.

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

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

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

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

450
Cchen_dev·12 minutes ago

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

176
Lli_ming·12 minutes ago

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

1
Rran_boMod·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
WwinterMod·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.

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

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

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

30
Ddev_zhou·2 days ago

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

198
Kkernel_panic·2 days ago

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

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

1
Aalice_dev·2 days ago

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

387
Ddev_zhou·2 days ago

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

1

This is the post detail page /en/c/baking-events/post/p12. 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 →