Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:126247 X-Original-To: internals@lists.php.net Delivered-To: internals@lists.php.net Received: from php-smtp4.php.net (php-smtp4.php.net [45.112.84.5]) by qa.php.net (Postfix) with ESMTPS id BC94C1A00BC for ; Thu, 30 Jan 2025 18:11:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1738260515; bh=yyJ/+bI4PDpSTOOhw+1dQciSZTA0wWx93jZtur6cuqM=; h=Date:From:To:Cc:In-Reply-To:References:Subject:From; b=OJ/wpqQtqVjCt5NKLTU1kZM30qEBqQIzWcAY+kN6g2ebbLc0eyXeCzM3jmkKvGUeZ JbaIDASrc0LSEj9a1OAJd4gpF1RpKdY9qWC2dvHBWLLTlTs+AVV88KJ2qK+DDPd7VO mQtZqIi5/MMqxITBmNF+5yKaKBX6yGm5WnK0n25vmMelnDLSxPSf04hRMcrjG2cJch ExUFsYj8zDLZ5nXr68zwckKAHdEhATjLwbegYsz3lzT5/wtdkwK3RiLt6ydHRU5Lki bGwuQYa274RexPl2kn+3fTKnjIDvgy1l1vggiFRn+CXjNHIx8M/cWbvdDShUOHbElL 9Sy98ifG1dUFg== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id EDB171801EA for ; Thu, 30 Jan 2025 18:08:34 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-0.1 required=5.0 tests=BAYES_50,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_MISSING,HTML_MESSAGE, RCVD_IN_DNSWL_LOW,SPF_HELO_PASS,SPF_PASS autolearn=no autolearn_force=no version=4.0.0 X-Spam-Virus: No X-Envelope-From: Received: from fout-b1-smtp.messagingengine.com (fout-b1-smtp.messagingengine.com [202.12.124.144]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Thu, 30 Jan 2025 18:08:34 +0000 (UTC) Received: from phl-compute-01.internal (phl-compute-01.phl.internal [10.202.2.41]) by mailfout.stl.internal (Postfix) with ESMTP id C71DB114009B; Thu, 30 Jan 2025 13:11:21 -0500 (EST) Received: from phl-imap-09 ([10.202.2.99]) by phl-compute-01.internal (MEProxy); Thu, 30 Jan 2025 13:11:21 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bottled.codes; h=cc:cc:content-type:content-type:date:date:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to; s=fm1; t=1738260681; x= 1738347081; bh=yyJ/+bI4PDpSTOOhw+1dQciSZTA0wWx93jZtur6cuqM=; b=A ZuPFQL2vjk1+Rlbkq/qWt6U+r5ztN1sW68jZHDBPNHETZOG1N7fcDxq9VueKnXO8 xTbxnCuXx1TB/zJGmdjg3n9UvYhxvDchkZr6Q5Z3TCIKjq2bi6686v4fP85KSYcR eMbxlvwv5mPTs9GrUqFJ/QpeihE/i7Gey4D0sL+3f9cX5Ml/Jo+X3UCRw0J+vz6t gL+gy+1dH+etdTQkhpNmw9CZ3e7eBhLQvl7Xy/IE3o5ZxFINZQ/U3yXMVUpMgfnF NUu8LBC/AsYU8W/Cy/1pI0d06mGbgQgJ1ujCLj8DNqNKusF8qnx0yxeYYM1O2KOi vEBBLYGbRM5uYZwTcyeHA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm3; t= 1738260681; x=1738347081; bh=yyJ/+bI4PDpSTOOhw+1dQciSZTA0wWx93jZ tur6cuqM=; b=E7eYrHEKavKzrAgq0SY3wusrCgkrNhZYtWWwqgPWrDSTMffcvf/ yT+IREGPKJqfTnT/MZmC48OuZ1JBBazXbs0Jdz0uc8jFdlJah4xXett+CeF7o50j w6/8A06fM50O8NRUJ8e1IaDlEyFJ+NwG3VKf9odmbTMeeyFFd/bSWGI34LU6xOES bAo35GvNpqyXlFMwCgkizln52BGklOQ6El9ujX+8cipK1jRrf9TIZzvpLVmQeZLN g0BS2RzJTAOa8CgB5/Pv8KDsoOTpXbr79yonMeUIBp6iAnlj/8YWLWjkX0QjCZXm fn6BEFVX+sl4lnFbFYtPTz0NKHhyPG+HBOQ== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefvddrtddtgdeiheduucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucenucfjughrpefoggffhf fvvefkjghfufgtsegrtderreertdejnecuhfhrohhmpedftfhosgcunfgrnhguvghrshdf uceorhhosgessghothhtlhgvugdrtghouggvsheqnecuggftrfgrthhtvghrnhepieeute ehvddvfeejhffgieehleehhedthfefkeejffelgfevvdekudetjeejtddtnecuvehluhhs thgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomheprhhosgessghothhtlh gvugdrtghouggvshdpnhgspghrtghpthhtohepfedpmhhouggvpehsmhhtphhouhhtpdhr tghpthhtohepvghthhesvghthhgrnhhivghlrdgtohhmpdhrtghpthhtohepihhnthgvrh hnrghlsheslhhishhtshdrphhhphdrnhgvthdprhgtphhtthhopegsuhhkkhgrsehphhhp rdhnvght X-ME-Proxy: Feedback-ID: ifab94697:Fastmail Received: by mailuser.phl.internal (Postfix, from userid 501) id 2D861780069; Thu, 30 Jan 2025 13:11:21 -0500 (EST) X-Mailer: MessagingEngine.com Webmail Interface Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net x-ms-reactions: disallow MIME-Version: 1.0 Date: Thu, 30 Jan 2025 19:11:00 +0100 To: "Arkadiy Kulev" , "Jakub Zelenka" Cc: internals@lists.php.net Message-ID: <3624b46b-16f2-4eb3-b1ac-d0439cd79153@app.fastmail.com> In-Reply-To: References: Subject: Re: [PHP-DEV] [RFC] Introducing pm.max_memory for PHP-FPM Content-Type: multipart/alternative; boundary=5f8ee6bb1e224c93904d3ea73b7d8a8a From: rob@bottled.codes ("Rob Landers") --5f8ee6bb1e224c93904d3ea73b7d8a8a Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable On Thu, Jan 30, 2025, at 17:41, Arkadiy Kulev wrote: > Hello! >> This wouldn't really work because FPM does not control the script dur= ing execution and would have to check it out after each allocation which= is not really viable. >=20 > Thanks for the feedback! I agree that monitoring memory usage after ea= ch allocation would be infeasible. However, my suggestion was actually t= o check memory usage *only once per request*, specifically at request sh= utdown, when FPM regains control and before assigning another request to= that worker.=20 >=20 > We already have hooks for request startup and request shutdown in FPM.= Could we simply insert a memory check at the request shutdown stage=E2=80= =94where the worker is returning control to the FPM master process=E2=80= =94before picking up a new request? >=20 > Just to be clear, "memory_limit" helps kill runaway scripts mid-reques= t. By contrast, the newly proposed pm.max_memory is meant to catch proce= sses with a slow leak across multiple requests. We only need to check at= the end of each request, which is presumably when the worker returns co= ntrol to FPM. To be honest, I haven't seen a 'slow' memory leak in a long time -- exce= pt when using fgetcsv which has had a reported memory leak since ~2012 s= omewhere on the old bug tracker. (I lost the link to it and don't even r= emember how to get to the tracker or if it still exists.) I haven't chec= ked if it has been fixed since 8.2, but I've seen a couple of reports of= it on r/php a couple of times in the last couple of years. =E2=80=94 Rob --5f8ee6bb1e224c93904d3ea73b7d8a8a Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: quoted-printable
On Thu, Jan 30,= 2025, at 17:41, Arkadiy Kulev wrote:
Hello!=
This wouldn't r= eally work because FPM does not control the script during execution and = would have to check it out after each allocation which is not really via= ble.

Thanks f= or the feedback! I agree that monitoring memory usage after each allocat= ion would be infeasible. However, my suggestion was actually to check me= mory usage only once per request, specifically at request shutdow= n, when FPM regains control and before assigning another request to that= worker. 

We already have hooks = for request startup and request shutdown in FPM. Could we simply insert = a memory check at the request shutdown stage=E2=80=94where the worker is= returning control to the FPM master process=E2=80=94before picking up a= new request?

Just to be clear, "memory_lim= it" helps kill runaway scripts mid-request. By contrast, the newly propo= sed pm.max_memory is meant to catch processes with a slow leak across mu= ltiple requests. We only need to check at the end of each request, which= is presumably when the worker returns control to FPM.

To be honest, I haven't seen a 'slo= w' memory leak in a long time -- except when using fgetcsv which has had= a reported memory leak since ~2012 somewhere on the old bug tracker. (I= lost the link to it and don't even remember how to get to the tracker o= r if it still exists.) I haven't checked if it has been fixed since 8.2,= but I've seen a couple of reports of it on r/php a couple of times in t= he last couple of years.

=E2=80=94 Rob
--5f8ee6bb1e224c93904d3ea73b7d8a8a--