]> git.ipfire.org Git - thirdparty/squid.git/blob - src/HelperChildConfig.cc
71c00442fe4b1d5edd66392e1d48b1daeb36f522
[thirdparty/squid.git] / src / HelperChildConfig.cc
1 #include "config.h"
2 #include "HelperChildConfig.h"
3 #include "globals.h"
4
5 #include <string.h>
6
7 HelperChildConfig::HelperChildConfig(const unsigned int m):
8 n_max(m),
9 n_startup(0),
10 n_idle(1),
11 concurrency(0),
12 n_running(0),
13 n_active(0)
14 {}
15
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;
25 return *this;
26 }
27
28 int
29 HelperChildConfig::needNew() const
30 {
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) {
62 debugs(0,0,"WARNING OVERIDE: Using idle=0 for helpers causes request failures. Overiding to use idle=1 instead.");
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) {
75 debugs(0,0,"WARNING OVERIDE: Capping startup=" << n_startup << " to the defined maximum (" << n_max <<")");
76 n_startup = n_max;
77 }
78
79 if (n_idle > n_max) {
80 debugs(0,0,"WARNING OVERIDE: Capping idle=" << n_idle << " to the defined maximum (" << n_max <<")");
81 n_idle = n_max;
82 }
83 }