p5h / p5summit-2019

Perl 5 Summit
0 stars 0 forks source link

Concurrency #21

Open toddr opened 4 years ago

atoomic commented 4 years ago

this is the killer feature we probably really need...

leonerd commented 4 years ago

For posterity, a link to my slides from today's talk. Posterity might not find them too useful without my waffly words alongside them, but it's a start.

https://docs.google.com/presentation/d/1fc_-7ZSdnzeJ94nRxuQqy0zHce4hZYigRlYFp3HbQYo/edit?usp=sharing

leonerd commented 4 years ago

After a good walk out in town just now I realise I may have made a huge error in the whole of this discussion. I was presuming that people necessarily wanted multi-core processing of CPU-intensive work - e.g. computing lists of primes, being the canonical example.

It may be that people were more interested in concurrent IO tasks, say that of performing lots of parallel http fetches; something that can be easily handled by one CPU core in one interpreter thread. Doing that is so much simpler; something that already works right now from CPAN could be:

use Future::Utils qw( fmap_scalar );

my $ua = Net::Async::HTTP->new;
IO::Async::Loop->new->add( $ua );

my @URLs = (... list of 10,000 URLs);
my $f = fmap_scalar {
    my $url = $_;
    $ua->GET( $url )
} foreach => \@URLs, concurrent => 100;
my @pages = $f->get;

Here we've fetched 10k HTTP pages, concurrently with 100 in flight at once. In one thread of CPU. With current Perl - works back as far as 5.14, or maybe even 5.10.

Not wishing to trivialise it but if that's "all" we want, then maybe that's just a matter of a bit of CPAN module bundling?

Leont commented 4 years ago

After a good walk out in town just now I realise I may have made a huge error in the whole of this discussion. I was presuming that people necessarily wanted multi-core processing of CPU-intensive work - e.g. computing lists of primes, being the canonical example.

It may be that people were more interested in concurrent IO tasks, say that of performing lots of parallel http fetches; something that can be easily handled by one CPU core in one interpreter thread. Doing that is so much simpler; something that already works right now from CPAN could be:

I think we need both. While the asynchronous IO tasks is the more common one, it's multiprocessing that can't be done without core support.