Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:113578 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 1038 invoked from network); 16 Mar 2021 20:44:20 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 16 Mar 2021 20:44:20 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 61D781804D8 for ; Tue, 16 Mar 2021 13:38:11 -0700 (PDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) 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,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=3.4.2 X-Spam-Virus: No X-Envelope-From: Received: from mail-pf1-f169.google.com (mail-pf1-f169.google.com [209.85.210.169]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Tue, 16 Mar 2021 13:38:10 -0700 (PDT) Received: by mail-pf1-f169.google.com with SMTP id 18so9637793pfo.6 for ; Tue, 16 Mar 2021 13:38:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=AZAjhNcsjwgQTVYlUH/YeQQyMUytMOn7M/9Qb5QtVAU=; b=HdF3SKFT4vjK+cB0JNWThowvVpmwdrG9NbOXHmdQ2KmqjM+5OzhfB61QQrqggxnNsE 4zhOcge5xuA+SvQ++mltAU9wq0Y5Fv1DphKmoTppm4fnWYRtQGJGMoDDjC+AZCmUlJm6 JyxuVy/SPsosiL8CfBKVnxQdqWnK0ZFIZEVM8I+pU2LzkuXs8gGScJ7R+5PNzxTXGHjW iMxzwvFtQaq6UtvWWZ8pKdSCWVvmDf1Flc/Ux7LWAHqJ2FTQgB5KeSQ8KB7T2Fz2ucxq +9yqFsSqh5gpxEs+DNoMcO6zFSKid+2KoBa8FWC/j+eVKbMo03vNd5Y7mnraC9uiCEh2 MLOg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=AZAjhNcsjwgQTVYlUH/YeQQyMUytMOn7M/9Qb5QtVAU=; b=ov8aKRqqYCn5JfLa1dZjA9sq+dTzl6nyZy+JdqSn9KlCKaLnNqo8qHHeqXh+dD0JLh a0bwDFWBN0EFEAfClBE1YT7J28gDxNEwFPs3zvmESaGoX8BVvmoXQeZHeBNLrLI3bh4T 4m80/q7wrscdAAFm9UIVaTKaYPDXscd3eNlvzx0nBZwxRc0WuMRY+nLZC/xWSOYU0PLk 8Upaajw8K3tJkr9hA3rpjuRVpx25hdMqOhGFPPRl5mn09FMPIGzPW8/iU1tkvVWUDYIj tGUslYGeLOhvljWN2LOGovYfJLtCLttaBE9rJfCCL+IhCJMJfTowOkttoXyWSwI2LZz2 6WXg== X-Gm-Message-State: AOAM530KwhwK39KxrgZ7o2UNWFzwxq+QnM/Mp2EvxJWTX7Ap8Q8/0hNe K0wGgzboy8BNR1xQ3ORKJkTPRrmpsophiVXi4LI= X-Google-Smtp-Source: ABdhPJz1BQ7zbqpW0xR5zhGY3tggWr3DdsJLcAK4QeFb20SZvF+tGKmraXC5vnpbB1R/P61d6yVnzd6pCImaL8+PeUg= X-Received: by 2002:a62:3847:0:b029:202:ad05:4476 with SMTP id f68-20020a6238470000b0290202ad054476mr1139231pfa.67.1615927089047; Tue, 16 Mar 2021 13:38:09 -0700 (PDT) MIME-Version: 1.0 References: <70951423-5e77-c150-6dce-dd3c62f8dc8b@php.net> <0b994a60-7970-605b-1657-d6ee732690e5@gmx.de> <5C73A1DE-E563-4F69-B8C7-6506F81D7345@trowski.com> In-Reply-To: Date: Tue, 16 Mar 2021 20:37:57 +0000 Message-ID: To: Niklas Keller Cc: Aaron Piotrowski , "Christoph M. Becker" , Michael Wallner , php internals , Derick Rethans Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Subject: Re: [PHP-DEV] [VOTE] Fibers From: joshdifabio@gmail.com (Josh Di Fabio) Hi Niklas, On Tue, Mar 16, 2021 at 8:07 PM Niklas Keller wrote: > > Hey Josh, > >> >> > This is a very valid concern to have. However, this code won't simply = break if executed asynchronously. >> > It only breaks if the same method (or other methods making use of the = same state) is executed concurrently on that object. >> >> I understand this, but of course this will be common in programs where >> fibers are used, and the nature of this proposal means that fibers >> will potentially be highly insidious and quite unpredictable in their >> reach. > > > Concurrent operations on stateful, mutable objects are certainly a risk a= nd concurrency shouldn't be introduced without thinking about the consequen= ces. Care must be taken if objects are used across different fibers concurr= ently, unless you use global state, then you'll have a harder time adding c= oncurrency to your application. I think this is wishful thinking. Real world software uses code from lots of developers and vendors. We can never realistically know the internals of our whole codebase or read through every line of code in order to evaluate whether we think each library we are using has been designed with fiber support in mind. A solution which relies on this is wishful thinking. >> >> > If you can see the race condition here, you can probably also see the = race condition in the original snippet above. >> >> The difference is that in the second case, the developer has >> *explicitly opted into the underlying call being async*. I.e. they >> expect it, and can design with it in mind. > > > While the developer opted into async / non-blocking I/O, they still might= not have thought about concurrent operations on that same object. But at least you know that the developer *intends* for the code to be run with fibers. This is especially important for third party code. >> > Being able to use the type system is a concern the RFC solves, but tha= t's rather just nice-to-have. The relevant problem is the call stack pollut= ion or "What color is your function" problem. It simply doesn't make sense = for applications and libraries to offer an async and non-async interface fo= r everything. Due to the "What color is your function" problem, there can't= be a gradual migration to non-blocking I/O, which will mostly result in no= n-blocking I/O simply not being supported by the majority of libraries, mak= ing it basically non-viable in PHP. >> >> Perhaps we could rather make fibers *opt in* at the *callsite* >> (similar to goroutine calls) in order to prevent functions >> unexpectedly being executed asynchronously due to faraway changes. >> This would be safe and predictable while also avoiding the "What color >> is your function" problem. For example >> >> private function capturePayment(): void >> { >> $paymentRequest =3D preparePaymentRequest($this->currentOrder); >> // allow, but don't require, the underlying call to use >> fibers. Callers higher up the stack would also have to opt in >> async $this->paymentGateway->capturePayment($paymentRequest); >> $this->currentOrder->setTransactionId($paymentRequest->getTransa= ctionId()); >> } >> >> With this approach, APIs we'd avoid the "what colour is your function" >> problem without sacrificing the safety that we really need in e.g. >> ecommerce. > > > This doesn't really avoid the "what color is your function" problem, as y= ou'd have to mark all function calls with "async" then, eventually resultin= g in every PHP function call having to be prefixed with "async". I certainly don't think we should expect to be in a position where all functions are async. Business logic is (should generally be) in pure, side effect free functions which, by definition, are not doing any IO. The point is to avoid accidentally making that code async. To clarify, my suggestion is that a keyword at the callsite would allow the callsite to opt in to fibers in the called function if that function supports fibers, and if we are currently within a fiber context, otherwise it would behave synchronously. > Rather than marking methods with "synchronized" as mentioned before, it m= ight be more feasible to mark methods with a keyword if they allow concurre= nt operations. I'll have to research which options are viable. > > Best, > Niklas I do appreciate your time, and I'm sorry for not asking these questions during the discussion period. I'll leave it here unless others feel the discussion is worth continuing. Thanks