MEDIUM: servers: Add a command to limit the number of idling connections.
Add a new command, "pool-max-conn" that sets the maximum number of connections
waiting in the orphan idling connections list (as activated with idle-timeout).
Using "-1" means unlimited. Using pools is now dependant on this.
diff --git a/include/proto/connection.h b/include/proto/connection.h
index f84b75a..2cf37ab 100644
--- a/include/proto/connection.h
+++ b/include/proto/connection.h
@@ -558,6 +558,7 @@
LIST_INIT(&conn->session_list);
conn->send_wait = NULL;
conn->recv_wait = NULL;
+ conn->idle_time = 0;
}
/* sets <owner> as the connection's owner */
@@ -673,6 +674,13 @@
if (objt_conn(s->si[1].end) == conn)
s->si[1].end = NULL;
}
+ /* The connection is currently in the server's idle list, so tell it
+ * there's one less connection available in that list.
+ */
+ if (conn->idle_time > 0) {
+ struct server *srv = __objt_server(conn->target);
+ srv->curr_idle_conns--;
+ }
conn_force_unsubscribe(conn);
LIST_DEL(&conn->list);
diff --git a/include/types/connection.h b/include/types/connection.h
index bcc2965..eff1001 100644
--- a/include/types/connection.h
+++ b/include/types/connection.h
@@ -446,7 +446,7 @@
struct sockaddr_storage from; /* client address, or address to spoof when connecting to the server */
struct sockaddr_storage to; /* address reached by the client, or address to connect to */
} addr; /* addresses of the remote side, client for producer and server for consumer */
- unsigned int idle_time; /* Time the connection was added to the idle list */
+ unsigned int idle_time; /* Time the connection was added to the idle list, or 0 if not in the idle list */
};
/* PROTO token registration */
diff --git a/include/types/server.h b/include/types/server.h
index bb53523..2eef2c3 100644
--- a/include/types/server.h
+++ b/include/types/server.h
@@ -223,7 +223,9 @@
struct list *safe_conns; /* safe idle connections attached to stream interfaces, shared */
struct list *idle_orphan_conns; /* Orphan connections idling */
unsigned int idle_timeout; /* Time to keep an idling orphan connection alive */
- struct task **idle_task; /* task responsible for cleaning idle orphan connections */
+ unsigned int max_idle_conns; /* Max number of connection allowed in the orphan connections list */
+ unsigned int curr_idle_conns; /* Current number of orphan idling connections */
+ struct task **idle_task; /* task responsible for cleaning idle orphan connections */
struct task *warmup; /* the task dedicated to the warmup when slowstart is set */
struct conn_src conn_src; /* connection source settings */