]>
Commit | Line | Data |
---|---|---|
f7f3304a | 1 | #include "squid.h" |
8a01b99e | 2 | #include "cache_cf.h" |
2eceb328 | 3 | #include "ConfigParser.h" |
582c2af2 | 4 | #include "Debug.h" |
48d54e4d | 5 | #include "globals.h" |
602d9612 | 6 | #include "HelperChildConfig.h" |
54a063a2 | 7 | #include "Parsing.h" |
48d54e4d AJ |
8 | |
9 | #include <string.h> | |
10 | ||
0db33c21 | 11 | HelperChildConfig::HelperChildConfig(const unsigned int m): |
48d54e4d | 12 | n_max(m), |
0db33c21 AR |
13 | n_startup(0), |
14 | n_idle(1), | |
15 | concurrency(0), | |
48d54e4d AJ |
16 | n_running(0), |
17 | n_active(0) | |
18 | {} | |
19 | ||
1af735c7 AJ |
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; | |
48d54e4d AJ |
29 | return *this; |
30 | } | |
31 | ||
881c4733 | 32 | int |
10044c9b A |
33 | HelperChildConfig::needNew() const |
34 | { | |
48d54e4d AJ |
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 | { | |
2eceb328 | 48 | char const *token = ConfigParser::NextToken(); |
48d54e4d AJ |
49 | |
50 | if (!token) | |
51 | self_destruct(); | |
52 | ||
53 | /* starts with a bare number for the max... back-compatible */ | |
54a063a2 | 54 | n_max = xatoui(token); |
48d54e4d | 55 | |
54a063a2 TX |
56 | if (n_max < 1) { |
57 | debugs(0, DBG_CRITICAL, "ERROR: The maximum number of processes cannot be less than 1."); | |
48d54e4d | 58 | self_destruct(); |
54a063a2 | 59 | } |
48d54e4d AJ |
60 | |
61 | /* Parse extension options */ | |
2eceb328 | 62 | for (; (token = ConfigParser::NextToken()) ;) { |
48d54e4d | 63 | if (strncmp(token, "startup=", 8) == 0) { |
54a063a2 | 64 | n_startup = xatoui(token + 8); |
48d54e4d | 65 | } else if (strncmp(token, "idle=", 5) == 0) { |
54a063a2 | 66 | n_idle = xatoui(token + 5); |
48d54e4d | 67 | if (n_idle < 1) { |
fa84c01d | 68 | debugs(0, DBG_CRITICAL, "WARNING OVERIDE: Using idle=0 for helpers causes request failures. Overiding to use idle=1 instead."); |
48d54e4d AJ |
69 | n_idle = 1; |
70 | } | |
71 | } else if (strncmp(token, "concurrency=", 12) == 0) { | |
54a063a2 | 72 | concurrency = xatoui(token + 12); |
48d54e4d | 73 | } else { |
54a063a2 | 74 | debugs(0, DBG_PARSE_NOTE(DBG_IMPORTANT), "ERROR: Undefined option: " << token << "."); |
48d54e4d AJ |
75 | self_destruct(); |
76 | } | |
77 | } | |
78 | ||
79 | /* simple sanity. */ | |
80 | ||
81 | if (n_startup > n_max) { | |
fa84c01d | 82 | debugs(0, DBG_CRITICAL, "WARNING OVERIDE: Capping startup=" << n_startup << " to the defined maximum (" << n_max <<")"); |
48d54e4d AJ |
83 | n_startup = n_max; |
84 | } | |
85 | ||
86 | if (n_idle > n_max) { | |
fa84c01d | 87 | debugs(0, DBG_CRITICAL, "WARNING OVERIDE: Capping idle=" << n_idle << " to the defined maximum (" << n_max <<")"); |
48d54e4d AJ |
88 | n_idle = n_max; |
89 | } | |
90 | } |