[MEDIUM] improve behaviour with large number of servers per proxy
When a very large number of servers is configured (thousands),
shutting down many of them at once could lead to large number
of calls to recalc_server_map() which already takes some time.
This would result in an O(N^3) computation time, leading to
noticeable pauses on slow embedded CPUs on test platforms.
Instead, mark the map as dirty and recalc it only when needed.
diff --git a/include/proto/backend.h b/include/proto/backend.h
index f0295b0..467e756 100644
--- a/include/proto/backend.h
+++ b/include/proto/backend.h
@@ -52,6 +52,9 @@
int newidx;
struct server *srv;
+ if (px->map_state & PR_MAP_RECALC)
+ recalc_server_map(px);
+
if (px->srv_map_sz == 0)
return NULL;
@@ -81,6 +84,9 @@
*/
static inline struct server *get_server_rr(struct proxy *px)
{
+ if (px->map_state & PR_MAP_RECALC)
+ recalc_server_map(px);
+
if (px->srv_map_sz == 0)
return NULL;
@@ -97,11 +103,14 @@
* If any server is found, it will be returned. If no valid server is found,
* NULL is returned.
*/
-static inline struct server *get_server_sh(const struct proxy *px,
+static inline struct server *get_server_sh(struct proxy *px,
const char *addr, int len)
{
unsigned int h, l;
+ if (px->map_state & PR_MAP_RECALC)
+ recalc_server_map(px);
+
if (px->srv_map_sz == 0)
return NULL;
@@ -133,6 +142,9 @@
unsigned long hash = 0;
int c;
+ if (px->map_state & PR_MAP_RECALC)
+ recalc_server_map(px);
+
if (px->srv_map_sz == 0)
return NULL;