Clean Architecture · Chinese · Why does clean-architecture-zh use twice the memory of comparable tools?

2.3K
CAr/clean-architecture-zh·posted by chen_dev·5 minutes agoAnnouncement

Why does clean-architecture-zh use twice the memory of comparable tools?

Short version: clean-architecture-zh 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.

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

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.

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.

1009 comments

1009 comments

· first 120 loaded
M
LlinlinMod·just nowedited

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

475
Wwinter·2 days ago

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

161
Nnikic·2 days ago

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

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

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

389
Llinlin·2 days ago

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

381
Sslow_query·2 days agoedited

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

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

368
Llinlin·2 days ago

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

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

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

394
Hhuang_ke·2 days agoedited

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

105
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
Zzhu_zong·2 hours ago

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

277
Rrase·2 days ago

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

4
Llinlin·2 days agoedited

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

259
Nnikic·2 hours ago

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

234
Zzhou_yi·2 days ago

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

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

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

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

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

179
Zzhu_zong·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
RraseOPMod·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.

144
Wwinter·2 hours ago

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

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

169
Ddev_zhou·2 days ago

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

159
Zzhu_zong·2 days ago

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

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

75
Cchen_dev·1 hour ago

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

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

121
Cchen_dev·28 minutes ago

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

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

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

180
Zzhu_zong·2 days ago

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

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

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

372
Sswoole_lee·2 days agoedited

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

82
Kkite·12 minutes ago

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

79
Rrase·2 hours ago

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

13
Cchen_dev·2 days ago

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

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

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

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

171
Cchen_dev·2 days ago

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

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

8
Wwinter·2 days ago

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

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

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

5
Wwinter·2 days ago

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

513
Zzhu_zongMod·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.

137
Rrase·2 hours ago

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

26
Ttang_hao·2 days ago

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

84
Ttang_hao·2 days ago

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

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

1
Kkite·12 minutes ago

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

56
Lli_ming·12 minutes ago

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

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

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

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

4
Kkernel_panic·just now

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

96
WwinterMod·just now

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.

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

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

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

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

177
Ddev_zhou·2 days agoLevel 6

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

94
Kkite·28 minutes ago

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

27
Nnikic·2 days ago

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

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

185
Ddev_zhou·2 days ago

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

206
Zzhu_zong·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
Lli_ming·2 days ago

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

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

453
Oops_wang·2 days agoLevel 6

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

281
Kkite·5 hours ago

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

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

5
Wwinter·2 days ago

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

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

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

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

25
Ttang_hao·1 hour ago

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

32
Sslow_query·2 days ago

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

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

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

18
Llinlin·2 days ago

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

16
Rran_bo·2 days ago

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

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

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

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

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

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

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

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

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

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

203
Bbob_chen·2 days ago

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

59
Aalice_dev·2 days ago

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

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

7
Zzhou_yi·2 days ago

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

99
LlinlinMod·12 minutes ago

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

285
Aalice_dev·2 days agoedited

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

329
Lli_ming·just now

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

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

2
Oops_wang·2 hours 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 hours ago

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

282
Kkernel_panic·2 days ago

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

449
Sswoole_lee·28 minutes ago

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

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

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

81
Cchen_dev·2 days agoLevel 6

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

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

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

48
Aalice_devOP·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
Ttang_hao·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

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

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

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

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

1

This is the post detail page /en/c/clean-architecture-zh/post/p8. 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 →