Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:128695 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 lists.php.net (Postfix) with ESMTPS id C1F3D1A00BC for ; Fri, 12 Sep 2025 22:37:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1757716572; bh=R2MFQpTw+ZCFa4iTO66s1Ar1yhCTbGs4Oet1YwU2fkA=; h=Date:From:To:In-Reply-To:References:Subject:From; b=oAjB7jD3FUDmNTYmhAPMtju3nl1rdxggaEf5520/fXj+dIqcLDsEXnQn8fNUCGQAe Tlz9aRyREmT8rPP8S+FBsdnyojbBvZXJuHJURZWg0GxPM3ztlDCycU0hY9RzlwRpEY v2bQPZWcsKExueyQYZv+/uamCqLVn4+9NPdgN2+ctJGwZt0Pnc0mbAZZc0/lcMCzoi aYnbbub8fGi6GeBCOFiyf4HBCzeIZbmR/mwvLqMIoBTwO/Hj0iwrDyXB0dD3zaiNuJ t2IeNRnnwiEVMbbwDuQub3VqRxouAMqimfNqLYYeeAJTtLGnLH3TA6DoQUQl/wx16Z 5FLrGDQlKQsYw== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 62FC9180077 for ; Fri, 12 Sep 2025 22:36:11 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,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.1 X-Spam-Virus: No X-Envelope-From: Received: from fout-a3-smtp.messagingengine.com (fout-a3-smtp.messagingengine.com [103.168.172.146]) (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, 12 Sep 2025 22:36:10 +0000 (UTC) Received: from phl-compute-05.internal (phl-compute-05.internal [10.202.2.45]) by mailfout.phl.internal (Postfix) with ESMTP id 5D3DCEC01EC; Fri, 12 Sep 2025 18:37:36 -0400 (EDT) Received: from phl-imap-05 ([10.202.2.95]) by phl-compute-05.internal (MEProxy); Fri, 12 Sep 2025 18:37:36 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bottled.codes; h=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=fm2; t=1757716656; x=1757803056; bh=R2MFQpTw+Z CFa4iTO66s1Ar1yhCTbGs4Oet1YwU2fkA=; b=h3l6V2LxPy7dTVrmdTRzs8Xqzb b8F+Y70PuGK8ceLJjKr7ldUITsPSYRLnxkhPW+z4IAnQKWhtjOJX4uqHSU0EccCQ YyzwE8rXrGj6p2b6pN71y3bZvUcKcMeNazqPaT5ii3Grarn6EYmQj0pTFn+yTM/J gUwvt00DReJd7MGQv5thhEBqBSays3EWBmMweIRG1VoieS0/Z6HHX9vsbvivl1xN VQtrZXJYUuHxYeiyE+0alesIFPCa3Xrll2ET1YeKLk9v9i9O9Kq/dwuHJA2x/aFl 1iHtgNMqcb2I9H/5FC5/PQnzFjCrT6z5P+NvNZEnoBSyv/RORMne2HP8F+lA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=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=fm1; t= 1757716656; x=1757803056; bh=R2MFQpTw+ZCFa4iTO66s1Ar1yhCTbGs4Oet 1YwU2fkA=; b=XGj1UXLYmIS1HZBCsaDaRItjUkk6yWJ0Fj3vbwdj3q5+lniVAfD NUGCGqywPf0aFodRF0RiW5LtS+W6irLBrd3ibVct3ZAUzAgcXmEvPhJ96k99TzxS wW456W0w5Ta79kveIbyJGv5+LZcqmLOwZtnV8U2iQm7L+mw7R0YsZN96GZg7afvK SpP1WDKm6DS3StR9KZ/ohnaVaaABXY523Pt+6+oo/e21XDZXAX/lVcXFR2JvGde2 0n2XhKO5EQolrUd/6qM4b9ZzEEhaLTwnXaSpRc2O7gIjwQ6KR62WTACnb/VuO0oC wwKhZkJBzVVoAZAC5MdTReFXEjxs+BhnWUQ== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeffedrtdeggdeftddvjecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpuffrtefokffrpgfnqfghnecuuegr ihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenucfjug hrpefoggffhffvkfgjfhfutgesrgdtreerredtjeenucfhrhhomhepfdftohgsucfnrghn uggvrhhsfdcuoehrohgssegsohhtthhlvggurdgtohguvghsqeenucggtffrrghtthgvrh hnpeeitdfhhfdvfffhtedtgfevfefgueeggeduueekjeehieeggffhieevleeffeeufeen ucffohhmrghinhepghhithhhuhgsrdgtohhmnecuvehluhhsthgvrhfuihiivgeptdenuc frrghrrghmpehmrghilhhfrhhomheprhhosgessghothhtlhgvugdrtghouggvshdpnhgs pghrtghpthhtohepvddpmhhouggvpehsmhhtphhouhhtpdhrtghpthhtohepihhnthgvrh hnrghlsheslhhishhtshdrphhhphdrnhgvthdprhgtphhtthhopehhrghnshhkrhgvnhht vghlseihrghhohhordguvg X-ME-Proxy: Feedback-ID: ifab94697:Fastmail Received: by mailuser.phl.internal (Postfix, from userid 501) id 975B5182007A; Fri, 12 Sep 2025 18:37:35 -0400 (EDT) X-Mailer: MessagingEngine.com Webmail Interface Precedence: list list-help: list-post: List-Id: x-ms-reactions: disallow MIME-Version: 1.0 X-ThreadId: A2uTmm58H_Sg Date: Sat, 13 Sep 2025 00:37:08 +0200 To: "Hans Krentel" , internals@lists.php.net Message-ID: <2a34b4a4-a1f3-40d1-a005-49a91a31b07c@app.fastmail.com> In-Reply-To: <1757713032326.1442271469.4286265584@yahoo.de> References: <1757713032326.1442271469.4286265584@yahoo.de> Subject: Re: [PHP-DEV] merging r/w locks Content-Type: multipart/alternative; boundary=d344e2f8712840f082949697bf2016e3 From: rob@bottled.codes ("Rob Landers") --d344e2f8712840f082949697bf2016e3 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable On Fri, Sep 12, 2025, at 23:39, Hans Krentel wrote: >=20 >=20 >=20 > On Tuesday 09 September 2025 10:14:31 (+02:00), Rob Landers wrote: >=20 > > Hi internals, > >=20 > > Is there any hope to have https://github.com/php/php-src/pull/16565 = merged before 8.5? It's too late to address all the locks, but having it= as part of the ABI would be nice so we can start fixing them for 8.6/9.= 0. In FrankenPHP, if something takes a lock, it can significantly affect= performance. By using r/w locks instead of exclusive locks, we can use = shared locks when reading instead of exclusive locks. > >=20 > > =E2=80=94 Rob >=20 > My educated guess would be that environ is per process. >=20 > -- hakre >=20 Hi Hakre, We already solved the environment locks in FrankenPHP (which uses thread= s instead of processes in ZTS mode) by basically =E2=80=9Cdeleting=E2=80= =9D the built-in environment functions and replacing them. Environment a= ccess is not thread safe, and Go (the language of FrankenPHP) uses its o= wn locks around environment access. Thus we needed to prevent concurrent= access to the environment in the two runtimes (TSRM vs. Go). That part = of the PR will just help with other SAPI performance when using PHP comp= iled in ZTS mode. The main feature of the PR is not the environment locks, but the adding = of non-exclusive locks to TSRM. For example, there are TSRM locks in OPc= ache, but they=E2=80=99re only used *during writes* and *don=E2=80=99t p= rotect reads*. This can lead to very subtle bugs and crashes that we see= sporadically in FrankenPHP. By enabling r/w locks (the new tsrm_rwlock_= rlock in this PR), we can protect reads *and* writes, without degrading = existing performance. TSRM itself could use this as well, so that every time FrankenPHP spawns= a new PHP thread, it doesn=E2=80=99t need to contend for reading/writin= g globals during startup (and for dealing with cases where TSRM cache ca= n=E2=80=99t be used, which affects ALL global reads/writes if I understa= nd correctly =E2=80=94 which is possible I don=E2=80=99t). I believe there are several other instances that would benefit from r/w = locks as well, such as mysqlnd, but it has been awhile since I looked at= this, and I=E2=80=99m just going off notes. =E2=80=94 Rob --d344e2f8712840f082949697bf2016e3 Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: quoted-printable


On Fri, Sep 12, 2025, at 23:39, Hans Krentel wrote:


On Tuesday 09 September 2025 10:14:31 (+02:0= 0), Rob Landers wrote:

> Hi internals,
=
> Is there any hope to have https://github.com/php/php-s= rc/pull/16565 merged before 8.5? It's too late to address all the lo= cks, but having it as part of the ABI would be nice so we can start fixi= ng them for 8.6/9.0. In FrankenPHP, if something takes a lock, it can si= gnificantly affect performance. By using r/w locks instead of exclusive = locks, we can use shared locks when reading instead of exclusive locks.<= /div>
> =E2=80=94 Rob

My educated guess would be that environ is per process.
-- hakre


Hi Hakre,

We already solved the environment l= ocks in FrankenPHP (which uses threads instead of processes in ZTS mode)= by basically =E2=80=9Cdeleting=E2=80=9D the built-in environment functi= ons and replacing them. Environment access is not thread safe, and Go (t= he language of FrankenPHP) uses its own locks around environment access.= Thus we needed to prevent concurrent access to the environment in the t= wo runtimes (TSRM vs. Go). That part of the PR will just help with other= SAPI performance when using PHP compiled in ZTS mode.

The main feature of the PR is not the environment locks, but the= adding of non-exclusive locks to TSRM. For example, there are TSRM lock= s in OPcache, but they=E2=80=99re only used during writes an= d don=E2=80=99t protect reads. This can lead to very subtle bugs = and crashes that we see sporadically in FrankenPHP. By enabling r/w lock= s (the new tsrm_rwlock_rlock in this PR), we can protect reads a= nd writes, without degrading existing performance.

TSRM itself could use this as well, so that every time FrankenPH= P spawns a new PHP thread, it doesn=E2=80=99t need to contend for readin= g/writing globals during startup (and for dealing with cases where TSRM = cache can=E2=80=99t be used, which affects ALL global reads/writes if I = understand correctly =E2=80=94 which is possible I don=E2=80=99t).
=

I believe there are several other instances that wou= ld benefit from r/w locks as well, such as mysqlnd, but it has been awhi= le since I looked at this, and I=E2=80=99m just going off notes.

=E2=80=94 Rob
--d344e2f8712840f082949697bf2016e3--