Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:128696 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 F0F5B1A00BC for ; Fri, 12 Sep 2025 23:15:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1757718854; bh=vMFSQRLTJKL4eT1mLo38907YpDtG63AUd2dcYayrLGo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ikt58flbPfVOp1fVBT195/7H9xc5+G+pGqCG0bigstCzNrrlsRbxC0QihsqKcUqyd 8npvkI66rwC4BYyvhPtWRylbzy0O53qNrQ7P9QVTWkZisO1kIsFTUuGr3fWlhPnWhX ZzEPtdta2q/t/86O9nman260593h6coL0qGVjnhI8rhY/9kSxSUy/y95sgZKkW1KJL Q8hTYiXZbI//cpv+FJpTPnroZTzD17recT4NmQDOCI6ugpPQTIdyQ1nGzmChFCskYj Ibbnl1eSF23dyJcLSDhm/m/7OPEtiuc9awunZ0Z43NtAEloEbtnf+GkchnfEKy00c9 oxKoTAyXTn0KA== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 7F61E18004E for ; Fri, 12 Sep 2025 23:14:13 +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.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_PASS,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=4.0.1 X-Spam-Virus: No X-Envelope-From: Received: from sonic313-21.consmr.mail.ir2.yahoo.com (sonic313-21.consmr.mail.ir2.yahoo.com [77.238.179.188]) (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 23:14:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.de; s=s2048; t=1757718927; bh=vMFSQRLTJKL4eT1mLo38907YpDtG63AUd2dcYayrLGo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject:Reply-To; b=RDSg/zSum2oZ0EBsVYRTUrOeaSBPWhKAtaRUOsPr7b+AbhZHINflSsFth1zzXReDGWNv+LcgFbJrQmrM1PDI+mcJYB/0yyG7yjO5O5+c0kQ+edL4fWDsEugUNPiV6fJceaGi/uKUKQS9jLtcmLJPS26gr8NzC+xAYafZgeHXdkfaMG4ye0X73S5c0o1NsBskuwQZqOjVRclTbIkvdjS3abNFoBB0FsNCbSQuyvYgiClJphIN0j2DhDV9v5cvUr1VOd0daaFCpWs43tgmlQ+MHWAC8V7BomwONo2AGgM7QHxZyhlLm02wDlkAi6ta/qrlgblW3exyBuGYp6Miwbnf7w== X-SONIC-DKIM-SIGN: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1757718927; bh=KAUlVg6M6l/Wb8dzSiolrC8e38QrSu8XA05l3rl7TxC=; h=X-Sonic-MF:From:To:Subject:Date:From:Subject; b=VxbeVSk2/JqIr1PQzMNIKB/hcCLLODxHIXTf06mH6axx+BidofHQhOjsgasQvAS/m7TmdwLlEvXuH2ZcWdT1dLzt75vbnky9bybmz8Rn56+U0XD5oxyhcZHBCQ1POzYS+uRSZQTBxU9DTH3QOkiYX87qh9QwIRxu16ePa4rD9CIx8WtGB3nWiLjvpoHP7TOBpx3A28H8tczcEtu2J9EmOjOvmMGpvnnLdKvOEDTkV7Qsj7q6rOiIIyto8bTx+pCPP4y7REgi0gwX7NdRgETJ6uf/ubtXD/nDrPxuXWZFzkA8K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orO1NxeqoMRdO98HzsZAHmInNp GBefzfmgU5Ulq5fe.P_6DsaiAxAq6o9XdS_WqEd8AcgOXtLtFxa6chsguWRjwGZd6aZdk.GkAzUa 99dFx8waXwwz9BaeIfHL15kx9q1HmXu0V_H8CdRtrEbVGL_PHzgo4lLTaWG8FlM958dJr1z7HMpX mIoqxdpqtQMyGnnoJKItdytax3QEO0u3uw16LfX690MkhJr5_AmHOOlKmGbMHiwgnM9Q2 X-Sonic-MF: X-Sonic-ID: 96af48e7-1697-49ed-bebf-0a28c902dd11 Received: from sonic.gate.mail.ne1.yahoo.com by sonic313.consmr.mail.ir2.yahoo.com with HTTP; Fri, 12 Sep 2025 23:15:27 +0000 Received: by hermes--production-ir2-7d8c9489f-fttzq (Yahoo Inc. Hermes SMTP Server) with ESMTPA ID 38c8ecc5f6bf081fe848344f8497a438; Fri, 12 Sep 2025 23:15:26 +0000 (UTC) Content-Type: text/plain; charset=utf-8 Message-ID: <1757718325216.2367189491.2395335932@yahoo.de> To: rob@bottled.codes Cc: internals@lists.php.net Subject: Re: [PHP-DEV] merging r/w locks Date: Fri, 12 Sep 2025 23:15:26 +0000 In-Reply-To: <2a34b4a4-a1f3-40d1-a005-49a91a31b07c@app.fastmail.com> References: <2a34b4a4-a1f3-40d1-a005-49a91a31b07c@app.fastmail.com> X-Mailer: Vivaldi Mail User-Agent: Vivaldi Mail/7.5.3735.66 Content-Transfer-Encoding: quoted-printable Precedence: list list-help: list-post: List-Id: x-ms-reactions: disallow MIME-Version: 1.0 From: hanskrentel@yahoo.de (Hans Krentel) On Saturday 13 September 2025 00:37:08 (+02:00), Rob Landers wrote: >=20 >=20 > 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 >=20 > Hi Hakre, >=20 > We already solved the environment locks in FrankenPHP (which uses threads= instead of processes in ZTS mode) by basically =E2=80=9Cdeleting=E2=80=9D = the built-in environment functions and replacing them. Environment access = is not thread safe, and Go (the language of FrankenPHP) uses its own 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 compiled in ZTS mode.= Well if you go go-routine level read-only this is probably safe, but it = _probably_ depends on what you expect to find on the top of _SERVER per = each SAPI. IIRC for FrankenPHP this is EMBED via CGO. > > 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 = OPcache, but they=E2=80=99re only used *during writes* and *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 locks (the new = tsrm_rwlock_rlock in this PR), we can protect reads *and* writes, without = degrading existing performance. If you see a benefit and it's across SAPIs -- why not consider it? If it's = that stable and works under any process model that folllows the C semantics= of GO (and PHP), this should be portable/transparent, shouldn't it? >=20 > 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/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). >=20 > 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. I don't know those API/ABI good enough, but perhaps Johannes could know on = spot for your question. >=20 > =E2=80=94 Rob -- hakre