Reputation: 377
i want to loadbalance soap requests between coming from a client to different instances of my service. i cant change the client and want to make the requests sticky by looking in to the payload of the requests and extracting a certain id, to make sure all requests with the same id end up on the same instance.
i've wrote a lua script to look into the payload and extra Information i Need. But for some reason every 5-6th requests has 50-60ms latency to establish Connection (the requests in between have 0ms latency) and i see log entry like
Oct 15 23:27:48 rp-proxy-p1 haproxy[30995]: Lua sample-fetch 'parseElement': yield not allowed.
Oct 15 23:27:48 rp-proxy-p1 haproxy[30995]: Lua sample-fetch 'parseElement': yield not allowed.
How can i prevent this latency and avoid the errors to occur and what does it mean?
my haproxy.cfg
global
log /dev/log local0
log /dev/log local1 notice
chroot /var/lib/haproxy
stats socket /run/haproxy/admin.sock mode 660 level admin
stats timeout 30s
user haproxy
group haproxy
daemon
lua-load /etc/haproxy/routing.lua
defaults
log global
mode tcp
option tcplog
option dontlognull
retries 3
option redispatch
maxconn 2000
timeout connect 1000
timeout client 500000
timeout server 500000
frontend my_frontend
bind *:7001
default_backend my_backend
backend my_backend
option tcp-check
balance source
stick-table type string size 30000k expire 30m
stick on "lua.parseElement"
server server1 server1.domain.com:8080 check port 8080 weight 1
server server2 server2.domain.com:8080 check port 8080 weight 1
routing.lua
function parseElement(txn, salt)
local payload = txn.req:dup()
local trx_id = payload.match(payload, "<transaction_id>(.-)</transaction_id>")
core.Info("value: "..trx_id)
return trx_id
end
core.register_fetches("parseElement", parseElement)
Upvotes: 0
Views: 1095
Reputation: 377
actually i just found the fault in my configuration.
1st) the backend should run in http mode, therefor i added
mode http
to backend my_backend
2nd) the lua script tries to access the body (txn.req
) but can't when the Body has not yet arrived when the script is executed. you can force haproxy to wait for the body to arrive before the script is executed by adding option http-buffer-request
to backend my_backend
backend my_backend
mode http
option http-buffer-request
option tcp-check
balance source
stick-table type string size 30000k expire 30m
stick on "lua.parseElement"
server server1 server1.domain.com:8080 check port 8080 weight 1
server server2 server2.domain.com:8080 check port 8080 weight 1
Upvotes: 1