]> git.ipfire.org Git - thirdparty/squid.git/blame - src/helper/ChildConfig.cc
Docs: Copyright updates for 2018 (#114)
[thirdparty/squid.git] / src / helper / ChildConfig.cc
CommitLineData
bbc27441 1/*
5b74111a 2 * Copyright (C) 1996-2018 The Squid Software Foundation and contributors
bbc27441
AJ
3 *
4 * Squid software is distributed under GPLv2+ license and includes
5 * contributions from numerous individuals and organizations.
6 * Please see the COPYING and CONTRIBUTORS files for details.
7 */
8
f7f3304a 9#include "squid.h"
8a01b99e 10#include "cache_cf.h"
2eceb328 11#include "ConfigParser.h"
582c2af2 12#include "Debug.h"
48d54e4d 13#include "globals.h"
76d9b994 14#include "helper/ChildConfig.h"
54a063a2 15#include "Parsing.h"
48d54e4d 16
074d6a40 17#include <cstring>
48d54e4d 18
aca988c4 19Helper::ChildConfig::ChildConfig():
f53969cc
SM
20 n_max(0),
21 n_startup(0),
22 n_idle(1),
23 concurrency(0),
24 n_running(0),
25 n_active(0),
26 queue_size(0),
6082a0e2 27 onPersistentOverload(actDie),
f53969cc 28 defaultQueueSize(true)
aca988c4
AJ
29{}
30
76d9b994 31Helper::ChildConfig::ChildConfig(const unsigned int m):
f53969cc
SM
32 n_max(m),
33 n_startup(0),
34 n_idle(1),
35 concurrency(0),
36 n_running(0),
37 n_active(0),
38 queue_size(2 * m),
6082a0e2 39 onPersistentOverload(actDie),
f53969cc 40 defaultQueueSize(true)
48d54e4d
AJ
41{}
42
76d9b994
AJ
43Helper::ChildConfig &
44Helper::ChildConfig::updateLimits(const Helper::ChildConfig &rhs)
1af735c7
AJ
45{
46 // Copy the limits only.
47 // Preserve the local state values (n_running and n_active)
48 n_max = rhs.n_max;
49 n_startup = rhs.n_startup;
50 n_idle = rhs.n_idle;
51 concurrency = rhs.concurrency;
6825b101 52 queue_size = rhs.queue_size;
6082a0e2 53 onPersistentOverload = rhs.onPersistentOverload;
6825b101 54 defaultQueueSize = rhs.defaultQueueSize;
48d54e4d
AJ
55 return *this;
56}
57
881c4733 58int
76d9b994 59Helper::ChildConfig::needNew() const
10044c9b 60{
48d54e4d
AJ
61 /* during the startup and reconfigure use our special amount... */
62 if (starting_up || reconfiguring) return n_startup;
63
64 /* keep a minimum of n_idle helpers free... */
65 if ( (n_active + n_idle) < n_max) return n_idle;
66
67 /* dont ever start more than n_max processes. */
68 return (n_max - n_active);
69}
70
71void
76d9b994 72Helper::ChildConfig::parseConfig()
48d54e4d 73{
2eceb328 74 char const *token = ConfigParser::NextToken();
48d54e4d 75
24095690 76 if (!token) {
48d54e4d 77 self_destruct();
24095690
AJ
78 return;
79 }
48d54e4d
AJ
80
81 /* starts with a bare number for the max... back-compatible */
54a063a2 82 n_max = xatoui(token);
48d54e4d 83
54a063a2
TX
84 if (n_max < 1) {
85 debugs(0, DBG_CRITICAL, "ERROR: The maximum number of processes cannot be less than 1.");
48d54e4d 86 self_destruct();
24095690 87 return;
54a063a2 88 }
48d54e4d
AJ
89
90 /* Parse extension options */
2eceb328 91 for (; (token = ConfigParser::NextToken()) ;) {
48d54e4d 92 if (strncmp(token, "startup=", 8) == 0) {
54a063a2 93 n_startup = xatoui(token + 8);
48d54e4d 94 } else if (strncmp(token, "idle=", 5) == 0) {
54a063a2 95 n_idle = xatoui(token + 5);
48d54e4d 96 if (n_idle < 1) {
fa84c01d 97 debugs(0, DBG_CRITICAL, "WARNING OVERIDE: Using idle=0 for helpers causes request failures. Overiding to use idle=1 instead.");
48d54e4d
AJ
98 n_idle = 1;
99 }
100 } else if (strncmp(token, "concurrency=", 12) == 0) {
54a063a2 101 concurrency = xatoui(token + 12);
6825b101
CT
102 } else if (strncmp(token, "queue-size=", 11) == 0) {
103 queue_size = xatoui(token + 11);
104 defaultQueueSize = false;
6082a0e2
EB
105 } else if (strncmp(token, "on-persistent-overload=", 23) == 0) {
106 const SBuf action(token + 23);
107 if (action.cmp("ERR") == 0)
108 onPersistentOverload = actErr;
109 else if (action.cmp("die") == 0)
110 onPersistentOverload = actDie;
111 else {
112 debugs(0, DBG_CRITICAL, "ERROR: Unsupported on-persistent-overloaded action: " << action);
113 self_destruct();
24095690 114 return;
6082a0e2 115 }
48d54e4d 116 } else {
54a063a2 117 debugs(0, DBG_PARSE_NOTE(DBG_IMPORTANT), "ERROR: Undefined option: " << token << ".");
48d54e4d 118 self_destruct();
24095690 119 return;
48d54e4d
AJ
120 }
121 }
122
123 /* simple sanity. */
124
125 if (n_startup > n_max) {
fa84c01d 126 debugs(0, DBG_CRITICAL, "WARNING OVERIDE: Capping startup=" << n_startup << " to the defined maximum (" << n_max <<")");
48d54e4d
AJ
127 n_startup = n_max;
128 }
129
130 if (n_idle > n_max) {
fa84c01d 131 debugs(0, DBG_CRITICAL, "WARNING OVERIDE: Capping idle=" << n_idle << " to the defined maximum (" << n_max <<")");
48d54e4d
AJ
132 n_idle = n_max;
133 }
f53969cc 134
6825b101
CT
135 if (defaultQueueSize)
136 queue_size = 2 * n_max;
48d54e4d 137}
f53969cc 138