]>
Commit | Line | Data |
---|---|---|
bbc27441 | 1 | /* |
ef57eb7b | 2 | * Copyright (C) 1996-2016 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 | 19 | Helper::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), | |
27 | defaultQueueSize(true) | |
aca988c4 AJ |
28 | {} |
29 | ||
76d9b994 | 30 | Helper::ChildConfig::ChildConfig(const unsigned int m): |
f53969cc SM |
31 | n_max(m), |
32 | n_startup(0), | |
33 | n_idle(1), | |
34 | concurrency(0), | |
35 | n_running(0), | |
36 | n_active(0), | |
37 | queue_size(2 * m), | |
38 | defaultQueueSize(true) | |
48d54e4d AJ |
39 | {} |
40 | ||
76d9b994 AJ |
41 | Helper::ChildConfig & |
42 | Helper::ChildConfig::updateLimits(const Helper::ChildConfig &rhs) | |
1af735c7 AJ |
43 | { |
44 | // Copy the limits only. | |
45 | // Preserve the local state values (n_running and n_active) | |
46 | n_max = rhs.n_max; | |
47 | n_startup = rhs.n_startup; | |
48 | n_idle = rhs.n_idle; | |
49 | concurrency = rhs.concurrency; | |
6825b101 CT |
50 | queue_size = rhs.queue_size; |
51 | defaultQueueSize = rhs.defaultQueueSize; | |
48d54e4d AJ |
52 | return *this; |
53 | } | |
54 | ||
881c4733 | 55 | int |
76d9b994 | 56 | Helper::ChildConfig::needNew() const |
10044c9b | 57 | { |
48d54e4d AJ |
58 | /* during the startup and reconfigure use our special amount... */ |
59 | if (starting_up || reconfiguring) return n_startup; | |
60 | ||
61 | /* keep a minimum of n_idle helpers free... */ | |
62 | if ( (n_active + n_idle) < n_max) return n_idle; | |
63 | ||
64 | /* dont ever start more than n_max processes. */ | |
65 | return (n_max - n_active); | |
66 | } | |
67 | ||
68 | void | |
76d9b994 | 69 | Helper::ChildConfig::parseConfig() |
48d54e4d | 70 | { |
2eceb328 | 71 | char const *token = ConfigParser::NextToken(); |
48d54e4d AJ |
72 | |
73 | if (!token) | |
74 | self_destruct(); | |
75 | ||
76 | /* starts with a bare number for the max... back-compatible */ | |
54a063a2 | 77 | n_max = xatoui(token); |
48d54e4d | 78 | |
54a063a2 TX |
79 | if (n_max < 1) { |
80 | debugs(0, DBG_CRITICAL, "ERROR: The maximum number of processes cannot be less than 1."); | |
48d54e4d | 81 | self_destruct(); |
54a063a2 | 82 | } |
48d54e4d AJ |
83 | |
84 | /* Parse extension options */ | |
2eceb328 | 85 | for (; (token = ConfigParser::NextToken()) ;) { |
48d54e4d | 86 | if (strncmp(token, "startup=", 8) == 0) { |
54a063a2 | 87 | n_startup = xatoui(token + 8); |
48d54e4d | 88 | } else if (strncmp(token, "idle=", 5) == 0) { |
54a063a2 | 89 | n_idle = xatoui(token + 5); |
48d54e4d | 90 | if (n_idle < 1) { |
fa84c01d | 91 | debugs(0, DBG_CRITICAL, "WARNING OVERIDE: Using idle=0 for helpers causes request failures. Overiding to use idle=1 instead."); |
48d54e4d AJ |
92 | n_idle = 1; |
93 | } | |
94 | } else if (strncmp(token, "concurrency=", 12) == 0) { | |
54a063a2 | 95 | concurrency = xatoui(token + 12); |
6825b101 CT |
96 | } else if (strncmp(token, "queue-size=", 11) == 0) { |
97 | queue_size = xatoui(token + 11); | |
98 | defaultQueueSize = false; | |
48d54e4d | 99 | } else { |
54a063a2 | 100 | debugs(0, DBG_PARSE_NOTE(DBG_IMPORTANT), "ERROR: Undefined option: " << token << "."); |
48d54e4d AJ |
101 | self_destruct(); |
102 | } | |
103 | } | |
104 | ||
105 | /* simple sanity. */ | |
106 | ||
107 | if (n_startup > n_max) { | |
fa84c01d | 108 | debugs(0, DBG_CRITICAL, "WARNING OVERIDE: Capping startup=" << n_startup << " to the defined maximum (" << n_max <<")"); |
48d54e4d AJ |
109 | n_startup = n_max; |
110 | } | |
111 | ||
112 | if (n_idle > n_max) { | |
fa84c01d | 113 | debugs(0, DBG_CRITICAL, "WARNING OVERIDE: Capping idle=" << n_idle << " to the defined maximum (" << n_max <<")"); |
48d54e4d AJ |
114 | n_idle = n_max; |
115 | } | |
f53969cc | 116 | |
6825b101 CT |
117 | if (defaultQueueSize) |
118 | queue_size = 2 * n_max; | |
48d54e4d | 119 | } |
f53969cc | 120 |