Suggested echo server implementation with HAProxy and Lua
Posted: Mon Nov 09, 2015 6:00 am
I've been in contact with the HAProxy mailing list, and since version 1.6 (with Lua support), it's capable of a much more efficient echo server implementation for the ABE WAN feature.
Sample configuration:
I've done a quick test of this with ab.
Apache+PHP at concurrency 100 typically takes 5-10ms to serve each request (tested up to 100000 total requests). However, at concurrency 1000, it frequently runs much slower (200-300ms) or hangs, even on much smaller total numbers of requests (1000-2000).
HAProxy+Lua at concurrency 100 returns 99% of requests within 2ms (most of them within 1ms). At concurrency 1000, it continues to perform the same way up to approximately 35000 total requests, after which (at least on my machine) a small percentage of requests apparently timeout and disconnect. I'm not sure whether that's a problem in HAProxy or a limitation of ab.
Sample configuration:
Code: Select all
#haproxy.cfg
global
lua-load echo.lua
frontend echo
bind :80
mode http
http-request lua.echo
#echo.lua
core.register_action("echo", { "http-req" }, function (txn)
local buffer = txn.f:src()
txn.res:send("HTTP/1.0 200 OK\r\nServer: haproxy-lua/echo\r\nContent-Type: text/html\r\nContent-Length: " .. buffer:len() .. "\r\nConnection: close\r\n\r\n" .. buffer)
txn:done()
end)
Apache+PHP at concurrency 100 typically takes 5-10ms to serve each request (tested up to 100000 total requests). However, at concurrency 1000, it frequently runs much slower (200-300ms) or hangs, even on much smaller total numbers of requests (1000-2000).
HAProxy+Lua at concurrency 100 returns 99% of requests within 2ms (most of them within 1ms). At concurrency 1000, it continues to perform the same way up to approximately 35000 total requests, after which (at least on my machine) a small percentage of requests apparently timeout and disconnect. I'm not sure whether that's a problem in HAProxy or a limitation of ab.