NixOS · Toolchain · I built a small tool with nixos-tools — code is open, feedback welcome

998
NIr/nixos-tools·posted by bob_chen·3 hours agoTranslation

I built a small tool with nixos-tools — code is open, feedback welcome

Short version: nixos-tools 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.

What genuinely surprised me was the tail. The average looked great while P99 jumped by an order of magnitude past some threshold. The cause was not nixos-tools itself but our upstream connection reuse — the load test traffic was too clean and hid the long-tail requests.

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

Bblog.vuejs.orgExternal link · opens in a new tab
142 comments

142 comments

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

493
Kkite·2 days ago

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

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

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

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

76
Mmike_xu·just nowedited

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

56
Llinlin·2 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.

423
Aalice_dev·1 hour 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
Zzhu_zong·just now

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.

461
Bbob_chenOP·2 days agoLevel 6

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.

390
Mmike_xu·2 days agoLevel 6

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.

376
Oops_wangOP·2 days agoLevel 6

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

247
Cchen_devMod·1 hour agoLevel 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.

253
Kkite·2 days agoLevel 6

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

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

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

300
Zzhu_zongOP·2 days agoLevel 6

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

106
Oops_wang·28 minutes agoeditedLevel 6

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

45
Llinlin·just noweditedLevel 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.

1
Zzhu_zongOP·1 hour ago

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

124
Cchen_dev·yesterdayLevel 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.

86
Rrase·2 days agoLevel 6

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.

63
Rran_bo·28 minutes agoLevel 6

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

21
Oops_wang·2 days agoLevel 6

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

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

44
Rran_boMod·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.

93
Hhuang_ke·12 minutes ago

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

75
Llinlin·1 hour ago

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

386
Aalice_dev·2 days agoeditedLevel 6

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

108
Bbob_chen·12 minutes agoedited

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

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

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

294
Hhuang_ke·2 days agoedited

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

276
Wwinter·just now

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

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

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

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

418
Mmike_xu·2 days ago

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

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

36
Ddev_zhou·2 days ago

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

403
KkiteOP·2 days ago

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

312
Rrase·2 days ago

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

352
Ddev_zhouOP·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.

284
Kkite·28 minutes ago

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

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

344
Llinlin·5 hours ago

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

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

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

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

326
Aalice_dev·just now

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

338
Cchen_dev·2 days ago

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

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

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

311
Kkernel_panic·2 days ago

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

127
Hhuang_ke·2 days agoedited

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

301
Sslow_query·2 days ago

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

301
Lli_ming·2 days ago

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

271
Cchen_devMod·2 days ago

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

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

259
Lli_ming·2 days ago

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

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

250
RraseOP·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.

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

252
Kkite·2 days ago

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

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

326
LlinlinMod·3 minutes ago

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

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

220
Cchen_dev·2 days ago

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

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

2
Wwinter·2 days ago

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

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

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

127
Rran_boMod·2 days ago

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

123
Rran_bo·1 hour ago

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

113
Wwinter·2 days ago

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

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

520
Sswoole_lee·2 days ago

One counter-example: below nixos-tools 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
Rrase·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.

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

83
Lli_ming·2 days ago

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

283
Sswoole_leeOP·2 days ago

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

6
Ddev_zhouOP·2 days ago

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

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

58
Bbob_chen·just nowedited

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.

55
Ddev_zhou·2 days ago

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

32
Zzhu_zongMod·2 days ago

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

1
Hhuang_ke·5 hours agoedited

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

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

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

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

20
Rrase·2 days ago

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

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

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

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

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

197
RraseOP·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.

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

59
Kkite·2 hours 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.

55
Ttang_hao·2 days agoedited

One counter-example: below nixos-tools 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
Sslow_query·2 days agoedited

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

21
Oops_wang·2 days ago

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

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

357
Hhuang_ke·2 days ago

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

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

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

47
Nnikic·2 days ago

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

41
Wwinter·2 days ago

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

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

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

139
Cchen_dev·2 days ago

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

31
Bbob_chen·2 days ago

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

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

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

8
Llinlin·12 minutes ago

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

7
Cchen_dev·yesterday

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

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

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

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

1

This is the post detail page /en/c/nixos-tools/post/p1. 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 →