Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:113062 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 32732 invoked from network); 3 Feb 2021 15:56:50 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 3 Feb 2021 15:56:50 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id B27FC1804B1 for ; Wed, 3 Feb 2021 07:40:18 -0800 (PST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp4.php.net X-Spam-Level: * X-Spam-Status: No, score=1.8 required=5.0 tests=BAYES_05,BODY_8BITS, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,RDNS_DYNAMIC,SPF_HELO_PASS,SPF_PASS autolearn=no autolearn_force=no version=3.4.2 X-Spam-Virus: No X-Envelope-From: Received: from qq.com (out203-205-251-60.mail.qq.com [203.205.251.60]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Wed, 3 Feb 2021 07:40:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=qq.com; s=s201512; t=1612366814; bh=IaTBlRT98blKzKbyLJZS6+exxPhWhZS5fZrOuG7DjVc=; h=Subject:From:In-Reply-To:Date:Cc:References:To; b=AlXZlrCEWJZweHe8ENoZJb8Hf7NTPvTSqKhdlhQQLEqZMbDPRVpCuVpMHZqOhjSjR aibp8SYA5dT32gm5KwieCcCe8zG6CYWPrNjWTIXy7ZfpcKnP86gqtrEhh0t9i/4BkZ cVVNgXn8kVkj+Vle+wLUN6tBpf5idQ3wDcm48R4c= Received: from [127.0.0.1] ([115.211.227.208]) by newxmesmtplogicsvrszc7.qq.com (NewEsmtp) with SMTP id A0C12E10; Wed, 03 Feb 2021 23:40:12 +0800 X-QQ-mid: xmsmtpt1612366812t16hwy5f7 Message-ID: X-QQ-XMAILINFO: N2pVADwlTVCgM0tsCOhvrhWkPyDXVAjnUYv5oJp1n+Qkh4JaWP/23xd6Ohyn8L c0JBCi6SZUUsfv3Z545jqnvcumP57Y7ztIystZmejgB4LvDTZ+H9jrHIgwOrje6R74de6CLmnx90 a7BVg3INRNMG4zK+dAmZSTdSF7+Q8lDdOsvaXrKcBMIH2xSVIfS6bqoBF9+e0I4abYsyV1T5jBJd c6qnZhPE8vrCaGLuD5UohCnGERP2OqH1J4U0kvK7W6W70cOO14qneflpVPOUxLt9sibp9BRdWann E5z8/nzSncRnQ4krT/gx6k/c6vJ13fsfyTZmJbY770l0LVtRIRq8Fy8pPp3fgOFy0AacmguMkyQL Qg5Uqn0MFxTwY7mx8UBvObh+Pv/oH6bm7rcoFpx5SSWXH9UNBGw/4gbjIXwAMK6TGJsIUtuEioUr K7LP9ZKFJI6mXs68dsDy1tLM5weICrS8R8fnAExpe49G18hzVaFkZ+zhXEt+ItjhzWVC+b+zkuy6 UctjeNOpayyxb9wqc1NqleqoWjSwgy6oBywup4afD8T1hqwqfRyNxdPwD94Qf6D5jCDxFwpk1TsW OmdfyeeGWv7eTJPRJBs33KdZ+tIwI7qKYJwFPkUAPN2HRsLp3BRPo6qZMS18omtHR2EAY53zleK3 1a9v8iiMW4Ib722Dkb4NvXbM51MLR/1iTlr/INW4fv69tWd93fx3dKkkzEXfNPvndQOUctu7bfnx 8kLTZKJR7TGmNmxKrNQ02/rk4pdxuBPL6b4kcuX8vtQoCmnGj5sEotLYOiF6EUHkeIbSrNMFQMQh IyFxcy3QjKUg== Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 13.4 \(3608.120.23.2.4\)) In-Reply-To: Date: Wed, 3 Feb 2021 23:39:35 +0800 Cc: php internals Content-Transfer-Encoding: quoted-printable X-OQ-MSGID: References: To: Aaron Piotrowski X-Mailer: Apple Mail (2.3608.120.23.2.4) Subject: Re: [PHP-DEV] [RFC] Fibers From: twose@qq.com (twosee) > 2020=E5=B9=B412=E6=9C=8818=E6=97=A5 =E4=B8=8A=E5=8D=8812:30=EF=BC=8CAaro= n Piotrowski =E5=86=99=E9=81=93=EF=BC=9A >=20 > Hello everyone! >=20 > I would like to introduce an RFC for adding full-stack fibers to PHP: = https://wiki.php.net/rfc/fibers >=20 > Fibers are primarily used to implement green-threads or coroutines for = asynchronous I/O. Fibers are similar to threads, except fibers exist = within a single thread and require cooperative scheduling of the fibers = by the process. Since fibers do not require a full CPU context switch, = they are lightweight and more performant than multi-processing or = threading for awaiting I/O. >=20 > An implementation as an extension is at = https://github.com/amphp/ext-fiber >=20 > Fibers are a complex feature. The RFC contains many examples and links = to code using fibers to help explain and demonstrate what is possible, = however I=E2=80=99m certain many more questions and concerns will arise. = Looking forward to feedback and discussion. >=20 > Aaron Piotrowski > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: https://www.php.net/unsub.php >=20 >=20 Hi there, So glad to see that the RFC of Fiber is back on the agenda. Let me introduce myself first. I'm a very active contributor to Swoole = and also a core member of the Swoole developing group. Though Swoole has not been mentioned in the RFC, Swoole has already = worked for async/coroutine feature for many years and always doing best = in order to be merged into php-src. It's extremely difficult to merge = Swoole into php-src fully because Swoole is systematic and complex. Even = the coroutine is a core but also a tiny part of Swoole.=20 In recent years, Swoole has been committed to improving stability and = overcoming technical problems. It can be said that the current Swoole is = very close to the ideal status. What's more, Swoole has been applied = widely by advanced enterprises in China. It has been verified by a large = amount of real-world applying. We may have more practical experience in = many details of the implementation of coroutine technology For the core of Fiber, the context switching of C stack and PHP VM = stack, there is no more obvious problem. But there is somewhere worth = improving, indeed. Furthermore, we may do more context switching, since = Swoole may yield from PHP internal function, which would make the "@" = not work. As we could see, the main controversy is what about the FiberScehduler. = I think it is designed for the amphp, however, it makes code hard to be = comprehended, and it was unnecessary if we just want a minimum coroutine = implementation. Just having creation and switching is enough for a minimum coroutine = implementation. So did the last Fiber proposal. The implementation of = the scheduler is still debatable. Otherwise, compared with the previous Fiber proposal, the most valuable = change in the new Fiber proposal is the introduction of C stack = coroutine technology.=20 In my opinion, the goal of the new Fiber proposal is not that ambitious. = It just eliminates the stack pollution caused by Promise. This makes the = style of PHP coroutine neither like the Nodejs which represents the pure = stackless coroutine, nor the Lua and Golang which represent pure stack = coroutine. Once PHP has a stack coroutine like Fiber, we can do more than what we = can do now. Since we can interrupt from PHP internal functions, then we = can replace all the implementation of PHP blocking functions, such as = sleep(), and we can also replace php_stream so that we can change the = implementation of PDO, mysqli, and phpredis into a coroutine way, and we = can also make curl become a coroutine version through libcurl's support = for multiplexing. In fact, many years ago, amphp-liked solutions were very popular in the = Chinese PHP community. But they were replaced by Swoole, eventually.=20 Performance is one of the reasons. Because, indeed, parsing protocol by = PHP is disadvantaged compared to parsing by C. Though the amphp-liked = solutions dose expand the PHP's capabilities, the performance is not = that satisfactory. However, Swoole performs like other static languages.=20= On another hand, the replacement cost. What has been proved is that most = PHP programmers want to continue to use common clients such as PDO, = mysqli, phpredis, and curl, and the great PHP package and library = ecosystem based on these clients is hard to replace. The cost of moving = a modern PHP application to Swoole is so low which was unimaginable = before. Many success cases there in the community. So what I want to explain is that once the PHP core is ready to accept = the Fiber proposal, everyone will start to think, what is the next? = Therefore, what Fiber's goal is what the Fiber extension is designed for = are particularly important. What I really care about is - does it just = simply eliminates the pollution of the stack caused by Promise, or it = plans to improve the performance of PHP applications by a hundredfold at = a low cost as Swoole did. Regards, Twosee=