Rust Community · Those easily-missed type details in Rust

292
Rsr/rust·posted by bob_chen·1 hour agoTranslation

Those easily-missed type details in Rust

Most Rust articles stop at "how to use it" and never cover "when not to use it". This is an attempt at the second half.

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.

Image placeholder · object storage in production
POST /api/uploads → CDN origin pull
134 comments

134 comments

· first 120 loaded
M
Bbob_chenOP·2 days ago

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

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

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

8
Mmike_xu·5 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.

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

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

41
Oops_wang·2 days agoedited

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

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

19
LlinlinOP·1 hour 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.

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

312
Kkite·2 days ago

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

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

307
Ddev_zhou·5 hours ago

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

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

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

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

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

267
Aalice_dev·2 days ago

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

264
Hhuang_keMod·yesterday

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.

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

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

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

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

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

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

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

180
Bbob_chen·2 days ago

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

168
Sslow_query·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".

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

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

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

125
Mmike_xu·3 minutes ago

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

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

266
Aalice_dev·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".

29
Ddev_zhouOP·2 days ago

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

60
Cchen_dev·2 days agoedited

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

112
Oops_wangOP·1 hour 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.

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

103
Hhuang_ke·yesterday

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

93
RraseOPMod·2 days ago

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

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

3
Kkite·yesterday

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

84
Oops_wangOP·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.

22
Oops_wang·2 days ago

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

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

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

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

66
Zzhu_zongOP·3 minutes ago

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

4
Lli_ming·2 days ago

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

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

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

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

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

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

40
Zzhu_zong·28 minutes ago

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

15
Sswoole_leeMod·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.

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

40
Llinlin·2 hours ago

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

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

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

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

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

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

78
Kkernel_panic·3 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.

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

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

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

132
Llinlin·2 days ago

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

120
Rran_bo·2 days ago

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

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

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.

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

12
Sslow_query·2 days agoedited

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

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

304
Wwinter·yesterday

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.

67
Wwinter·3 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.

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

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

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

1
Lli_ming·2 days agoedited

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

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

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

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

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

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

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

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

65
Aalice_dev·5 hours agoedited

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

87
Kkernel_panic·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".

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

26
Ttang_hao·2 days agoedited

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

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

158
RraseOP·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
Zzhou_yi·2 days ago

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

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

24
Rran_bo·2 days ago

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

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

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

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

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

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

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

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

12
Kkernel_panic·1 hour 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.

1
Rran_bo·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".

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

440
WwinterMod·12 minutes ago

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

1
Aalice_dev·2 days ago

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

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

65
Rrase·2 days ago

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

167
Wwinter·28 minutes 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.

27
Lli_ming·yesterday

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.

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

4
Zzhu_zong·5 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.

4
Sswoole_lee·2 days ago

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

1
KkiteMod·2 days ago

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

1
Zzhu_zong·2 days ago

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

1
Rrase·2 days ago

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

173
NnikicOP·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
Oops_wang·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/rust/post/p12. 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 →