Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:126239 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 AF1291A00BC for ; Thu, 30 Jan 2025 12:43:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1738240812; bh=ozMiTU9f3/txMPHmeF7WQExZy8ewjHHXYstVzbY63hY=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=FtShAPuBuUqgWH8KA42wRXVTllnpOQT5CEJ5tJT+hPwSmuCN+mrfsBQRbqdYxbCFk qh02RnuxHWL4FAycTfjI/E7pxxaoAitzH0R4ojzw9NJ0bo79zonIPS22TKs2OeeqPf bQNJuRWn7GJoRfYIkHj/f2IGL3QHE68JjQc4x6snTD1f0U97GYla9bCCR7y/8jZzpp ryTmjwZGZMenmn/VcFWAJMoqCzJ2c59S9tUfInUuLeOQJfF7v2Ntc/H1f3oCEI8g92 b7gWK4McFRxUu5rLRccoP1YldEiwmoHK45FzFwb7+HjnaqBKhw1c750QpirCVAqVRn 9di+kEwRqe5jA== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 17C81180040 for ; Thu, 30 Jan 2025 12:40:12 +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=2.0 required=5.0 tests=BAYES_50,DMARC_NONE, FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS, HTML_MESSAGE,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL, SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=4.0.0 X-Spam-Virus: No X-Envelope-From: Received: from mail-oa1-f52.google.com (mail-oa1-f52.google.com [209.85.160.52]) (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 12:40:11 +0000 (UTC) Received: by mail-oa1-f52.google.com with SMTP id 586e51a60fabf-29e5c0c46c3so428117fac.3 for ; Thu, 30 Jan 2025 04:42:59 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1738240979; x=1738845779; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=QBb9hdbduzw2M4o1YRiQUCf9T6UFTcVBoYMv8GE+bNc=; b=ffBoi3/86Gp0uI88qKFC19nl2xbGM/ADAOPr3WxDkqehjGjR5laT2DjwOa4ik4VidZ D6JgwShZCsyhyv4bNJ9uia2Ji288CEnhIzL8snJMlagWMCGicLvhOGIoWV6tIa3J07eb w/pTe7fuPzDwKjEjR0jnJ2SmtCc6ELDLi0h6noH+IB2rf2tqa2Qpaz35+kZeNS210xX9 UfUTSqhQypcJhdJzEPiMAezp61+CQFs4i9+1liVPaSwkCYzb6k7oXtlbdUtxVPKVAFi6 SrNyuFXDxMqMXpIKVl/h4FD4EB1q10lEaxt/HiMRBfZ/Sy52fGQ0g7GCpZlGbyGgSllJ 719g== X-Gm-Message-State: AOJu0YxfPrDLIh34yDUxbjRIMGL9hFmBsEPyUjIX4oFZv4PksWOqIE9S zs2dliPcRjWNfO/xcn5Cj6EE2XUUdI871WG4gTXDWtN2fjmHFM3HjLM23Z2+ipLlVSjqC2l2KlC L3GoGTe545gDcjcUSJ1p6XFYqznMSl66K X-Gm-Gg: ASbGnctDMyfQ9pZoKytaLFBRHz0L/RMrfz+oQFcDnkukLrW0KNFakdeYeK3WkyiDann OLzbG8SHiHCMtY3oZHb3GXC1zPVSkMWAv6c9warjfKaXzuEEsmRSxZBIFX1LL5CqyctcX5kRs X-Google-Smtp-Source: AGHT+IFgpxre3oCzqAtLrHwVMB80qdcm+sYwPkp0IuenLGjX5lSZblJ2TOsdNaPrfdXUmzxmHUp8Dvdaicl+vUfli3s= X-Received: by 2002:a05:6871:3a83:b0:29e:443b:edcd with SMTP id 586e51a60fabf-2b32f3043efmr3682847fac.37.1738240978713; Thu, 30 Jan 2025 04:42:58 -0800 (PST) Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net x-ms-reactions: disallow MIME-Version: 1.0 References: In-Reply-To: Date: Thu, 30 Jan 2025 13:42:47 +0100 X-Gm-Features: AWEUYZnruVAjjjMnlTC01dcOZivWLjlNhbbHfz4_3QXn0CjfuIJphJLFQ8SkeJU Message-ID: Subject: Re: [PHP-DEV] [RFC] Introducing pm.max_memory for PHP-FPM To: Arkadiy Kulev Cc: internals@lists.php.net Content-Type: multipart/alternative; boundary="00000000000012086e062cebc4af" From: bukka@php.net (Jakub Zelenka) --00000000000012086e062cebc4af Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Hi, On Tue, Jan 28, 2025 at 2:17=E2=80=AFAM Arkadiy Kulev wr= ote: > Hello everyone, > > I=E2=80=99d like to propose adding a new configuration directive, tentati= vely > called *pm.max_memory*, to PHP-FPM. This directive would allow > administrators to specify a per-child memory usage limit, after which the > PHP-FPM child process would gracefully exit or restart. > I think it's reasonable as an additional protection and a bit nicer than pm.max_requests. However, implementation might be tricky. > Implementation Details and Challenges > > I am not proposing to implement this feature myself=E2=80=94I=E2=80=99m m= ore of a sysadmin > and don=E2=80=99t have the necessary C knowledge to patch php-src. Howeve= r, here > are some thoughts on what the implementation might involve: > > 1. *Measuring memory usage:* Likely via getrusage(), mallinfo() (on > some platforms), or reading from /proc/self/statm on Linux. > > This wouldn't really work because FPM does not control the script during execution and would have to check it out after each allocation which is not really viable. > > - *System-level OOM or cgroups:* This approach can kill the entire > pool or container, which is often more disruptive than recycling a sin= gle > worker. > > I think this is really the only way that I can see to make it work reliably. We have got already an old feature request for that: https://bugs.php.net/bug.php?id=3D70605 . There was even a PR https://github.com/php/php-src/pull/2440 but it was using unmaintained lib and cgroup v1. We should use something cgroup v2 based but it is not a small job to add it. Anyway you can create a GitHub feature request for this so it doesn't get forgotten and maybe one day there will a better PR that can be accepted. Cheers Jakub --00000000000012086e062cebc4af Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Hi,

On Tue, Jan = 28, 2025 at 2:17=E2=80=AFAM Arkadiy Kulev <eth@ethaniel.com> wrote:

Hello everyone,

I=E2=80=99d like to propose adding a ne= w configuration directive, tentatively called pm.max_memory, to PHP-FPM. This directive would allow administrators to sp= ecify a per-child memory usage limit, after which the PHP-FPM child process= would gracefully exit or restart.


I think it's reasonable as an additional protection an= d a bit nicer than=C2=A0pm.max_requests. However, implementation might be t= ricky.
=C2=A0

Implementation Details and Challenges

I am not proposing to = implement this feature myself=E2=80=94I=E2=80=99m more of a sysadmin and do= n=E2=80=99t have the necessary C knowledge to patch php-src. H= owever, here are some thoughts on what the implementation might involve:

  1. Measuring memory usage: Likely via getrusag= e(), mallinfo() (on some platforms), or reading from /proc/self/statm on Linux.
=
This wouldn't really work because FPM does not control t= he script during execution and would have to check it out after each alloca= tion which is not really viable.
=C2=A0
  • System-= level OOM or cgroups: This approach can kill the entire pool or co= ntainer, which is often more disruptive than recycling a single worker.


I think this is= really the only way that I can see to make it work reliably. We have got a= lready an old feature request for that: https://bugs.php.net/bug.php?id=3D70605 . There was ev= en a PR=C2=A0https://g= ithub.com/php/php-src/pull/2440 but it was using unmaintained lib and c= group v1. We should use something cgroup v2 based but it is not a small job= to add it.

Anyway you can create a GitHub feature= request for this so it doesn't get forgotten and maybe one day there w= ill a better PR that can be accepted.

Cheers
=

Jakub
--00000000000012086e062cebc4af--