NixOS · Toolchain · Six rules for error handling in nixos-tools that I settled on

470
NIr/nixos-tools·posted by bob_chen·yesterdayInternals

Six rules for error handling in nixos-tools that I settled on

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

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.

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.

Sstackoverflow.comExternal link · opens in a new tab
164 comments

164 comments

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

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

517
Rrase·2 days agoedited

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

513
Ddev_zhou·5 hours 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.

507
Nnikic·2 days agoedited

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

492
Rrase·just nowedited

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.

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

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

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

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

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

492
Cchen_dev·2 days ago

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

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

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

435
Mmike_xu·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".

112
Ddev_zhou·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".

432
Wwinter·just now

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.

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

471
Rrase·just now

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.

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

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

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

369
Ttang_hao·2 days ago

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

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

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

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

296
Mmike_xuOP·5 hours 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.

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

162
Ttang_hao·2 days ago

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

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

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

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

215
Kkite·5 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.

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

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

19
Oops_wang·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".

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

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

48
Wwinter·3 minutes ago

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

7
Sswoole_lee·2 days ago

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

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

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

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

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

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

127
RraseOPMod·2 days ago

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

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

277
Zzhou_yi·2 days ago

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

391
Rran_bo·3 minutes ago

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

148
Rran_bo·28 minutes ago

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

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

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

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

351
Nnikic·2 days ago

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

443
Ddev_zhou·2 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.

57
Bbob_chen·2 days agoLevel 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.

332
Kkernel_panic·28 minutes agoLevel 6

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

5
Zzhou_yi·2 days ago

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

81
Ddev_zhou·28 minutes agoedited

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.

68
Mmike_xuOP·2 days agoedited

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

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

61
Zzhu_zongMod·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·yesterdayLevel 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.

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

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

66
Rran_bo·2 days agoLevel 6

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

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

6
Bbob_chenOP·2 days ago

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

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

1
Zzhu_zong·2 days ago

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

2
Wwinter·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
Ddev_zhou·yesterday

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

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

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

112
Oops_wangMod·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.

111
Sswoole_lee·5 hours ago

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

121
Oops_wang·28 minutes ago

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

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

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

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

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

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

88
Rrase·2 days ago

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

80
Lli_ming·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
Kkite·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.

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

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

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

481
Ddev_zhou·2 days agoedited

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

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

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

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

47
NnikicOP·2 days ago

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

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

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

458
Kkernel_panicMod·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.

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

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

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

40
Ddev_zhou·12 minutes 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.

15
Ddev_zhouOP·2 days agoedited

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

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

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

19
KkiteOP·2 days ago

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

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

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

9
Nnikic·12 minutes ago

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

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

47
Sslow_query·2 days agoedited

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

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

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

373
Zzhu_zongOP·2 days ago

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

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

2
Sswoole_lee·2 days agoedited

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

25
Nnikic·3 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".

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

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

87
Oops_wang·2 days agoedited

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

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

84

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