[Southampton-pm] Perl Mongers meetup
Iain Campbell
i.campbell at mac.com
Thu Dec 3 07:09:44 PST 2015
Thanks, mate. I’ll have a tinker about with this and come back with a barrage of questions, no doubt. :)
> On 3 Dec 2015, at 13:56, Vytautas D <vytdau at gmail.com> wrote:
>
> Iain,
> See dummy Coro example, hopefully code is self explanatory. Here are
> two forever loops, and they cede automatically on blocking calls i.e.
> sleep and rouse_wait.
>
> #!/usr/bin/perl
>
> use 5.14.0;
> use warnings;
>
> use Coro;
> use Coro::AnyEvent;
> use AnyEvent;
> use AnyEvent::HTTP;
>
> $AnyEvent::HTTP::MAX_PER_HOST = 10;
>
> # Some dummy stats
> my $s = 0; # succeeded
> my $f = 0; # failed
> my $round = 0;
>
> # Track time passed
> my $start = AnyEvent->now();
>
> my $watcher = Coro::async{
> while(1) {
> Coro::AnyEvent::sleep( 5 );
> my $end = AnyEvent->now();
> my $lasted = $end - $start;
>
> say "s/f: $s/$f in $lasted, ", ($s+$f)/$lasted, "req/s";
>
> # reset stats
> $s = 0;
> $f = 0;
>
> # reset start time
> $start = $end;
> }
> };
>
> while (1) {
> my $cb = Coro::rouse_cb();
> AnyEvent::HTTP::http_request(
> GET => "http://google.com",
> "persistent" => "1",
> "keepalive" => "1",
> $cb,
> );
> my ( $body, $hdr ) = Coro::rouse_wait($cb);
>
> if ( $hdr->{Status} =~ /^2/ ) {
> $s++;
> } else {
> $f++;
> }
> }
>
> On Wed, Dec 2, 2015 at 8:07 PM, Vytautas D <vytdau at gmail.com> wrote:
>> Warning to anyone coming - it took me 20mins to find a parking...
>>
>> On 2 Dec 2015 13:52, "GARLAND DUNCAN" <duncan.garland at ntlworld.com> wrote:
>>>
>>>
>>>
>>>> On 02 December 2015 at 12:09 Anton Oussik <antonoussik at gmail.com> wrote:
>>>>
>>>>
>>>> Will happen tonight at the platform tavern, I plan to be there from
>>>> around
>>>> 7. Hope to discuss the upcoming workshop and Perl 6. See you there!
>>>> _______________________________________________
>>>> Southampton-pm mailing list
>>>> Southampton-pm at pm.org
>>>> http://mail.pm.org/mailman/listinfo/southampton-pm
>>>
>>>
>>> I'll be there
>>> _______________________________________________
>>> Southampton-pm mailing list
>>> Southampton-pm at pm.org
>>> http://mail.pm.org/mailman/listinfo/southampton-pm
> _______________________________________________
> Southampton-pm mailing list
> Southampton-pm at pm.org
> http://mail.pm.org/mailman/listinfo/southampton-pm
More information about the Southampton-pm
mailing list