PHP Community · Help: PHP fails to start intermittently in containers, logs inside

318
phpr/php·posted by zhou_yi·yesterdayTranslation

Help: PHP fails to start intermittently in containers, logs inside

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

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.

Performance44%
Maintainability28%
Ecosystem and community17%
Hiring difficulty11%

541 votes total

146 comments

146 comments

· first 120 loaded
M
Kkernel_panicOP·2 days ago

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

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

56
Lli_ming·2 days ago

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

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

446
Ddev_zhou·2 days ago

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

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

39
Kkite·2 days ago

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

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

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

398
Ddev_zhou·yesterdayedited

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

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

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

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

376
Ttang_hao·2 days ago

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

374
Kkite·yesterday

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.

373
Aalice_dev·2 days ago

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

19
Rrase·2 days ago

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

132
Hhuang_ke·2 days ago

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

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

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

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

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

277
Oops_wang·2 days ago

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

186
NnikicOP·2 days ago

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

131
Rrase·2 days agoedited

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

105
Ddev_zhou·12 minutes agoedited

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

399
Aalice_devOP·2 days agoedited

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

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

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

52
Bbob_chen·3 minutes ago

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

397
Zzhu_zong·2 days ago

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

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

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

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

305
Hhuang_ke·2 days ago

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

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

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

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

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

30
Lli_ming·just nowedited

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.

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

241
Ttang_hao·2 hours ago

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

17
Kkite·2 days ago

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

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

460
Kkernel_panic·2 days ago

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

272
Ddev_zhou·3 minutes agoedited

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

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

290
Sslow_query·5 hours agoedited

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

29
Hhuang_keOP·yesterdayedited

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

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

334
WwinterOP·2 hours 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.

216
Mmike_xu·2 days agoeditedLevel 6

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

40
Zzhou_yi·2 days ago

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

73
Cchen_dev·2 days ago

One counter-example: below PHP 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
Bbob_chen·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.

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

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

177
Cchen_dev·2 days ago

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

147
Bbob_chen·just now

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

234
Zzhou_yi·2 days ago

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

144
Zzhu_zong·2 days agoedited

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

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

124
Lli_ming·2 days ago

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

300
Zzhou_yi·2 days ago

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

123
Cchen_dev·2 days ago

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

458
Zzhu_zong·yesterday

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.

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

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

57
Wwinter·2 days ago

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

16
Nnikic·just now

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

119
Cchen_dev·3 minutes ago

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

2
Mmike_xu·3 minutes ago

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

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

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

10
Wwinter·2 days ago

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

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

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

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

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

115
Hhuang_ke·2 days ago

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

40
Oops_wang·28 minutes ago

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

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

74
Sslow_query·12 minutes ago

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

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

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

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

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

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

59
Aalice_dev·5 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.

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

48
Lli_ming·3 minutes ago

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

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

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

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

309
Rran_bo·2 days ago

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

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

46
Hhuang_ke·2 days ago

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

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

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

25
Ttang_hao·just now

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

25
Lli_mingMod·2 days ago

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

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

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

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

20
Ttang_haoMod·2 days ago

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

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

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

17
Llinlin·2 days ago

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

15
Kkite·2 days agoedited

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

15
Cchen_dev·2 days ago

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

12
Llinlin·2 days ago

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

9
Kkite·2 days ago

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

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

1
Kkernel_panic·2 days ago

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

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

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

41
Kkite·2 days ago

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

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

1

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