]> git.ipfire.org Git - thirdparty/squid.git/blob - src/HelperChildConfig.cc
SourceFormat Enforcement
[thirdparty/squid.git] / src / HelperChildConfig.cc
1 #include "squid.h"
2 #include "cache_cf.h"
3 #include "ConfigParser.h"
4 #include "Debug.h"
5 #include "globals.h"
6 #include "HelperChildConfig.h"
7 #include "Parsing.h"
8
9 #include <string.h>
10
11 HelperChildConfig::HelperChildConfig(const unsigned int m):
12 n_max(m),
13 n_startup(0),
14 n_idle(1),
15 concurrency(0),
16 n_running(0),
17 n_active(0)
18 {}
19
20 HelperChildConfig &
21 HelperChildConfig::updateLimits(const HelperChildConfig &rhs)
22 {
23 // Copy the limits only.
24 // Preserve the local state values (n_running and n_active)
25 n_max = rhs.n_max;
26 n_startup = rhs.n_startup;
27 n_idle = rhs.n_idle;
28 concurrency = rhs.concurrency;
29 return *this;
30 }
31
32 int
33 HelperChildConfig::needNew() const
34 {
35 /* during the startup and reconfigure use our special amount... */
36 if (starting_up || reconfiguring) return n_startup;
37
38 /* keep a minimum of n_idle helpers free... */
39 if ( (n_active + n_idle) < n_max) return n_idle;
40
41 /* dont ever start more than n_max processes. */
42 return (n_max - n_active);
43 }
44
45 void
46 HelperChildConfig::parseConfig()
47 {
48 char const *token = ConfigParser::NextToken();
49
50 if (!token)
51 self_destruct();
52
53 /* starts with a bare number for the max... back-compatible */
54 n_max = xatoui(token);
55
56 if (n_max < 1) {
57 debugs(0, DBG_CRITICAL, "ERROR: The maximum number of processes cannot be less than 1.");
58 self_destruct();
59 }
60
61 /* Parse extension options */
62 for (; (token = ConfigParser::NextToken()) ;) {
63 if (strncmp(token, "startup=", 8) == 0) {
64 n_startup = xatoui(token + 8);
65 } else if (strncmp(token, "idle=", 5) == 0) {
66 n_idle = xatoui(token + 5);
67 if (n_idle < 1) {
68 debugs(0, DBG_CRITICAL, "WARNING OVERIDE: Using idle=0 for helpers causes request failures. Overiding to use idle=1 instead.");
69 n_idle = 1;
70 }
71 } else if (strncmp(token, "concurrency=", 12) == 0) {
72 concurrency = xatoui(token + 12);
73 } else {
74 debugs(0, DBG_PARSE_NOTE(DBG_IMPORTANT), "ERROR: Undefined option: " << token << ".");
75 self_destruct();
76 }
77 }
78
79 /* simple sanity. */
80
81 if (n_startup > n_max) {
82 debugs(0, DBG_CRITICAL, "WARNING OVERIDE: Capping startup=" << n_startup << " to the defined maximum (" << n_max <<")");
83 n_startup = n_max;
84 }
85
86 if (n_idle > n_max) {
87 debugs(0, DBG_CRITICAL, "WARNING OVERIDE: Capping idle=" << n_idle << " to the defined maximum (" << n_max <<")");
88 n_idle = n_max;
89 }
90 }