php / php/php-src

FPM delayed process restarting

オープン
#9,632 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

Feature SAPI: fpm
主要言語
C
スター
40.4k
フォーク
8.1k
平均マージ
2日 13時間
マージ済み PR(30日)
96

説明

Description

There is an issue in FPM happening when a child crashes shortly after the start. That might cause a loop of child restarts which might result in unresponsive master process because it is overloaded with handling restarts - signal events. One such case was described in bug #61558. Although that particular issue got fixed, this should be addressed as it might still happen due to the crash in extension or similar problem.

The solution could be to introduce an increased delay between process restarts. The idea is that we would measure how many restarts were done in the last second or some sensible time. If it goes over lets say 2 x pm.max_children, then we would set delay before starting a new child. If that happens in such short interval + current delay again, we increase the delay. If there are no restarts, then we would decrease the delay so we can recover in case it was just a temporary problem however unlikely this is.

Unfortunately it brings various challenges:

  1. The scoreboard would need to be extended with some extra data (probably just one field counting number of children created from the beginning) and some sort of scoreboard history would need to be introduced to compare data between specific intervals. It could be done using some sort of scoreboard snapshots during server maintenance or managed using its own periodic events. It should be easily selectable so some optimal structure might need to be introduced.
  2. The current delay might need to be also stored in scoreboard as it's a shared value. With the above check, it means it will increase amount of reads and writes to scoreboard and we might need to do some smarter locking before that.
  3. Starting of the child would need to move to a separate event so the delay can be performed. It might be a good thing in general but it's not clear if it could potentially introduce some regression if used for all starts so we might need some abstraction so we can still trigger immediate starts directly without going through even loop. It might need some experimenting as well.
  4. Consideration of ondemand pm where we can have natural starts when scaling up. Surely we don't want to delay those.
  5. Configuration for the specific params so users can tweak it if it's too strict or lax for their workload. We should have good enough defaults but we cannot obviously make it optimal for all workloads.
  6. Finding the right defaults which will require some comprehensive testing with different sort of configurations.
  7. Possibly prevent infinite wait loop - it should be enough to limit it to the sum of max children in all pools. Or might be worth to give another try to https://github.com/php/php-src/pull/9027 which catches primarily a pid of the terminated child. Although this might need some extra checking on Mac as it was failing there and it's not clear as there is much benefit in it.

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

まず、issue で説明されている FPM 子プロセスの起動、クラッシュ時の再起動処理、scoreboard へのアクセス、イベントループを追跡します。遅延した再起動が自然なスケーリングとどのように連携すべきかを決める前に、ondemand プロセスマネージャーのパスと pull request #9027 を確認します。完了の条件は、通常の起動を妨げずに再起動ストームを防止し、適切なデフォルト値を設定し、説明されているすべての構成をカバーすることです。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
c
領域
backend
issue の種類
バグ
難易度
5/5
見積もり時間
1週間以上
活発さ
停滞
明瞭さ
説明が足りない
初心者へのやさしさ
25/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。