antonputra / tutorials

DevOps Tutorials
https://youtube.com/antonputra
MIT License
3.19k stars 2.5k forks source link

perf: Rust improvements #309

Closed SuperioOne closed 1 month ago

SuperioOne commented 1 month ago

I added small changes to Rust code to make it little bit more 1:1 with Zig version.

Changes:

Example assembly comparisons, if anyone interested in; Rust - https://godbolt.org/z/9aG61z1a8 Zig - https://godbolt.org/z/4nYTEEY1j

I also tested both versions with bombardier. Differences are limited, and I don't think it would change the benchmark results too much, but :: it's something ::

Current main HEAD:

Bombarding http://localhost:8080/api/devices for 1m0s using 200 connection(s)
Done!
Statistics        Avg      Stdev        Max
  Reqs/sec    286812.28   13257.35  325394.30
  Latency      696.38us   359.38us   126.93ms
  Latency Distribution
     50%   680.00us
     75%   712.00us
     90%   777.00us
     95%     0.90ms
     99%     1.00ms
  HTTP codes:
    1xx - 0, 2xx - 17194108, 3xx - 0, 4xx - 0, 5xx - 0
    others - 0
  Throughput:    63.95MB/s

PR version:

Bombarding http://localhost:8080/api/devices for 1m0s using 200 connection(s)
Done!
Statistics        Avg      Stdev        Max
  Reqs/sec    292939.26   13736.39  349142.71
  Latency      681.52us   291.79us   115.37ms
  Latency Distribution
     50%   665.00us
     75%   695.00us
     90%   768.00us
     95%     0.89ms
     99%     0.99ms
  HTTP codes:
    1xx - 0, 2xx - 17567441, 3xx - 0, 4xx - 0, 5xx - 0
    others - 0
  Throughput:    65.34MB/s