MySQL Community · Cut our MySQL build from 4 minutes to 40 seconds with these 5 changes

555
Myr/mysql·posted by rase·just nowExperience

Cut our MySQL build from 4 minutes to 40 seconds with these 5 changes

Short version: MySQL 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.

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)
}

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.

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.

234 comments

234 comments

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

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

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

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

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

339
Wwinter·2 days ago

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

420
Ddev_zhouMod·2 days ago

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

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

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

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

355
NnikicOP·2 days ago

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

160
Sslow_query·2 days agoedited

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

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

142
Oops_wang·just now

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

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

173
Sswoole_leeMod·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
Nnikic·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.

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

495
KkiteOP·12 minutes ago

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

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

230
Sslow_queryOP·2 days ago

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

51
Cchen_devOP·2 days ago

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

182
Zzhu_zong·2 days agoLevel 6

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

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

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

58
Rran_boOP·2 days ago

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

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

216
Wwinter·2 days agoeditedLevel 6

Can you give a minimal reproduction? I ran it locally for ten minutes and could not reproduce on macOS with the latest version.

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

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

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

17
Zzhou_yi·2 days agoedited

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

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

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

35
Wwinter·2 days agoLevel 6

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

47
Rran_bo·2 days ago

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

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

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

210
Kkite·3 minutes ago

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

77
Zzhu_zongMod·just now

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

109
Zzhou_yi·2 days ago

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

321
Hhuang_ke·5 hours ago

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

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

77
Rrase·3 minutes agoLevel 6

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

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

135
Sswoole_lee·5 hours ago

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

10
Bbob_chen·2 days agoedited

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

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

431
Rran_bo·2 days ago

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

68
Oops_wang·2 days ago

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

8
Ttang_haoOP·2 days ago

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

258
Oops_wang·2 days ago

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

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

300
Ttang_haoOP·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.

238
Nnikic·2 days ago

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

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

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

2
Lli_ming·2 days agoedited

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

1
Sslow_query·12 minutes ago

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

241
Rran_bo·2 days agoedited

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

241
Ddev_zhou·1 hour ago

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

239
Sslow_queryOP·12 minutes 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.

151
Hhuang_keMod·12 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.

439
Llinlin·2 days ago

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

45
Rran_bo·2 days ago

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

258
Kkernel_panic·28 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.

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

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

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

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

36
Ddev_zhou·yesterday

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

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

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

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

209
Sswoole_leeOP·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.

140
Kkernel_panic·12 minutes ago

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

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.

188
Nnikic·28 minutes ago

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

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

128
Mmike_xuOP·2 days ago

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

67
Sslow_query·2 days ago

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

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

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

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

121
Nnikic·just now

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

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

103
Hhuang_keOP·12 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.

41
Sslow_query·2 days ago

One counter-example: below MySQL 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
Rran_boMod·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.

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

6
KkiteOPMod·2 days ago

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

13
Mmike_xu·3 minutes ago

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

62
Mmike_xuOP·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
Sslow_query·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.

54
Oops_wang·2 days ago

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

48
Llinlin·2 days ago

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

39
Ttang_hao·2 days ago

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

9
Kkernel_panic·2 days ago

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

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

50
Wwinter·2 days ago

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

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

4
Llinlin·28 minutes ago

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

3
Zzhu_zong·1 hour ago

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

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

2
Llinlin·2 days ago

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

11
NnikicMod·2 days ago

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

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

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

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

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

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

2
Ttang_hao·2 days ago

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

1
Bbob_chen·2 days ago

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

1
Sswoole_lee·2 days ago

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

1
Rrase·2 days ago

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

178
Zzhou_yi·2 days ago

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

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

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

81
Cchen_dev·5 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·2 days ago

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

19

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