]>
git.ipfire.org Git - thirdparty/squid.git/blob - src/MessageDelayPools.cc
2 * Copyright (C) 1996-2018 The Squid Software Foundation and contributors
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.
12 #include "acl/Gadgets.h"
14 #include "ConfigParser.h"
15 #include "DelaySpec.h"
17 #include "MessageBucket.h"
18 #include "MessageDelayPools.h"
20 #include "SquidTime.h"
26 MessageDelayPools::~MessageDelayPools()
32 MessageDelayPools::Instance()
34 static MessageDelayPools pools
;
38 MessageDelayPool::Pointer
39 MessageDelayPools::pool(const SBuf
&name
)
41 auto it
= std::find_if(pools
.begin(), pools
.end(),
42 [&name
](const MessageDelayPool::Pointer p
) { return p
->poolName
== name
; });
43 return it
== pools
.end() ? 0 : *it
;
47 MessageDelayPools::add(MessageDelayPool
*p
)
49 const auto it
= std::find_if(pools
.begin(), pools
.end(),
50 [&p
](const MessageDelayPool::Pointer mp
) { return mp
->poolName
== p
->poolName
; });
51 if (it
!= pools
.end()) {
52 debugs(3, DBG_CRITICAL
, "WARNING: Ignoring duplicate " << p
->poolName
<< " response delay pool");
59 MessageDelayPools::freePools()
64 MessageDelayPool::MessageDelayPool(const SBuf
&name
, int64_t bucketSpeed
, int64_t bucketSize
,
65 int64_t aggregateSpeed
, int64_t aggregateSize
, uint16_t initialBucketPercent
):
68 individualRestore(bucketSpeed
),
69 individualMaximum(bucketSize
),
70 aggregateRestore(aggregateSpeed
),
71 aggregateMaximum(aggregateSize
),
72 initialBucketLevel(initialBucketPercent
),
73 lastUpdate(squid_curtime
)
75 theBucket
.level() = aggregateMaximum
;
78 MessageDelayPool::~MessageDelayPool()
81 aclDestroyAccessList(&access
);
85 MessageDelayPool::refillBucket()
89 const int incr
= squid_curtime
- lastUpdate
;
91 lastUpdate
= squid_curtime
;
93 spec
.restore_bps
= aggregateRestore
;
94 spec
.max_bytes
= aggregateMaximum
;
95 theBucket
.update(spec
, incr
);
100 MessageDelayPool::dump(StoreEntry
*entry
) const
102 SBuf
name("response_delay_pool_access ");
103 name
.append(poolName
);
104 dump_acl_access(entry
, name
.c_str(), access
);
105 storeAppendPrintf(entry
, "response_delay_pool parameters %" PRId64
" %" PRId64
" %" PRId64
" %" PRId64
" %d\n",
106 individualRestore
, individualMaximum
, aggregateRestore
, aggregateMaximum
, initialBucketLevel
);
107 storeAppendPrintf(entry
, "\n");
110 MessageBucket::Pointer
111 MessageDelayPool::createBucket()
113 return new MessageBucket(individualRestore
, initialBucketLevel
, individualMaximum
, this);
117 MessageDelayConfig::parseResponseDelayPool()
119 static const SBuf
bucketSpeedLimit("individual-restore");
120 static const SBuf
maxBucketSize("individual-maximum");
121 static const SBuf
aggregateSpeedLimit("aggregate-restore");
122 static const SBuf
maxAggregateSize("aggregate-maximum");
123 static const SBuf
initialBucketPercent("initial-bucket-level");
125 static std::map
<SBuf
, int64_t> params
;
126 params
[bucketSpeedLimit
] = -1;
127 params
[maxBucketSize
] = -1;
128 params
[aggregateSpeedLimit
] = -1;
129 params
[maxAggregateSize
] = -1;
130 params
[initialBucketPercent
] = 50;
132 const SBuf
name(ConfigParser::NextToken());
133 if (name
.isEmpty()) {
134 debugs(3, DBG_CRITICAL
, "FATAL: response_delay_pool missing required \"name\" parameter.");
140 char *value
= nullptr;
141 while (ConfigParser::NextKvPair(key
, value
)) {
143 debugs(3, DBG_CRITICAL
, "FATAL: '" << key
<< "' option missing value");
147 auto it
= params
.find(SBuf(key
));
148 if (it
== params
.end()) {
149 debugs(3, DBG_CRITICAL
, "FATAL: response_delay_pool unknown option '" << key
<< "'");
153 it
->second
= (it
->first
== initialBucketPercent
) ? xatos(value
) : xatoll(value
, 10);
156 const char *fatalMsg
= nullptr;
157 if ((params
[bucketSpeedLimit
] < 0) != (params
[maxBucketSize
] < 0))
158 fatalMsg
= "'individual-restore' and 'individual-maximum'";
159 else if ((params
[aggregateSpeedLimit
] < 0) != (params
[maxAggregateSize
] < 0))
160 fatalMsg
= "'aggregate-restore' and 'aggregate-maximum'";
163 debugs(3, DBG_CRITICAL
, "FATAL: must use " << fatalMsg
<< " options in conjunction");
168 MessageDelayPool
*pool
= new MessageDelayPool(name
,
169 params
[bucketSpeedLimit
],
170 params
[maxBucketSize
],
171 params
[aggregateSpeedLimit
],
172 params
[maxAggregateSize
],
173 static_cast<uint16_t>(params
[initialBucketPercent
])
175 MessageDelayPools::Instance()->add(pool
);
179 MessageDelayConfig::parseResponseDelayPoolAccess() {
180 const char *token
= ConfigParser::NextToken();
182 debugs(3, DBG_CRITICAL
, "ERROR: required pool_name option missing");
185 MessageDelayPool::Pointer pool
= MessageDelayPools::Instance()->pool(SBuf(token
));
186 static ConfigParser parser
;
188 aclParseAccessLine("response_delay_pool_access", parser
, &pool
->access
);
192 MessageDelayConfig::freePools()
194 MessageDelayPools::Instance()->freePools();
198 MessageDelayConfig::dumpResponseDelayPoolParameters(StoreEntry
*entry
, const char *name
)
200 auto &pools
= MessageDelayPools::Instance()->pools
;
201 for (auto pool
: pools
)