]>
Commit | Line | Data |
---|---|---|
b27668ec | 1 | /* |
b8ae064d | 2 | * Copyright (C) 1996-2023 The Squid Software Foundation and contributors |
b27668ec EB |
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 | #ifndef MESSAGEDELAYPOOLS_H | |
10 | #define MESSAGEDELAYPOOLS_H | |
11 | ||
12 | #if USE_DELAY_POOLS | |
13 | ||
14 | #include "acl/Acl.h" | |
15 | #include "base/RefCount.h" | |
16 | #include "DelayBucket.h" | |
17 | #include "DelayPools.h" | |
4eac3407 | 18 | #include "sbuf/SBuf.h" |
b27668ec EB |
19 | |
20 | class MessageBucket; | |
21 | typedef RefCount<MessageBucket> MessageBucketPointer; | |
22 | ||
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 | |
27 | { | |
28 | public: | |
29 | typedef RefCount<MessageDelayPool> Pointer; | |
30 | ||
31 | MessageDelayPool(const SBuf &name, int64_t bucketSpeed, int64_t bucketSize, | |
32 | int64_t aggregateSpeed, int64_t aggregateSize, uint16_t initialBucketPercent); | |
337b9aa4 | 33 | ~MessageDelayPool() override; |
b27668ec EB |
34 | MessageDelayPool(const MessageDelayPool &) = delete; |
35 | MessageDelayPool &operator=(const MessageDelayPool &) = delete; | |
36 | ||
37 | /// Increases the aggregate bucket level with the aggregateRestore speed. | |
38 | void refillBucket(); | |
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; } | |
47 | ||
48 | void dump (StoreEntry * entry) const; | |
49 | ||
50 | acl_access *access; | |
51 | /// the response delay pool name | |
52 | SBuf poolName; | |
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; | |
65 | ||
66 | private: | |
67 | /// Time the aggregate bucket level was last refilled. | |
68 | time_t lastUpdate; | |
69 | }; | |
70 | ||
71 | /// \ingroup DelayPoolsAPI | |
72 | /// represents all configured 'response' delay pools | |
73 | class MessageDelayPools | |
74 | { | |
75 | public: | |
76 | MessageDelayPools(const MessageDelayPools &) = delete; | |
77 | MessageDelayPools &operator=(const MessageDelayPools &) = delete; | |
78 | ||
79 | static MessageDelayPools *Instance(); | |
80 | ||
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 | |
86 | void freePools(); | |
87 | ||
88 | std::vector<MessageDelayPool::Pointer> pools; | |
89 | ||
90 | private: | |
91 | MessageDelayPools() {} | |
92 | ~MessageDelayPools(); | |
93 | void Stats() { } // TODO | |
94 | }; | |
95 | ||
96 | /// represents configuration for response delay pools | |
97 | class MessageDelayConfig | |
98 | { | |
99 | public: | |
100 | void parseResponseDelayPool(); | |
8b082ed9 | 101 | void dumpResponseDelayPoolParameters(StoreEntry *); |
b27668ec EB |
102 | void parseResponseDelayPoolAccess(); |
103 | void freePools(); | |
104 | }; | |
105 | ||
106 | #define free_response_delay_pool_access(X) | |
107 | #define dump_response_delay_pool_access(X, Y, Z) | |
108 | ||
109 | inline void | |
110 | free_response_delay_pool_parameters(MessageDelayConfig * cfg) | |
111 | { | |
112 | cfg->freePools(); | |
113 | } | |
114 | ||
115 | inline void | |
8b082ed9 | 116 | dump_response_delay_pool_parameters(StoreEntry *entry, const char *, MessageDelayConfig &cfg) |
b27668ec | 117 | { |
8b082ed9 | 118 | cfg.dumpResponseDelayPoolParameters(entry); |
b27668ec EB |
119 | } |
120 | ||
121 | inline void | |
122 | parse_response_delay_pool_parameters(MessageDelayConfig * cfg) | |
123 | { | |
124 | cfg->parseResponseDelayPool(); | |
125 | } | |
126 | ||
127 | inline void | |
128 | parse_response_delay_pool_access(MessageDelayConfig * cfg) | |
129 | { | |
130 | cfg->parseResponseDelayPoolAccess(); | |
131 | } | |
132 | ||
133 | #endif | |
134 | #endif | |
135 |