Why does the overall average response time for long connections (keep-alive) exceed that for short connections (close) in performance tests?
00:57 20 Jan 2026

Why does the overall average response time for long connections (keep-alive) exceed that for short connections (close) in performance tests? Why is this, and how can it be optimized?

wrk performance test results pic:

average response time:

14.01ms > 9.76ms (keepalive > close)

command:

1.post 500KB,connection:keepalive

wrk -t8 -c16 -d1m -s post.lua --latency --timeout 5s http://10.129.9.39:5074/user

2. post 500KB,connection:close

wrk -t8 -c16 -d1m -s post_close.lua --latency --timeout 5s http://10.129.9.39:5074/user

client post 500KB, server returned the string "ok".

post.lua

wrk.method = "POST"
wrk.headers["Content-Type"] = "application/json"
wrk.headers["Connection"] = "keep-alive"
local file = io.open("/root/tls/500kb.json", "rb")
wrk.body = file:read("*all")
file:close()

post_close.lua

wrk.method = "POST"
wrk.headers["Content-Type"] = "application/json"
wrk.headers["Connection"] = "close"
local file = io.open("/root/tls/500kb.json", "rb")
wrk.body = file:read("*all")
file:close()
http