Async-Microservice
view release on metacpan or search on metacpan
GET_sleep
https://time.meon.eu/v1/sleep?duration=2.5
This is the only response method processed in parallel (the other ones
are pure CPU-bound) that sleeps for a given (or random) number of
seconds and only then returns the request response with when it started
and how long it took. Normally this is the same as what is in the
duration parameter, but in case the server is overloaded with requests,
the event loop may call the timer handler much later than the duration.
Try:
ab -n 1000 -c 500 http://localhost:8085/v1/sleep?duration=3
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 259 432.8 21 1033
Processing: 3001 3090 72.5 3061 3253
Waiting: 3001 3090 72.5 3061 3253
Total: 3022 3349 394.1 3155 4065
lib/Async/Microservice/Time.pm view on Meta::CPAN
=head3 GET_sleep
L<https://time.meon.eu/v1/sleep?duration=2.5>
This is the only response method processed in parallel (the other ones are
pure CPU-bound) that sleeps for a given (or random) number of seconds and
only then returns the request response with when it started and how long
it took. Normally this is the same as what is in the duration parameter,
but in case the server is overloaded with requests, the event loop may call the
timer handler much later than the duration. Try:
ab -n 1000 -c 500 http://localhost:8085/v1/sleep?duration=3
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 259 432.8 21 1033
Processing: 3001 3090 72.5 3061 3253
Waiting: 3001 3090 72.5 3061 3253
Total: 3022 3349 394.1 3155 4065
Then try to run together with 100% CPU load:
lib/Async/MicroserviceReq.pm view on Meta::CPAN
has 'request_timeout' => ( is => 'ro', isa => 'Num', required => 1 );
has '_warn_running_too_long' => (
is => 'ro',
isa => 'ArrayRef',
lazy => 1,
builder => '_build_warn_running_too_long'
);
after 'BUILD' => sub {
my ($self) = @_;
$self->_warn_running_too_long; # init timer
return;
};
sub _build_base_url {
my ($self) = @_;
return URI->new('/') if !$self->using_frontend_proxy;
my $https_on = '';
$https_on = $self->headers->header('HTTP_X_FORWARDED_HTTPS')
if $self->headers->header('HTTP_X_FORWARDED_HTTPS');
lib/Async/MicroserviceReq.pm view on Meta::CPAN
$redirect_host_port = $redirect_host . ':' . $redirect_port;
}
return URI->new( $url_scheme . '://' . $redirect_host_port . '/' );
}
sub _build_warn_running_too_long {
my ($o_self) = @_;
weaken( my $self = $o_self );
return AnyEvent->timer(
'after' => $self->request_timeout,
'interval' => $self->request_timeout,
'cb' => sub {
$log->errorf(
'request %s %s running too long for %d seconds',
$self->method, $self->path, ( time - $self->request_start ),
);
},
);
}
( run in 1.477 second using v1.01-cache-2.11-cpan-adec679a428 )