Skip to content

Instantly share code, notes, and snippets.

@moznion
Created July 6, 2017 09:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save moznion/1495622ee883ac69ff82799ece0f401a to your computer and use it in GitHub Desktop.
Save moznion/1495622ee883ac69ff82799ece0f401a to your computer and use it in GitHub Desktop.
use v6.c;
use Crust::Request;
use JSON::Fast;
sub app($env) {
my $req = Crust::Request.new($env);
given $req.path-info {
when '/' {
my $q = $req.query-parameters<q>;
if (!$q) {
return 400, [], ["Missing mandatory parameter `q`"];
}
return 200, ['Content-Type' => 'application/json'], [to-json { echo => $q }];
}
default {
return 404, [], ["Not Found"];
}
}
}
@moznion
Copy link
Author

moznion commented Jul 6, 2017

$ crustup --server HTTP::Server::Tiny echo.p6w
$ wrk -t 100 -c 500 "http://localhost:5000/?q=hello"
Running 10s test @ http://localhost:5000/?q=hello
  100 threads and 500 connections
  Thread Stats   Avg      Stdev     Max   +/- Stdev
    Latency   348.78ms  311.42ms 977.82ms   80.00%
    Req/Sec     6.56      7.62    19.00     77.78%
  15 requests in 10.10s, 5.14KB read
  Socket errors: connect 0, read 517, write 0, timeout 0
Requests/sec:      1.49
Transfer/sec:     520.94B

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment