Alipay Mini Program Community · Cut our alipay-miniprogram build from 4 minutes to 40 seconds with these 5 changes

625
AMr/alipay-miniprogram·posted by linlin·1 hour agoOpen source

Cut our alipay-miniprogram build from 4 minutes to 40 seconds with these 5 changes

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

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 query that broke: a full scan over 20M rows.
-- A composite index took P99 from 1.8s down to 42ms.
SELECT id, title, created_at
  FROM posts
 WHERE community_id = ?
   AND status = 1
 ORDER BY score DESC
 LIMIT 20;

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.

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.

296 comments

296 comments

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

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

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

175
Bbob_chen·2 days ago

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

3
Ddev_zhou·2 days ago

One counter-example: below alipay-miniprogram 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
Zzhou_yiOP·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.

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

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

465
Wwinter·just now

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

449
Aalice_dev·1 hour agoedited

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

401
Kkite·2 days ago

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

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

45
Rrase·2 days ago

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

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

62
Ttang_hao·2 days ago

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

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

399
Kkernel_panic·yesterday

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

366
Hhuang_ke·2 days ago

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

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

323
Sswoole_lee·2 days ago

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

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

313
Nnikic·yesterday

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

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

294
Rran_boOP·2 days ago

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

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

199
Hhuang_ke·2 days ago

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

188
Ddev_zhou·2 days ago

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

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

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

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

153
Nnikic·2 days agoedited

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

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

114
Cchen_dev·2 days ago

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

8
Mmike_xuOP·2 days agoedited

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

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

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

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

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

87
Nnikic·2 days ago

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

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

159
WwinterOP·2 days ago

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

16
Aalice_devOP·2 days ago

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

1
Zzhou_yi·2 days ago

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

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

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

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

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

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

194
Cchen_dev·just now

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

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

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

26
Aalice_devOP·28 minutes agoedited

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

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

17
Wwinter·just nowLevel 6

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

2
Cchen_dev·2 days agoedited

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

273
Rrase·2 days agoLevel 6

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.

159
Zzhu_zong·2 days agoeditedLevel 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.

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

450
Oops_wang·2 hours ago

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

243
Ttang_hao·2 hours ago

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

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

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

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

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

174
Sswoole_lee·2 days ago

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

382
Ddev_zhou·2 days agoedited

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

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

79
Llinlin·2 days ago

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

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

88
Sslow_queryOP·2 hours agoLevel 6

One counter-example: below alipay-miniprogram 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
Kkernel_panic·2 hours agoedited

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

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

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

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

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

324
Mmike_xu·2 days agoLevel 6

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

26
Nnikic·5 hours 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.

28
Rrase·1 hour ago

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

499
Oops_wang·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
Wwinter·12 minutes 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.

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

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

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

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

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

55
Sslow_query·2 days ago

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

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

19
Zzhu_zong·yesterday

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

18
Ttang_hao·2 days ago

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

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

180
Kkite·2 days ago

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

52
Zzhu_zong·2 days ago

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

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

13
Rrase·2 days ago

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

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

10
Sslow_query·2 days ago

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

115
Ttang_hao·2 days ago

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

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

4
Kkite·2 days ago

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

329
Bbob_chen·1 hour agoedited

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

381
Hhuang_ke·2 days ago

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

96
Nnikic·2 days ago

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

3
Kkite·3 minutes ago

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

3
Sswoole_lee·3 minutes ago

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

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

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

340
Wwinter·2 hours ago

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

96
Cchen_dev·just now

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

332
Rran_bo·2 days agoLevel 6

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

324
Zzhou_yi·2 days agoLevel 6

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.

154
Ttang_hao·12 minutes ago

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

269
Ddev_zhouOP·1 hour ago

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

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

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

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

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

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

1

This is the post detail page /en/c/alipay-miniprogram/post/p5. 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 →