]>
Commit | Line | Data |
---|---|---|
f7f3304a | 1 | #include "squid.h" |
48d54e4d AJ |
2 | #include "HelperChildConfig.h" |
3 | #include "globals.h" | |
4 | ||
5 | #include <string.h> | |
6 | ||
0db33c21 | 7 | HelperChildConfig::HelperChildConfig(const unsigned int m): |
48d54e4d | 8 | n_max(m), |
0db33c21 AR |
9 | n_startup(0), |
10 | n_idle(1), | |
11 | concurrency(0), | |
48d54e4d AJ |
12 | n_running(0), |
13 | n_active(0) | |
14 | {} | |
15 | ||
1af735c7 AJ |
16 | HelperChildConfig & |
17 | HelperChildConfig::updateLimits(const HelperChildConfig &rhs) | |
18 | { | |
19 | // Copy the limits only. | |
20 | // Preserve the local state values (n_running and n_active) | |
21 | n_max = rhs.n_max; | |
22 | n_startup = rhs.n_startup; | |
23 | n_idle = rhs.n_idle; | |
24 | concurrency = rhs.concurrency; | |
48d54e4d AJ |
25 | return *this; |
26 | } | |
27 | ||
881c4733 | 28 | int |
10044c9b A |
29 | HelperChildConfig::needNew() const |
30 | { | |
48d54e4d AJ |
31 | /* during the startup and reconfigure use our special amount... */ |
32 | if (starting_up || reconfiguring) return n_startup; | |
33 | ||
34 | /* keep a minimum of n_idle helpers free... */ | |
35 | if ( (n_active + n_idle) < n_max) return n_idle; | |
36 | ||
37 | /* dont ever start more than n_max processes. */ | |
38 | return (n_max - n_active); | |
39 | } | |
40 | ||
41 | void | |
42 | HelperChildConfig::parseConfig() | |
43 | { | |
44 | char const *token = strtok(NULL, w_space); | |
45 | ||
46 | if (!token) | |
47 | self_destruct(); | |
48 | ||
49 | /* starts with a bare number for the max... back-compatible */ | |
50 | n_max = atoi(token); | |
51 | ||
52 | if (n_max < 1) | |
53 | self_destruct(); | |
54 | ||
55 | /* Parse extension options */ | |
56 | for (; (token = strtok(NULL, w_space)) ;) { | |
57 | if (strncmp(token, "startup=", 8) == 0) { | |
58 | n_startup = atoi(token + 8); | |
59 | } else if (strncmp(token, "idle=", 5) == 0) { | |
60 | n_idle = atoi(token + 5); | |
61 | if (n_idle < 1) { | |
fa84c01d | 62 | debugs(0, DBG_CRITICAL, "WARNING OVERIDE: Using idle=0 for helpers causes request failures. Overiding to use idle=1 instead."); |
48d54e4d AJ |
63 | n_idle = 1; |
64 | } | |
65 | } else if (strncmp(token, "concurrency=", 12) == 0) { | |
66 | concurrency = atoi(token + 12); | |
67 | } else { | |
68 | self_destruct(); | |
69 | } | |
70 | } | |
71 | ||
72 | /* simple sanity. */ | |
73 | ||
74 | if (n_startup > n_max) { | |
fa84c01d | 75 | debugs(0, DBG_CRITICAL, "WARNING OVERIDE: Capping startup=" << n_startup << " to the defined maximum (" << n_max <<")"); |
48d54e4d AJ |
76 | n_startup = n_max; |
77 | } | |
78 | ||
79 | if (n_idle > n_max) { | |
fa84c01d | 80 | debugs(0, DBG_CRITICAL, "WARNING OVERIDE: Capping idle=" << n_idle << " to the defined maximum (" << n_max <<")"); |
48d54e4d AJ |
81 | n_idle = n_max; |
82 | } | |
83 | } |