Squid Web Cache master
Loading...
Searching...
No Matches
ChildConfig.cc
Go to the documentation of this file.
1/*
2 * Copyright (C) 1996-2025 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/Stream.h"
13#include "globals.h"
14#include "helper/ChildConfig.h"
15#include "Parsing.h"
16#include "sbuf/SBuf.h"
17
18#include <cstring>
19
21 n_max(0),
22 n_startup(0),
23 n_idle(1),
24 concurrency(0),
25 n_running(0),
26 n_active(0),
27 queue_size(0),
28 onPersistentOverload(actDie),
29 defaultQueueSize(true)
30{}
31
33 n_max(m),
34 n_startup(0),
35 n_idle(1),
36 concurrency(0),
37 n_running(0),
38 n_active(0),
39 queue_size(2 * m),
40 onPersistentOverload(actDie),
41 defaultQueueSize(true)
42{}
43
46{
47 // Copy the limits only.
48 // Preserve the local state values (n_running and n_active)
49 n_max = rhs.n_max;
50 n_startup = rhs.n_startup;
51 n_idle = rhs.n_idle;
52 concurrency = rhs.concurrency;
53 queue_size = rhs.queue_size;
54 onPersistentOverload = rhs.onPersistentOverload;
55 defaultQueueSize = rhs.defaultQueueSize;
56 return *this;
57}
58
59int
61{
62 /* during the startup and reconfigure use our special amount... */
63 if (starting_up || reconfiguring) return n_startup;
64
65 /* keep a minimum of n_idle helpers free... */
66 if ( (n_active + n_idle) < n_max) return n_idle;
67
68 /* do not ever start more than n_max processes. */
69 return (n_max - n_active);
70}
71
72void
74{
75 char const *token = ConfigParser::NextToken();
76
77 if (!token) {
79 return;
80 }
81
82 /* starts with a bare number for the max... back-compatible */
83 n_max = xatoui(token);
84
85 if (n_max < 1) {
86 debugs(0, DBG_CRITICAL, "ERROR: The maximum number of processes cannot be less than 1.");
88 return;
89 }
90
91 /* Parse extension options */
92 for (; (token = ConfigParser::NextToken()) ;) {
93 if (strncmp(token, "startup=", 8) == 0) {
94 n_startup = xatoui(token + 8);
95 } else if (strncmp(token, "idle=", 5) == 0) {
96 n_idle = xatoui(token + 5);
97 if (n_idle < 1) {
98 debugs(0, DBG_CRITICAL, "WARNING: OVERRIDE: Using idle=0 for helpers causes request failures. Overriding to use idle=1 instead.");
99 n_idle = 1;
100 }
101 } else if (strncmp(token, "concurrency=", 12) == 0) {
102 concurrency = xatoui(token + 12);
103 } else if (strncmp(token, "queue-size=", 11) == 0) {
104 queue_size = xatoui(token + 11);
105 defaultQueueSize = false;
106 } else if (strncmp(token, "on-persistent-overload=", 23) == 0) {
107 const SBuf action(token + 23);
108 if (action.cmp("ERR") == 0)
109 onPersistentOverload = actErr;
110 else if (action.cmp("die") == 0)
111 onPersistentOverload = actDie;
112 else {
113 debugs(0, DBG_CRITICAL, "ERROR: Unsupported on-persistent-overloaded action: " << action);
115 return;
116 }
117 } else if (strncmp(token, "reservation-timeout=", 20) == 0)
118 reservationTimeout = xatoui(token + 20);
119 else {
120 debugs(0, DBG_PARSE_NOTE(DBG_IMPORTANT), "ERROR: Undefined option: " << token << ".");
122 return;
123 }
124 }
125
126 /* simple sanity. */
127
128 if (n_startup > n_max) {
129 debugs(0, DBG_CRITICAL, "WARNING: OVERRIDE: Capping startup=" << n_startup << " to the defined maximum (" << n_max <<")");
130 n_startup = n_max;
131 }
132
133 if (n_idle > n_max) {
134 debugs(0, DBG_CRITICAL, "WARNING: OVERRIDE: Capping idle=" << n_idle << " to the defined maximum (" << n_max <<")");
135 n_idle = n_max;
136 }
137
138 if (defaultQueueSize)
139 queue_size = 2 * n_max;
140}
141
unsigned int xatoui(const char *token, char eov)
Definition Parsing.cc:58
void self_destruct(void)
Definition cache_cf.cc:275
static char * NextToken()
unsigned int n_max
Definition ChildConfig.h:48
unsigned int n_startup
Definition ChildConfig.h:57
unsigned int n_idle
Definition ChildConfig.h:66
unsigned int queue_size
Definition ChildConfig.h:91
ChildConfig & updateLimits(const ChildConfig &rhs)
unsigned int concurrency
Definition ChildConfig.h:72
SubmissionErrorHandlingAction onPersistentOverload
how to handle a new request for helper that was overloaded for too long
Definition ChildConfig.h:99
int needNew() const
Definition SBuf.h:94
int cmp(const SBuf &S, const size_type n) const
shorthand version for compare()
Definition SBuf.h:279
#define DBG_PARSE_NOTE(x)
Definition Stream.h:42
#define DBG_IMPORTANT
Definition Stream.h:38
#define debugs(SECTION, LEVEL, CONTENT)
Definition Stream.h:192
#define DBG_CRITICAL
Definition Stream.h:37
int starting_up
int reconfiguring