ChildConfig.cc
Go to the documentation of this file.
1/*
2 * Copyright (C) 1996-2022 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
17#include <cstring>
18
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 onPersistentOverload(actDie),
28 defaultQueueSize(true)
29{}
30
32 n_max(m),
33 n_startup(0),
34 n_idle(1),
35 concurrency(0),
36 n_running(0),
37 n_active(0),
38 queue_size(2 * m),
39 onPersistentOverload(actDie),
40 defaultQueueSize(true)
41{}
42
45{
46 // Copy the limits only.
47 // Preserve the local state values (n_running and n_active)
48 n_max = rhs.n_max;
49 n_startup = rhs.n_startup;
50 n_idle = rhs.n_idle;
51 concurrency = rhs.concurrency;
52 queue_size = rhs.queue_size;
53 onPersistentOverload = rhs.onPersistentOverload;
54 defaultQueueSize = rhs.defaultQueueSize;
55 return *this;
56}
57
58int
60{
61 /* during the startup and reconfigure use our special amount... */
62 if (starting_up || reconfiguring) return n_startup;
63
64 /* keep a minimum of n_idle helpers free... */
65 if ( (n_active + n_idle) < n_max) return n_idle;
66
67 /* do not ever start more than n_max processes. */
68 return (n_max - n_active);
69}
70
71void
73{
74 char const *token = ConfigParser::NextToken();
75
76 if (!token) {
78 return;
79 }
80
81 /* starts with a bare number for the max... back-compatible */
82 n_max = xatoui(token);
83
84 if (n_max < 1) {
85 debugs(0, DBG_CRITICAL, "ERROR: The maximum number of processes cannot be less than 1.");
87 return;
88 }
89
90 /* Parse extension options */
91 for (; (token = ConfigParser::NextToken()) ;) {
92 if (strncmp(token, "startup=", 8) == 0) {
93 n_startup = xatoui(token + 8);
94 } else if (strncmp(token, "idle=", 5) == 0) {
95 n_idle = xatoui(token + 5);
96 if (n_idle < 1) {
97 debugs(0, DBG_CRITICAL, "WARNING: OVERRIDE: Using idle=0 for helpers causes request failures. Overriding to use idle=1 instead.");
98 n_idle = 1;
99 }
100 } else if (strncmp(token, "concurrency=", 12) == 0) {
101 concurrency = xatoui(token + 12);
102 } else if (strncmp(token, "queue-size=", 11) == 0) {
103 queue_size = xatoui(token + 11);
104 defaultQueueSize = false;
105 } else if (strncmp(token, "on-persistent-overload=", 23) == 0) {
106 const SBuf action(token + 23);
107 if (action.cmp("ERR") == 0)
108 onPersistentOverload = actErr;
109 else if (action.cmp("die") == 0)
110 onPersistentOverload = actDie;
111 else {
112 debugs(0, DBG_CRITICAL, "ERROR: Unsupported on-persistent-overloaded action: " << action);
114 return;
115 }
116 } else if (strncmp(token, "reservation-timeout=", 20) == 0)
117 reservationTimeout = xatoui(token + 20);
118 else {
119 debugs(0, DBG_PARSE_NOTE(DBG_IMPORTANT), "ERROR: Undefined option: " << token << ".");
121 return;
122 }
123 }
124
125 /* simple sanity. */
126
127 if (n_startup > n_max) {
128 debugs(0, DBG_CRITICAL, "WARNING: OVERRIDE: Capping startup=" << n_startup << " to the defined maximum (" << n_max <<")");
129 n_startup = n_max;
130 }
131
132 if (n_idle > n_max) {
133 debugs(0, DBG_CRITICAL, "WARNING: OVERRIDE: Capping idle=" << n_idle << " to the defined maximum (" << n_max <<")");
134 n_idle = n_max;
135 }
136
137 if (defaultQueueSize)
138 queue_size = 2 * n_max;
139}
140
#define true
Definition: GnuRegex.c:241
unsigned int xatoui(const char *token, char eov)
Definition: Parsing.cc:58
void self_destruct(void)
Definition: cache_cf.cc:276
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)
Definition: ChildConfig.cc:44
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: ChildConfig.cc:59
Definition: SBuf.h:94
#define DBG_PARSE_NOTE(x)
Definition: Stream.h:45
#define DBG_IMPORTANT
Definition: Stream.h:41
#define debugs(SECTION, LEVEL, CONTENT)
Definition: Stream.h:196
#define DBG_CRITICAL
Definition: Stream.h:40
int starting_up
int reconfiguring
static bool action(int fd, size_t metasize, const char *fn, const char *url, const SquidMetaList &meta)
Definition: purge.cc:311

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors