Kafka · English · Why does kafka-en use twice the memory of comparable tools?

1.7K
KAr/kafka-en·posted by swoole_lee·yesterdayDiscussion

Why does kafka-en use twice the memory of comparable tools?

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

The first thing was to collapse the variables. We were changing config and upgrading the version at the same time, and afterwards nobody could say which change caused what. We rolled back to moving one variable at a time, re-ran three times, and only then did the curve settle. Tedious, but not skippable.

Image placeholder · object storage in production
POST /api/uploads → CDN origin pull
555 comments

555 comments

· first 120 loaded
M
Ttang_hao·2 hours ago

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

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

10
Sswoole_lee·2 days ago

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

271
Sswoole_lee·just now

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.

418
Aalice_dev·2 days ago

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

414
Mmike_xu·2 days ago

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

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

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

73
Hhuang_keOP·2 days ago

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

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

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

2
Bbob_chen·12 minutes 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.

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

392
Sswoole_lee·2 days ago

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

378
NnikicMod·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.

366
Bbob_chen·2 days ago

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

362
Mmike_xu·2 days ago

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

351
Zzhou_yi·2 days ago

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

330
Rran_bo·2 days ago

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

320
Nnikic·2 days ago

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

316
Lli_ming·2 days ago

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

313
WwinterMod·2 days ago

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

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

293
Wwinter·1 hour ago

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

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

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

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

225
Zzhou_yi·28 minutes ago

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

166
Ddev_zhou·2 days ago

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

508
LlinlinOP·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.

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

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

62
Lli_ming·5 hours agoLevel 6

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

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

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

6
Kkite·3 minutes ago

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

18
Hhuang_ke·2 days ago

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

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

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

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

69
Bbob_chen·1 hour ago

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

276
Kkernel_panic·2 days agoLevel 6

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

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

8
Llinlin·2 days agoeditedLevel 6

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

1
Lli_ming·just now

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

54
Bbob_chen·yesterday

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

411
Aalice_dev·2 days agoeditedLevel 6

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

189
Sslow_queryOP·yesterdayeditedLevel 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.

8
Aalice_dev·2 hours ago

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

39
Sslow_queryOP·2 days ago

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

318
Lli_ming·yesterdayLevel 6

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

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

17
Lli_ming·2 days ago

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

40
Sswoole_lee·2 days agoeditedLevel 6

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

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

5
Kkite·2 days ago

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

1
Cchen_devOP·just now

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

217
Rrase·2 days ago

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

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

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

134
Oops_wang·28 minutes agoedited

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

55
Hhuang_ke·2 days ago

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

38
Ttang_hao·12 minutes 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.

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

254
Kkite·2 days ago

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

178
Kkite·2 days ago

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

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

247
Sslow_query·yesterday

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

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

197
Wwinter·2 hours ago

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

169
Oops_wang·2 days ago

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

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

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

43
Mmike_xu·2 days agoedited

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

41
Wwinter·2 days ago

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

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

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

202
Zzhu_zongOP·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
Kkernel_panicOP·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.

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

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

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

59
Llinlin·2 days ago

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

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

89
Ddev_zhou·2 days agoedited

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

325
Kkernel_panic·2 days ago

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

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

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

73
Cchen_dev·2 days ago

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

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

57
Sswoole_lee·5 hours ago

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

29
Llinlin·2 days ago

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

28
RraseMod·1 hour ago

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

26
Sswoole_leeOP·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.

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

383
Oops_wang·2 days ago

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

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

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

236
Rran_bo·just now

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

23
Hhuang_ke·2 days ago

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

185
Ttang_hao·2 days ago

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

86
Kkernel_panic·2 days ago

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

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

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

3
Lli_ming·1 hour ago

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

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

86
Ttang_hao·2 days ago

One counter-example: below kafka-en 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
Ddev_zhouOP·2 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.

411
Wwinter·2 days ago

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

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

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

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

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

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

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

1
Lli_ming·2 days ago

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

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

1

This is the post detail page /en/c/kafka-en/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 →