Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HAProxy general purpose counters and stick tables

I'm trying to use HAProxy for rate-limiting. I need to keep track of several endpoints and limit them individually. So far I was using general purpose counters. However, there is only 3 of them, sc0 to sc2.

In the documentation, it mentions that all the operations on these counters take an optional table parameter, but it's not clear, then, if I can track different things on different tables, but using the same counters.

In other words: is the limit of 3 general purpose counters global, or per sticky table?

If, after proper table definition and track instructions, I do

sc1_inc_gpc0(table1)

(and, under different conditions)

sc1_inc_gpc0(table2)

And then have 2 acl rules like acl X sc1_get_gpc0(table1) gt 1 acl Y sc1_get_gpc0(table2) gt 1

Will the two acls work indepentently, or they would to all effects track the same counter?

Thanks for all help! (In case you are wondering: for a number of reasons, at the moment I could not use a different solution than HAProxy for rate-limiting)

like image 331
mlr Avatar asked Mar 09 '23 16:03

mlr


1 Answers

Self answered after looking at the source code and testing.

  • Yes it is possible to use the same counter on different tables
  • Moreover, you can also increment the number of available counters at build time. The default is 3, but it can be set up to 10 for sure. Then generic versions of the functions like sc_gpc0_rate(<ctr>[,<table>]) can be used, passing the index of the new counter as first argument.
like image 88
mlr Avatar answered Mar 29 '23 08:03

mlr