Keyboard Community · I upgraded our production keyboard and hit these 11 landmines

680
KEr/keyboard·posted by swoole_lee·3 hours agoJobs

I upgraded our production keyboard and hit these 11 landmines

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

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

// Minimal reproduction: you must use a real long-tail distribution here.
// Uniform load-test traffic will never trigger this.
func (s *Server) handle(ctx context.Context) error {
    conn, err := s.pool.Acquire(ctx)
    if err != nil {
        return fmt.Errorf("acquire: %w", err)
    }
    defer conn.Release()

    return s.do(ctx, conn)
}

The first thing was to collapse the variables. We were changing config and upgrading the version at the same time, and afterwards nobody could say which change caused what. We rolled back to moving one variable at a time, re-ran three times, and only then did the curve settle. Tedious, but not skippable.

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.

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.

113 comments

113 comments

M
Zzhu_zongOPMod·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.

491
Kkite·2 days agoedited

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

483
Rran_bo·2 hours agoedited

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

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

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

459
Lli_ming·2 days ago

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

457
Nnikic·2 days ago

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

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

406
Ttang_haoOP·2 days ago

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

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

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

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

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

391
Nnikic·2 days ago

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

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

372
Bbob_chen·2 days ago

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

357
Oops_wang·2 days ago

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

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

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

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

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

209
Hhuang_ke·2 days ago

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

37
Nnikic·12 minutes ago

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

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

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

223
Sslow_query·3 minutes ago

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

480
Cchen_dev·2 days ago

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

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

4
Cchen_dev·2 days ago

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

259
Sslow_queryOP·1 hour ago

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

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

443
Bbob_chen·5 hours ago

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

201
Rran_bo·12 minutes ago

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

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

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

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

483
Cchen_dev·2 days ago

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

166
Rran_bo·2 hours ago

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

4
Rran_bo·3 minutes agoLevel 6

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

24
Zzhu_zong·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
Kkite·2 days ago

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

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

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

28
Rran_bo·5 hours agoLevel 6

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

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

29
Hhuang_ke·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
Llinlin·yesterday

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

17
Bbob_chen·5 hours ago

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

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

360
Cchen_dev·2 days ago

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

73
Zzhou_yi·2 days ago

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

186
Kkernel_panic·2 days agoedited

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

378
Wwinter·2 days ago

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

182
Oops_wang·2 days ago

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

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

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

152
Ddev_zhou·just now

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

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

142
Ttang_hao·2 days agoedited

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

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

8
Bbob_chen·3 minutes ago

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

129
Zzhu_zong·yesterday

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

45
Wwinter·just now

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

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

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

11
Sslow_query·3 minutes ago

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

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

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

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

199
RraseOP·2 days ago

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

33
Nnikic·2 days ago

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

64
Zzhu_zong·2 days ago

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

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

119
Oops_wang·2 days ago

This is not a keyboard 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

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.

109
Sswoole_lee·2 days ago

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

108
Bbob_chenOP·2 days ago

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

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

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

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

109
Nnikic·2 days ago

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

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

21
Hhuang_ke·1 hour ago

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

68
NnikicOP·2 days agoedited

One counter-example: below keyboard 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
Llinlin·2 days agoedited

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

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

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

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

31
Oops_wang·2 days ago

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

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

27
Oops_wang·28 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.

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

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

454
Cchen_dev·2 days ago

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

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

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

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

218
Aalice_dev·2 days ago

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

502
Mmike_xu·2 days ago

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

161
Rrase·28 minutes ago

One counter-example: below keyboard 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
LlinlinOP·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.

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

18
Sswoole_lee·3 minutes ago

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

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

10
Hhuang_ke·yesterday

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.

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

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

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

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

1

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