Skip to content

Instantly share code, notes, and snippets.

@IvanChepurnyi
Last active April 29, 2021 12:33
Show Gist options
  • Save IvanChepurnyi/6ebd90f4cb14766e5f8ff080783260d0 to your computer and use it in GitHub Desktop.
Save IvanChepurnyi/6ebd90f4cb14766e5f8ff080783260d0 to your computer and use it in GitHub Desktop.
Benchmark HTTP service
{
"require": {
"amphp/http-server": "^2.1"
}
}
<?php
require __DIR__ . '/../vendor/autoload.php';
use Amp\Http\Server\RequestHandler\CallableRequestHandler;
use Amp\Http\Server\HttpServer;
use Amp\Http\Server\Request;
use Amp\Http\Server\Response;
use Amp\Http\Status;
use Amp\Socket\Server;
use Psr\Log\NullLogger;
Amp\Loop::run(function () {
$sockets = [
Server::listen("0.0.0.0:8888"),
Server::listen("[::]:8888"),
];
$counter = 0;
$options = (new \Amp\Http\Server\Options())
->withoutCompression()
->withConnectionsPerIpLimit(10000)
->withConnectionLimit(10000)
->withoutHttp2Upgrade()
->withoutPush()
->withoutDebugMode()
->withoutRequestLogContext()
;
$server = new HttpServer($sockets, new CallableRequestHandler(static function (Request $request) use (&$counter) {
$counter += 1;
return new Response(Status::OK, [
"content-type" => "text/plain; charset=utf-8"
], sprintf("Hey you are the %d hit", $counter));
}), new NullLogger, $options);
yield $server->start();
// Stop the server gracefully when SIGINT is received.
// This is technically optional, but it is best to call Server::stop().
Amp\Loop::onSignal(SIGINT, function (string $watcherId) use ($server) {
Amp\Loop::cancel($watcherId);
yield $server->stop();
});
});
wrk -c 500 -d 30s -t 12 -R 20k -L http://localhost:8888
Running 30s test @ http://localhost:8888
12 threads and 500 connections
Thread calibration: mean lat.: 456.139ms, rate sampling interval: 3485ms
Thread calibration: mean lat.: 458.787ms, rate sampling interval: 3125ms
Thread calibration: mean lat.: 294.161ms, rate sampling interval: 1654ms
Thread calibration: mean lat.: 391.126ms, rate sampling interval: 3123ms
Thread calibration: mean lat.: 325.404ms, rate sampling interval: 2699ms
Thread calibration: mean lat.: 359.069ms, rate sampling interval: 2533ms
Thread calibration: mean lat.: 72.867ms, rate sampling interval: 222ms
Thread calibration: mean lat.: 282.298ms, rate sampling interval: 2017ms
Thread calibration: mean lat.: 323.637ms, rate sampling interval: 2574ms
Thread calibration: mean lat.: 390.142ms, rate sampling interval: 3031ms
Thread calibration: mean lat.: 359.098ms, rate sampling interval: 2983ms
Thread calibration: mean lat.: 436.261ms, rate sampling interval: 3827ms
Thread Stats Avg Stdev Max +/- Stdev
Latency 393.08ms 703.12ms 2.89s 85.17%
Req/Sec 1.67k 49.23 1.86k 92.68%
Latency Distribution (HdrHistogram - Recorded Latency)
50.000% 86.65ms
75.000% 111.55ms
90.000% 1.65s
99.000% 2.73s
99.900% 2.86s
99.990% 2.88s
99.999% 2.89s
100.000% 2.89s
Detailed Percentile spectrum:
Value Percentile TotalCount 1/(1-Percentile)
0.902 0.000000 1 1.00
31.551 0.100000 39698 1.11
49.791 0.200000 79358 1.25
63.327 0.300000 119010 1.43
75.711 0.400000 158721 1.67
86.655 0.500000 198411 2.00
90.751 0.550000 218118 2.22
95.359 0.600000 238179 2.50
100.479 0.650000 257795 2.86
105.791 0.700000 277847 3.33
111.551 0.750000 297501 4.00
149.631 0.775000 307346 4.44
452.863 0.800000 317261 5.00
761.343 0.825000 327170 5.71
1075.199 0.850000 337116 6.67
1342.463 0.875000 347039 8.00
1496.063 0.887500 351963 8.89
1651.711 0.900000 356928 10.00
1806.335 0.912500 361883 11.43
1965.055 0.925000 366850 13.33
2119.679 0.937500 371806 16.00
2191.359 0.943750 374315 17.78
2234.367 0.950000 376853 20.00
2312.191 0.956250 379283 22.86
2387.967 0.962500 381734 26.67
2465.791 0.968750 384271 32.00
2504.703 0.971875 385488 35.56
2537.471 0.975000 386676 40.00
2576.383 0.978125 387911 45.71
2615.295 0.981250 389137 53.33
2656.255 0.984375 390404 64.00
2676.735 0.985938 390996 71.11
2693.119 0.987500 391618 80.00
2709.503 0.989062 392246 91.43
2729.983 0.990625 392855 106.67
2752.511 0.992188 393470 128.00
2760.703 0.992969 393799 142.22
2777.087 0.993750 394155 160.00
2785.279 0.994531 394466 182.86
2799.615 0.995313 394727 213.33
2807.807 0.996094 395020 256.00
2815.999 0.996484 395211 284.44
2824.191 0.996875 395336 320.00
2830.335 0.997266 395501 365.71
2834.431 0.997656 395726 426.67
2838.527 0.998047 395814 512.00
2842.623 0.998242 395871 568.89
2848.767 0.998437 395988 640.00
2850.815 0.998633 396042 731.43
2854.911 0.998828 396126 853.33
2856.959 0.999023 396183 1024.00
2861.055 0.999121 396250 1137.78
2863.103 0.999219 396297 1280.00
2863.103 0.999316 396297 1462.86
2869.247 0.999414 396345 1706.67
2875.391 0.999512 396391 2048.00
2877.439 0.999561 396416 2275.56
2877.439 0.999609 396416 2560.00
2879.487 0.999658 396472 2925.71
2879.487 0.999707 396472 3413.33
2879.487 0.999756 396472 4096.00
2881.535 0.999780 396514 4551.11
2881.535 0.999805 396514 5120.00
2881.535 0.999829 396514 5851.43
2881.535 0.999854 396514 6826.67
2883.583 0.999878 396531 8192.00
2883.583 0.999890 396531 9102.22
2883.583 0.999902 396531 10240.00
2885.631 0.999915 396567 11702.86
2885.631 0.999927 396567 13653.33
2885.631 0.999939 396567 16384.00
2885.631 0.999945 396567 18204.44
2885.631 0.999951 396567 20480.00
2885.631 0.999957 396567 23405.71
2885.631 0.999963 396567 27306.67
2885.631 0.999969 396567 32768.00
2885.631 0.999973 396567 36408.89
2885.631 0.999976 396567 40960.00
2885.631 0.999979 396567 46811.43
2885.631 0.999982 396567 54613.33
2885.631 0.999985 396567 65536.00
2885.631 0.999986 396567 72817.78
2885.631 0.999988 396567 81920.00
2885.631 0.999989 396567 93622.86
2885.631 0.999991 396567 109226.67
2885.631 0.999992 396567 131072.00
2885.631 0.999993 396567 145635.56
2885.631 0.999994 396567 163840.00
2885.631 0.999995 396567 187245.71
2885.631 0.999995 396567 218453.33
2885.631 0.999996 396567 262144.00
2885.631 0.999997 396567 291271.11
2885.631 0.999997 396567 327680.00
2885.631 0.999997 396567 374491.43
2887.679 0.999998 396568 436906.67
2887.679 1.000000 396568 inf
#[Mean = 393.080, StdDeviation = 703.122]
#[Max = 2885.632, Total count = 396568]
#[Buckets = 27, SubBuckets = 2048]
----------------------------------------------------------
589713 requests in 30.02s, 107.31MB read
Socket errors: connect 0, read 0, write 0, timeout 34
Requests/sec: 19644.69
Transfer/sec: 3.57MB
wrk -c 500 -d 30s -t 12 -R 20k -L http://localhost:8888
Running 30s test @ http://localhost:8888
12 threads and 500 connections
Thread calibration: mean lat.: 436.566ms, rate sampling interval: 1505ms
Thread calibration: mean lat.: 403.223ms, rate sampling interval: 1480ms
Thread calibration: mean lat.: 438.928ms, rate sampling interval: 1533ms
Thread calibration: mean lat.: 435.329ms, rate sampling interval: 1527ms
Thread calibration: mean lat.: 418.367ms, rate sampling interval: 1504ms
Thread calibration: mean lat.: 452.697ms, rate sampling interval: 1540ms
Thread calibration: mean lat.: 456.284ms, rate sampling interval: 1542ms
Thread calibration: mean lat.: 405.498ms, rate sampling interval: 1465ms
Thread calibration: mean lat.: 519.788ms, rate sampling interval: 2658ms
Thread calibration: mean lat.: 479.900ms, rate sampling interval: 1628ms
Thread calibration: mean lat.: 548.088ms, rate sampling interval: 2967ms
Thread calibration: mean lat.: 562.105ms, rate sampling interval: 3217ms
Thread Stats Avg Stdev Max +/- Stdev
Latency 1.75s 581.40ms 4.09s 69.04%
Req/Sec 1.53k 25.08 1.60k 74.05%
Latency Distribution (HdrHistogram - Recorded Latency)
50.000% 1.74s
75.000% 2.12s
90.000% 2.40s
99.000% 3.53s
99.900% 3.92s
99.990% 4.07s
99.999% 4.09s
100.000% 4.09s
Detailed Percentile spectrum:
Value Percentile TotalCount 1/(1-Percentile)
760.319 0.000000 3 1.00
997.375 0.100000 36379 1.11
1200.127 0.200000 72692 1.25
1374.207 0.300000 108959 1.43
1560.575 0.400000 145263 1.67
1744.895 0.500000 181803 2.00
1824.767 0.550000 199805 2.22
1908.735 0.600000 217972 2.50
1987.583 0.650000 236230 2.86
2068.479 0.700000 254474 3.33
2117.631 0.750000 272889 4.00
2146.303 0.775000 281587 4.44
2168.831 0.800000 290937 5.00
2205.695 0.825000 299668 5.71
2271.231 0.850000 308806 6.67
2338.815 0.875000 317820 8.00
2377.727 0.887500 322660 8.89
2398.207 0.900000 327256 10.00
2410.495 0.912500 331435 11.43
2424.831 0.925000 335932 13.33
2572.287 0.937500 340493 16.00
2674.687 0.943750 342757 17.78
2770.943 0.950000 345022 20.00
2867.199 0.956250 347271 22.86
2967.551 0.962500 349539 26.67
3069.951 0.968750 351810 32.00
3127.295 0.971875 352970 35.56
3186.687 0.975000 354110 40.00
3248.127 0.978125 355228 45.71
3313.663 0.981250 356350 53.33
3383.295 0.984375 357493 64.00
3422.207 0.985938 358077 71.11
3459.071 0.987500 358621 80.00
3504.127 0.989062 359198 91.43
3549.183 0.990625 359768 106.67
3596.287 0.992188 360332 128.00
3620.863 0.992969 360619 142.22
3645.439 0.993750 360890 160.00
3672.063 0.994531 361181 182.86
3700.735 0.995313 361461 213.33
3733.503 0.996094 361744 256.00
3751.935 0.996484 361885 284.44
3768.319 0.996875 362028 320.00
3790.847 0.997266 362172 365.71
3813.375 0.997656 362316 426.67
3837.951 0.998047 362447 512.00
3852.287 0.998242 362526 568.89
3866.623 0.998437 362587 640.00
3889.151 0.998633 362663 731.43
3907.583 0.998828 362733 853.33
3926.015 0.999023 362803 1024.00
3936.255 0.999121 362840 1137.78
3942.399 0.999219 362872 1280.00
3956.735 0.999316 362907 1462.86
3979.263 0.999414 362945 1706.67
3991.551 0.999512 362980 2048.00
3999.743 0.999561 362996 2275.56
4003.839 0.999609 363014 2560.00
4016.127 0.999658 363032 2925.71
4030.463 0.999707 363056 3413.33
4034.559 0.999756 363069 4096.00
4038.655 0.999780 363075 4551.11
4040.703 0.999805 363086 5120.00
4042.751 0.999829 363094 5851.43
4052.991 0.999854 363102 6826.67
4063.231 0.999878 363112 8192.00
4065.279 0.999890 363122 9102.22
4065.279 0.999902 363122 10240.00
4067.327 0.999915 363129 11702.86
4067.327 0.999927 363129 13653.33
4073.471 0.999939 363132 16384.00
4081.663 0.999945 363135 18204.44
4087.807 0.999951 363138 20480.00
4089.855 0.999957 363147 23405.71
4089.855 0.999963 363147 27306.67
4089.855 0.999969 363147 32768.00
4089.855 0.999973 363147 36408.89
4089.855 0.999976 363147 40960.00
4089.855 0.999979 363147 46811.43
4091.903 0.999982 363154 54613.33
4091.903 1.000000 363154 inf
#[Mean = 1747.760, StdDeviation = 581.399]
#[Max = 4089.856, Total count = 363154]
#[Buckets = 27, SubBuckets = 2048]
----------------------------------------------------------
546165 requests in 30.02s, 99.38MB read
Requests/sec: 18193.75
Transfer/sec: 3.31MB
wrk -c 500 -d 30s -t 12 -R 20k -L http://localhost:8888
Running 30s test @ http://localhost:8888
12 threads and 500 connections
Thread calibration: mean lat.: 716.437ms, rate sampling interval: 4317ms
Thread calibration: mean lat.: 738.529ms, rate sampling interval: 4689ms
Thread calibration: mean lat.: 702.372ms, rate sampling interval: 5128ms
Thread calibration: mean lat.: 761.037ms, rate sampling interval: 4952ms
Thread calibration: mean lat.: 687.117ms, rate sampling interval: 4820ms
Thread calibration: mean lat.: 762.446ms, rate sampling interval: 4935ms
Thread calibration: mean lat.: 708.794ms, rate sampling interval: 3952ms
Thread calibration: mean lat.: 683.704ms, rate sampling interval: 4177ms
Thread calibration: mean lat.: 730.067ms, rate sampling interval: 4284ms
Thread calibration: mean lat.: 809.163ms, rate sampling interval: 4661ms
Thread calibration: mean lat.: 749.311ms, rate sampling interval: 4179ms
Thread calibration: mean lat.: 829.693ms, rate sampling interval: 5586ms
Thread Stats Avg Stdev Max +/- Stdev
Latency 2.46s 1.15s 6.50s 70.49%
Req/Sec 1.49k 10.32 1.50k 71.74%
Latency Distribution (HdrHistogram - Recorded Latency)
50.000% 2.26s
75.000% 2.88s
90.000% 4.27s
99.000% 5.82s
99.900% 6.30s
99.990% 6.46s
99.999% 6.50s
100.000% 6.51s
Detailed Percentile spectrum:
Value Percentile TotalCount 1/(1-Percentile)
820.223 0.000000 1 1.00
1174.527 0.100000 35383 1.11
1481.727 0.200000 70667 1.25
1745.919 0.300000 105977 1.43
2007.039 0.400000 141279 1.67
2260.991 0.500000 176662 2.00
2385.919 0.550000 194282 2.22
2525.183 0.600000 212131 2.50
2652.159 0.650000 229757 2.86
2766.847 0.700000 247482 3.33
2877.439 0.750000 264940 4.00
2934.783 0.775000 273947 4.44
3067.903 0.800000 282528 5.00
3366.911 0.825000 291372 5.71
3665.919 0.850000 300218 6.67
3964.927 0.875000 309057 8.00
4114.431 0.887500 313415 8.89
4268.031 0.900000 317878 10.00
4419.583 0.912500 322313 11.43
4579.327 0.925000 326696 13.33
4751.359 0.937500 331091 16.00
4845.567 0.943750 333357 17.78
4939.775 0.950000 335513 20.00
5042.175 0.956250 337733 22.86
5152.767 0.962500 339957 26.67
5271.551 0.968750 342156 32.00
5332.991 0.971875 343225 35.56
5402.623 0.975000 344368 40.00
5472.255 0.978125 345429 45.71
5550.079 0.981250 346535 53.33
5636.095 0.984375 347659 64.00
5681.151 0.985938 348207 71.11
5730.303 0.987500 348763 80.00
5779.455 0.989062 349276 91.43
5836.799 0.990625 349834 106.67
5902.335 0.992188 350396 128.00
5935.103 0.992969 350658 142.22
5971.967 0.993750 350956 160.00
6008.831 0.994531 351229 182.86
6049.791 0.995313 351504 213.33
6090.751 0.996094 351761 256.00
6115.327 0.996484 351911 284.44
6139.903 0.996875 352052 320.00
6164.479 0.997266 352188 365.71
6189.055 0.997656 352318 426.67
6217.727 0.998047 352454 512.00
6234.111 0.998242 352524 568.89
6250.495 0.998437 352593 640.00
6266.879 0.998633 352660 731.43
6287.359 0.998828 352734 853.33
6307.839 0.999023 352805 1024.00
6316.031 0.999121 352831 1137.78
6328.319 0.999219 352871 1280.00
6340.607 0.999316 352901 1462.86
6356.991 0.999414 352938 1706.67
6373.375 0.999512 352971 2048.00
6381.567 0.999561 352985 2275.56
6389.759 0.999609 353000 2560.00
6402.047 0.999658 353022 2925.71
6410.239 0.999707 353037 3413.33
6418.431 0.999756 353052 4096.00
6422.527 0.999780 353061 4551.11
6430.719 0.999805 353073 5120.00
6434.815 0.999829 353080 5851.43
6443.007 0.999854 353089 6826.67
6451.199 0.999878 353097 8192.00
6455.295 0.999890 353101 9102.22
6459.391 0.999902 353106 10240.00
6463.487 0.999915 353110 11702.86
6467.583 0.999927 353114 13653.33
6471.679 0.999939 353118 16384.00
6471.679 0.999945 353118 18204.44
6475.775 0.999951 353122 20480.00
6475.775 0.999957 353122 23405.71
6479.871 0.999963 353126 27306.67
6483.967 0.999969 353129 32768.00
6483.967 0.999973 353129 36408.89
6483.967 0.999976 353129 40960.00
6488.063 0.999979 353131 46811.43
6488.063 0.999982 353131 54613.33
6492.159 0.999985 353132 65536.00
6496.255 0.999986 353133 72817.78
6496.255 0.999988 353133 81920.00
6500.351 0.999989 353135 93622.86
6500.351 0.999991 353135 109226.67
6500.351 0.999992 353135 131072.00
6500.351 0.999993 353135 145635.56
6500.351 0.999994 353135 163840.00
6504.447 0.999995 353136 187245.71
6504.447 0.999995 353136 218453.33
6504.447 0.999996 353136 262144.00
6504.447 0.999997 353136 291271.11
6504.447 0.999997 353136 327680.00
6508.543 0.999997 353137 374491.43
6508.543 1.000000 353137 inf
#[Mean = 2456.488, StdDeviation = 1151.878]
#[Max = 6504.448, Total count = 353137]
#[Buckets = 27, SubBuckets = 2048]
----------------------------------------------------------
528295 requests in 30.00s, 96.12MB read
Socket errors: connect 0, read 0, write 0, timeout 63
Requests/sec: 17610.33
Transfer/sec: 3.20MB
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment