nodejs/llhttp

Performance issues between llhttp and http_parser

Closed this issue · 0 comments

Hello everyone, I have been integrating llhttp recently. During the performance testing using wrk, the results were not as good as http_parser. Are there any other methods to maximize the performance of llhttp? Thank you.

The callback functions for llhttp and http_parser are the same.

// http_parser
wrk -t4 -c500 -d30s -s script.lua http://127.0.0.1/
Running 30s test @ http://127.0.0.1/
  4 threads and 500 connections
  Thread Stats   Avg      Stdev     Max   +/- Stdev
    Latency     4.87ms    2.19ms  28.15ms   74.16%
    Req/Sec    23.13k     1.87k   31.86k    75.63%
  2769162 requests in 30.10s, 433.10MB read
Requests/sec:  91994.75
Transfer/sec:     14.39MB

// llhttp
wrk -t4 -c500 -d30s -s script.lua http://127.0.0.1/
Running 30s test @ http://127.0.0.1/
  4 threads and 500 connections
  Thread Stats   Avg      Stdev     Max   +/- Stdev
    Latency     4.94ms    2.35ms  35.06ms   73.95%
    Req/Sec    22.79k     1.98k   33.21k    76.78%
  2727296 requests in 30.08s, 426.56MB read
Requests/sec:  90671.83
Transfer/sec:     14.18MB

script.lua

function randomString(length)
  local charset = {}
  for i = 48, 57 do table.insert(charset, string.char(i)) end -- 0-9
  for i = 65, 90 do table.insert(charset, string.char(i)) end -- A-Z
  for i = 97, 122 do table.insert(charset, string.char(i)) end -- a-z
  math.randomseed(os.time())
  local str = ""
  for _ = 1, length do
    str = str .. charset[math.random(1, #charset)]
  end
  return str
end


wrk.method = "POST"
data = '{"data":"' ..randomString(1024 * 10).. '"}'
wrk.body = data
wrk.headers["Host"] = "127.0.0.1"
wrk.headers["Accept"] = "application/json,text/html;q=0.9,application/xhtml+xml;q=0.9,application/xml;q=0.8,*/*;q=0.7"
wrk.headers["Connection"] = "keep-alive"
wrk.headers["Content-Type"] = "application/json"
wrk.headers["Content-Length"] = #data