]>
git.ipfire.org Git - thirdparty/squid.git/blob - src/MessageDelayPools.h
2 * Copyright (C) 1996-2023 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.
9 #ifndef SQUID_SRC_MESSAGEDELAYPOOLS_H
10 #define SQUID_SRC_MESSAGEDELAYPOOLS_H
15 #include "base/RefCount.h"
16 #include "DelayBucket.h"
17 #include "DelayPools.h"
18 #include "sbuf/SBuf.h"
21 typedef RefCount
<MessageBucket
> MessageBucketPointer
;
23 /// \ingroup DelayPoolsAPI
24 /// Represents one 'response' delay pool, creates individual response
25 /// buckets and performes aggregate limiting for them
26 class MessageDelayPool
: public RefCountable
29 typedef RefCount
<MessageDelayPool
> Pointer
;
31 MessageDelayPool(const SBuf
&name
, int64_t bucketSpeed
, int64_t bucketSize
,
32 int64_t aggregateSpeed
, int64_t aggregateSize
, uint16_t initialBucketPercent
);
33 ~MessageDelayPool() override
;
34 MessageDelayPool(const MessageDelayPool
&) = delete;
35 MessageDelayPool
&operator=(const MessageDelayPool
&) = delete;
37 /// Increases the aggregate bucket level with the aggregateRestore speed.
39 /// decreases the aggregate level
40 void bytesIn(int qty
) { if (!noLimit()) theBucket
.bytesIn(qty
); }
41 /// current aggregate level
42 int level() { return theBucket
.level(); }
43 /// creates an individual response bucket
44 MessageBucketPointer
createBucket();
45 /// whether the aggregate bucket has no limit
46 bool noLimit () const { return aggregateRestore
< 0; }
48 void dump (StoreEntry
* entry
) const;
51 /// the response delay pool name
53 /// the speed limit of an individual bucket (bytes/s)
54 int64_t individualRestore
;
55 /// the maximum size of an individual bucket
56 int64_t individualMaximum
;
57 /// the speed limit of the aggregate bucket (bytes/s)
58 int64_t aggregateRestore
;
59 /// the maximum size of the aggregate bucket
60 int64_t aggregateMaximum
;
61 /// the initial bucket size as a percentage of individualMaximum
62 uint16_t initialBucketLevel
;
63 /// the aggregate bucket
64 DelayBucket theBucket
;
67 /// Time the aggregate bucket level was last refilled.
71 /// \ingroup DelayPoolsAPI
72 /// represents all configured 'response' delay pools
73 class MessageDelayPools
76 MessageDelayPools(const MessageDelayPools
&) = delete;
77 MessageDelayPools
&operator=(const MessageDelayPools
&) = delete;
79 static MessageDelayPools
*Instance();
81 /// returns a MessageDelayPool with a given name or null otherwise
82 MessageDelayPool::Pointer
pool(const SBuf
&name
);
83 /// appends a single MessageDelayPool, created during configuration
84 void add(MessageDelayPool
*pool
);
85 /// memory cleanup, performing during reconfiguration
88 std::vector
<MessageDelayPool::Pointer
> pools
;
91 MessageDelayPools() {}
93 void Stats() { } // TODO
96 /// represents configuration for response delay pools
97 class MessageDelayConfig
100 void parseResponseDelayPool();
101 void dumpResponseDelayPoolParameters(StoreEntry
*);
102 void parseResponseDelayPoolAccess();
106 #define free_response_delay_pool_access(X)
107 #define dump_response_delay_pool_access(X, Y, Z)
110 free_response_delay_pool_parameters(MessageDelayConfig
* cfg
)
116 dump_response_delay_pool_parameters(StoreEntry
*entry
, const char *, MessageDelayConfig
&cfg
)
118 cfg
.dumpResponseDelayPoolParameters(entry
);
122 parse_response_delay_pool_parameters(MessageDelayConfig
* cfg
)
124 cfg
->parseResponseDelayPool();
128 parse_response_delay_pool_access(MessageDelayConfig
* cfg
)
130 cfg
->parseResponseDelayPoolAccess();
134 #endif /* SQUID_SRC_MESSAGEDELAYPOOLS_H */