Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:126254 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 68C6B1A00BC for ; Fri, 31 Jan 2025 10:14:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1738318324; bh=Pm60cyEKOmHLdHIqjj7VFpiLcTJjIxFPEfbCHENcq0Y=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=F6zuRdtUCjdh9CF0eSBY98ja6UQQ6bKbwYzujU/kAOmQ4ZkeaTy0KyqkrMOteSST+ N3RSLtjtKCz1qAveZYV4GXTu3bKGkctCLsqvVmVYLSTEUp6smmC1hDof0zK3hfiL2M yHHNp9l/oKA+lCkOsn+XO/tXYK9+xH3GY67PqUfyfj0VhftqdLTSqeIEph4PBorhTX hTyfqZlXBptZOy5zb+h+Ehhk4fR+LFpc7uuHIMpZjmVjZtBw+3+Jdd9+4cEEzDCr7A Nsh56Yjqu5dYtICg5WQlaND7sanFZE8b+mQbzRotu0U+W0mdMYsJ2F9ipruIhKNGYn EYKI43zt8GlBQ== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 414E2180039 for ; Fri, 31 Jan 2025 10:12:04 +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-ot1-f50.google.com (mail-ot1-f50.google.com [209.85.210.50]) (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 ; Fri, 31 Jan 2025 10:12:03 +0000 (UTC) Received: by mail-ot1-f50.google.com with SMTP id 46e09a7af769-71e2aa8d5e3so1005250a34.2 for ; Fri, 31 Jan 2025 02:14:51 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1738318490; x=1738923290; 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=Pm60cyEKOmHLdHIqjj7VFpiLcTJjIxFPEfbCHENcq0Y=; b=rDM0v7t4H+oyxUCm1/Q6jUFMR5h1d5fpijhoZTHUi/aHrvVuUW2rY8WtiLyOw4uFhx lulojBj9oDpu3urM3nfKWWLuM0EhBdVwd3xV8Svm/2YREkJoXUpB4Lay7SxEDjI6uRjz ScAQKPnuDD+66/t2PtlljVrDyATyCkviEQ3fM2nN0vHVfOx/XsT8mINwINwcAMHtBmsL B46RyicbQhBGnUz0UUv0oJ0MbOrTGAFKsH4uPoWByZckveamaZwSR01vrYo1R1IetKJS JGDVq8MW+Eft0eUBn31RLjCskzI31deUMdIL8sPSoVm453fIVHuKnSaeLXPvMdaEw0Sm 7crg== X-Gm-Message-State: AOJu0Ywf2PWzy0e1n6SCwHpS1wLWrQpt5U9kUX6L99hSdAYbZpidZqFY h0DTdDPKLZi14/MgEBP1uItru2BBYhOBQY33/N7E5kvICh6CAlHwM5naZZP6psgRdOVd84j/zb4 pIPg7F+mjR9i90eWUSNEMz66sjn8= X-Gm-Gg: ASbGncvU9gOR5MMkBMGgD9soFHTTxonXouVvXVSWQTTxGKz3jKLuQc5kMSMeeV9mwdD CjncAP3EdktminnC4LlTwcibI/dlGvuS5KW3WHbnmRUZCraPCKHJovQ5dcZwk3imqpGoi290Y X-Google-Smtp-Source: AGHT+IFdlQ9lDL4zIB/xRfgutddqNwJD5R0wXaLq5Dq5bcA/VAvNgIn/77Z+g9rPjkp3xgs6D0MVKEdpwMNTwX2qjWM= X-Received: by 2002:a05:6830:dca:b0:71d:f8bd:4be4 with SMTP id 46e09a7af769-726568db701mr6988270a34.19.1738318490507; Fri, 31 Jan 2025 02:14:50 -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: Fri, 31 Jan 2025 11:14:39 +0100 X-Gm-Features: AWEUYZmi7z-B8pXha_ks0CZzuM11WjLDh8R8u6YcS5gDr9sdkFUyEcRizqKYI78 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="000000000000221edc062cfdd071" From: bukka@php.net (Jakub Zelenka) --000000000000221edc062cfdd071 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Hi, > 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. >> > > Thanks for the feedback! I agree that monitoring memory usage after each > allocation would be infeasible. However, my suggestion was actually to > check memory usage *only once per request*, specifically at request > shutdown, when FPM regains control and before assigning another request t= o > that worker. > > I think that would require a different name because it would not reflect max memory usage in any way - it would be measured at the time when the memory usage is lowest. We could maybe set some options that would measure the maximum of increase of memory between requests - I mean difference between lowest memory usage (most likely after the first request) and then compare against current usage after the latest request and set limit on this difference. Not sure about the name for that. Maybe something like pm.max_memory_increase or something like that. > 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? > > Yeah that would be possible. > Just to be clear, "memory_limit" helps kill runaway scripts mid-request. > By contrast, the newly proposed pm.max_memory is meant to catch processes > with a slow leak across multiple requests. We only need to check at the e= nd > of each request, which is presumably when the worker returns control to F= PM. > There is one thing to note that memory_limit actually measure only memory allocated through the per request php memory allocator so it's not actually limit on total usage including the standard allocator memory usage. So there would be still a use case for total limit using cgroups but I agree that the more important use is to catch slow leaks which the above should help with in a better way than pm.max_requests. Regards, Jakub --000000000000221edc062cfdd071 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Hi,<= /div>
=C2=A0
This wouldn't really work because FPM does not control the= script during execution and would have to check it out after each allocati= on which is not really viable.

= Thanks for the feedback! I agree that monitoring memory usage after each al= location would be infeasible. However, my suggestion was actually to check = memory usage only once per request, specifically at request shutdown= , when FPM regains control and before assigning another request to that wor= ker.=C2=A0


I think that would require a different name because it would not ref= lect max memory usage in any way - it would be measured at the time when th= e memory usage is lowest. We could maybe set some options that would measur= e the maximum of increase of memory between requests - I mean difference be= tween lowest memory usage (most likely after the first request) and then co= mpare against current usage after the latest request and set limit on this = difference. Not sure about the name for that. Maybe something like pm.max_m= emory_increase or something like that.
=C2=A0
We already have hooks for request startup and request = shutdown in FPM. Could we simply insert a memory check at the request shutd= own stage=E2=80=94where the worker is returning control to the FPM master p= rocess=E2=80=94before picking up a new request?


Yeah that would be possible.
=C2=A0
Just to be clear, &quo= t;memory_limit" helps kill runaway scripts mid-request. By contrast, t= he newly proposed pm.max_memory is meant to catch processes with a slow lea= k across multiple requests. We only need to check at the end of each reques= t, which is presumably when the worker returns control to FPM.
<= /div>

There is one thing to note that memor= y_limit actually measure only memory allocated through the per request php = memory allocator so it's not actually limit on total usage including th= e standard allocator memory usage. So there would be still a use case for t= otal limit using cgroups but I agree that the more important use is to catc= h slow leaks which the above should help with in a better way than pm.max_r= equests.

Regards,

Jakub
--000000000000221edc062cfdd071--