mirror of
https://github.com/haproxy/haproxy.git
synced 2026-07-12 10:35:55 -04:00
MEDIUM: proxy: no longer allocate the default-server entry by default
The default-server entry used to always be allocated. Now we'll postpone its allocation for the first time we need it, i.e. during a "default-server" directive, or when inheriting a defaults section which has one. The memory savings are significant, on a large configuration with 100k backends and no default-server directive, the memory usage dropped from 800MB RSS to 420MB (380 MB saved). It should be possible to also address configs using default-server by releasing this entry when leaving the proxy section, which is not done yet.
This commit is contained in:
parent
76828d4120
commit
49a619acae
1 changed files with 17 additions and 11 deletions
28
src/proxy.c
28
src/proxy.c
|
|
@ -1685,16 +1685,6 @@ int setup_new_proxy(struct proxy *px, const char *name, unsigned int cap, char *
|
||||||
{
|
{
|
||||||
init_new_proxy(px);
|
init_new_proxy(px);
|
||||||
|
|
||||||
/* allocate the default server section */
|
|
||||||
px->defsrv = calloc(1, sizeof(*px->defsrv));
|
|
||||||
if (!px->defsrv) {
|
|
||||||
memprintf(errmsg, "out of memory");
|
|
||||||
goto fail;
|
|
||||||
}
|
|
||||||
|
|
||||||
px->defsrv->id = "default-server";
|
|
||||||
srv_settings_init(px->defsrv);
|
|
||||||
|
|
||||||
if (name) {
|
if (name) {
|
||||||
px->id = strdup(name);
|
px->id = strdup(name);
|
||||||
if (!px->id) {
|
if (!px->id) {
|
||||||
|
|
@ -1807,8 +1797,24 @@ static int proxy_defproxy_cpy(struct proxy *curproxy, const struct proxy *defpro
|
||||||
struct eb32_node *node;
|
struct eb32_node *node;
|
||||||
|
|
||||||
/* set default values from the specified default proxy */
|
/* set default values from the specified default proxy */
|
||||||
if (curproxy->defsrv)
|
|
||||||
|
if (defproxy->defsrv) {
|
||||||
|
if (!curproxy->defsrv) {
|
||||||
|
/* there's a default-server in the defaults proxy but
|
||||||
|
* none allocated yet in the current proxy so we have
|
||||||
|
* to allocate and pre-initialize it right now.
|
||||||
|
*/
|
||||||
|
curproxy->defsrv = calloc(1, sizeof(*curproxy->defsrv));
|
||||||
|
if (!curproxy->defsrv) {
|
||||||
|
memprintf(errmsg, "proxy '%s': out of memory allocating default-server", curproxy->id);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
curproxy->defsrv->id = "default-server";
|
||||||
|
srv_settings_init(curproxy->defsrv);
|
||||||
|
}
|
||||||
srv_settings_cpy(curproxy->defsrv, defproxy->defsrv, 0);
|
srv_settings_cpy(curproxy->defsrv, defproxy->defsrv, 0);
|
||||||
|
}
|
||||||
|
|
||||||
curproxy->flags = (defproxy->flags & PR_FL_DISABLED); /* Only inherit from disabled flag */
|
curproxy->flags = (defproxy->flags & PR_FL_DISABLED); /* Only inherit from disabled flag */
|
||||||
curproxy->options = defproxy->options;
|
curproxy->options = defproxy->options;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue