Linux Community · Six rules for error handling in linux that I settled on

825
LIr/linux·posted by tang_hao·2 days agoTutorial

Six rules for error handling in linux that I settled on

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.

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.

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

Ddeveloper.mozilla.orgExternal link · opens in a new tab
317 comments

317 comments

· first 120 loaded
M
Zzhou_yi·yesterday

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

501
Rrase·2 days ago

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

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

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

498
Wwinter·2 days ago

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

496
Hhuang_ke·2 hours ago

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

487
Wwinter·2 days ago

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

474
LlinlinOP·2 days ago

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

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

179
Cchen_dev·2 days ago

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

54
Sswoole_lee·2 days ago

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

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

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

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

438
Kkite·2 days ago

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

433
Nnikic·2 days ago

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

34
Aalice_dev·2 days ago

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

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

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

328
Lli_ming·2 days ago

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

26
Sswoole_lee·1 hour ago

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

283
Cchen_dev·2 days ago

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

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

222
Wwinter·2 hours ago

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

347
Wwinter·2 days ago

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

1
Nnikic·28 minutes ago

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

220
Rrase·2 days ago

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

191
Sswoole_lee·2 days ago

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

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

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

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

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

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

320
Sswoole_lee·2 days ago

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

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

127
Ttang_hao·3 minutes agoedited

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

111
Rran_bo·28 minutes ago

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

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

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

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

118
WwinterOP·yesterday

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

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

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

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

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

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

15
Sslow_query·5 hours 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

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.

244
KkiteOP·2 days ago

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

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

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

249
Ttang_hao·2 days ago

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

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

37
Sswoole_lee·2 hours ago

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

186
Oops_wang·2 days ago

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

3
Bbob_chen·2 days ago

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

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

431
NnikicOP·2 days ago

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

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

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

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

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

26
Lli_ming·2 days ago

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

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

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

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

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

36
Bbob_chen·2 days ago

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

295
Hhuang_keOP·2 days agoLevel 6

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

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

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

12
Kkernel_panic·2 days ago

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

222
Wwinter·2 days ago

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

75
Lli_ming·12 minutes agoLevel 6

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

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

1
Mmike_xu·2 hours agoLevel 6

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

293
Bbob_chen·28 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.

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

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

14
Rran_bo·2 days ago

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

4
Wwinter·2 days ago

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

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

3
Zzhu_zong·3 minutes ago

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

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

1
Sswoole_lee·3 minutes ago

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

381
Sslow_query·3 minutes ago

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

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

449
Ddev_zhou·2 hours agoLevel 6

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

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

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

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

83
Kkernel_panic·2 days agoLevel 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.

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

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

249
Zzhu_zong·1 hour ago

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

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

60
NnikicOP·28 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.

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

256
Wwinter·28 minutes ago

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

1
Aalice_dev·yesterday

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

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

345
Oops_wang·2 days agoedited

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

208
Cchen_dev·2 days ago

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

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

14
Lli_ming·2 days ago

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

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

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

11
Hhuang_ke·2 days agoeditedLevel 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.

8
Kkite·1 hour agoedited

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

279
Bbob_chen·2 days ago

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

110
LlinlinOP·28 minutes ago

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

1
Rran_bo·12 minutes ago

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

240
LlinlinOP·2 days ago

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

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

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

1
Wwinter·2 days ago

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

1
Rrase·2 days ago

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

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

121

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