Rust Community · War story: Rust timezone handling almost cost us a full day of billing

944
Rsr/rust·posted by zhu_zong·3 days agoTutorial

War story: Rust timezone handling almost cost us a full day of billing

Short version: Rust 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 Rust itself but our upstream connection reuse — the load test traffic was too clean and hid the long-tail requests.

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.

Pphp.netExternal link · opens in a new tab
241 comments

241 comments

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

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

498
Rran_bo·2 days ago

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

489
Oops_wang·2 days ago

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

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

110
Bbob_chen·2 days ago

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

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

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

432
Kkite·2 days agoedited

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

403
Zzhu_zongOP·3 minutes ago

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

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

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

515
NnikicOP·just now

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

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

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

279
Kkernel_panicOP·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.

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

240
Aalice_dev·12 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.

241
Zzhou_yi·2 hours ago

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

61
Rrase·5 hours ago

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

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

224
Lli_ming·2 days ago

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

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

215
NnikicOP·12 minutes ago

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

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

80
Mmike_xu·12 minutes ago

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

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

25
Sswoole_lee·2 days ago

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

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

479
Bbob_chen·2 days ago

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

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

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

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

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.

181
Llinlin·2 days ago

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

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

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

170
Aalice_dev·2 days ago

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

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

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

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

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

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

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

87
Hhuang_ke·2 days ago

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

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

57
RraseOP·2 days ago

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

1
Rrase·2 days ago

One counter-example: below Rust 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
Aalice_dev·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.

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

105
Rrase·28 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.

88
Bbob_chen·2 hours ago

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

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

287
Sswoole_lee·28 minutes ago

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

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

257
Rrase·2 days ago

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

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

75
Ddev_zhou·3 minutes ago

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

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

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

4
Nnikic·2 days agoedited

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

61
Lli_ming·2 days ago

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

388
Kkernel_panic·2 days ago

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

20
Aalice_dev·2 days ago

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

60
Ddev_zhou·2 days ago

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

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

49
Lli_ming·2 days ago

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

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

42
Cchen_dev·2 days ago

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

36
Aalice_dev·2 days ago

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

36
Aalice_dev·2 days ago

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

67
Kkernel_panicMod·2 days agoedited

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

1
Wwinter·12 minutes ago

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

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

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

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

293
Mmike_xu·2 days ago

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

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

410
Llinlin·2 days ago

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

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

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

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

197
Kkernel_panic·2 days ago

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

2
Mmike_xu·2 hours ago

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

365
KkiteMod·2 days agoedited

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

91
Wwinter·2 days ago

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

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

48
Sswoole_lee·5 hours ago

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

6
Hhuang_ke·1 hour ago

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

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

145
Zzhou_yi·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
Ttang_haoMod·2 days ago

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

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

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

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

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

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

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

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

138
Mmike_xu·2 days ago

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

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

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

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

41
Ddev_zhou·1 hour ago

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

18
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
Kkite·28 minutes ago

One counter-example: below Rust 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
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
Ttang_haoOP·yesterday

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.

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

287
Zzhou_yi·2 days ago

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

12
Sswoole_lee·2 days agoLevel 6

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

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

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

6
Rran_bo·2 days ago

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

5
Rran_bo·2 days ago

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

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

5
Bbob_chen·2 days ago

One counter-example: below Rust 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
Rran_bo·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.

2
Nnikic·1 hour agoedited

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

2
Ttang_hao·2 days ago

One counter-example: below Rust 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

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