I recently wrote a web application using Kemal, which has an API for generating QR images:
/key/qrcode. It takes about tens of milliseconds to call it once.
If I use the
wrk test to only respond to static page API, such as the home page, this is the result:
➜ ~ wrk -c 8000 -t 6 -d 15 http://localhost:8080/ Running 15s test @ http://localhost:8080/ 6 threads and 8000 connections Thread Stats Avg Stdev Max +/- Stdev Latency 61.02ms 11.64ms 265.48ms 89.10% Req/Sec 2.74k 847.52 4.29k 67.90% 243625 requests in 15.04s, 1.38GB read Socket errors: connect 6983, read 0, write 0, timeout 0 Requests/sec: 16201.40 Transfer/sec: 94.14MB
But testing the API generated by the QR Code, the result becomes like this:
➜ ~ wrk -c 8000 -t 6 -d 15 http://localhost:8080/key/qrcode Running 15s test @ http://localhost:8080/key/qrcode 6 threads and 8000 connections Thread Stats Avg Stdev Max +/- Stdev Latency 1.00s 571.39ms 1.98s 58.33% Req/Sec 10.76 8.27 40.00 76.26% 455 requests in 15.03s, 2.83MB read Socket errors: connect 6983, read 0, write 0, timeout 395 Requests/sec: 30.28 Transfer/sec: 193.00KB
The QR Code is implemented using C binding for
libqrencode and stumpy_png.
Worse, my Kemal app couldn’t respond to any requests when I tested the
How should Crystal respond to this situation?