Hi Ansgar, On Tue, Feb 11, 2025 at 08:49:29AM +0100, Ansgar Jazdzewski wrote: > Hi Folks, > > I'm looking for a way to count the number of in-flight operations per > user (extracted from the URL path) and store that value in a variable. > My goal is to track and enforce a per-user concurrency limit using > HAProxy's stick tables and GPC. > > My approach is to use a GPC counter, incrementing it on request and > decrementing it when the response is sent. > > Draft Configuration; > ``` > frontend http-in > bind *:80 > > stick-table type string size 1m expire 10m store gpc0 > http-request set-var(txn.user) path,regsub(^/([^/]+)/.*$,\1) > http-request track-sc0 var(txn.user) > > # Increase in-flight counter > http-request set-var(txn.gpc0) sc_inc_gpc0() > > # Limit concurrent requests per user to 5 > acl user_over_limit sc_get_gpc0() gt 5 > http-request deny if user_over_limit > > # Decrease in-flight counter when response is sent > http-response set-var(txn.gpc0) sc_dec_gpc0() > ... > ``` > > However, sc_dec_gpc0() does not seem to be implemented yet. Do you > think such a function is needed, or is there another approach I could > take to track in-flight operations per user effectively?
There is much simpler. Please have a look at sc_trackers(). It returns the number of active "track-sc" on a given entry. I think it does exactly what you're looking for, without requiring to increment nor decrement a counter. Regards, Willy