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