]> git.ipfire.org Git - thirdparty/squid.git/blob - src/DelayUser.cc
Summary: Merge delay class 4 performance enhancements.
[thirdparty/squid.git] / src / DelayUser.cc
1
2 /*
3 * $Id: DelayUser.cc,v 1.3 2003/02/08 01:45:47 robertc Exp $
4 *
5 * DEBUG: section 77 Delay Pools
6 * AUTHOR: Robert Collins <robertc@squid-cache.org>
7 *
8 * SQUID Web Proxy Cache http://www.squid-cache.org/
9 * ----------------------------------------------------------
10 *
11 * Squid is the result of efforts by numerous individuals from
12 * the Internet community; see the CONTRIBUTORS file for full
13 * details. Many organizations have provided support for Squid's
14 * development; see the SPONSORS file for full details. Squid is
15 * Copyrighted (C) 2001 by the Regents of the University of
16 * California; see the COPYRIGHT file for full details. Squid
17 * incorporates software developed and/or copyrighted by other
18 * sources; see the CREDITS file for full details.
19 *
20 * This program is free software; you can redistribute it and/or modify
21 * it under the terms of the GNU General Public License as published by
22 * the Free Software Foundation; either version 2 of the License, or
23 * (at your option) any later version.
24 *
25 * This program is distributed in the hope that it will be useful,
26 * but WITHOUT ANY WARRANTY; without even the implied warranty of
27 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28 * GNU General Public License for more details.
29 *
30 * You should have received a copy of the GNU General Public License
31 * along with this program; if not, write to the Free Software
32 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
33 *
34 *
35 * Copyright (c) 2003, Robert Collins <robertc@squid-cache.org>
36 */
37
38 #include "config.h"
39
40 #if DELAY_POOLS
41 #include "squid.h"
42 #include "DelayUser.h"
43 #include "authenticate.h"
44 #include "NullDelayId.h"
45 #include "Store.h"
46
47 void *
48 DelayUser::operator new(size_t size)
49 {
50 DelayPools::MemoryUsed += sizeof (DelayUser);
51 return ::operator new (size);
52 }
53
54 void
55 DelayUser::operator delete (void *address)
56 {
57 DelayPools::MemoryUsed -= sizeof (DelayUser);
58 ::operator delete (address);
59 }
60
61 void
62 DelayUser::deleteSelf() const
63 {
64 delete this;
65 }
66
67 DelayUser::DelayUser()
68 {
69 DelayPools::registerForUpdates (this);
70 }
71
72 static SplayNode<DelayUserBucket::Pointer>::SPLAYFREE DelayUserFree;
73
74 DelayUser::~DelayUser()
75 {
76 DelayPools::deregisterForUpdates (this);
77 buckets.head->destroy (DelayUserFree);
78 }
79
80 static SplayNode<DelayUserBucket::Pointer>::SPLAYCMP DelayUserCmp;
81
82 int
83 DelayUserCmp(DelayUserBucket::Pointer const &left, DelayUserBucket::Pointer const &right)
84 {
85 /* for rate limiting, case insensitive */
86 return strcasecmp(left->authUser->username(), right->authUser->username());
87 }
88
89 void
90 DelayUserFree(DelayUserBucket::Pointer &)
91 {
92 }
93
94 void
95 DelayUserStatsWalkee(DelayUserBucket::Pointer const &current, void *state)
96 {
97 current->stats ((StoreEntry *)state);
98 }
99
100 void
101 DelayUser::stats(StoreEntry * sentry)
102 {
103 spec.stats (sentry, "Per User");
104 if (spec.restore_bps == -1)
105 return;
106 storeAppendPrintf(sentry, "\t\tCurrent: ");
107 if (!buckets.head) {
108 storeAppendPrintf (sentry, "Not used yet.\n\n");
109 return;
110 }
111 buckets.head->walk(DelayUserStatsWalkee, sentry);
112 storeAppendPrintf(sentry, "\n\n");
113 }
114
115 void
116 DelayUser::dump(StoreEntry *entry) const
117 {
118 spec.dump(entry);
119 }
120
121 struct DelayUserUpdater
122 {
123 DelayUserUpdater (DelaySpec &_spec, int _incr):spec(_spec),incr(_incr){};
124 DelaySpec spec;
125 int incr;
126 };
127 void
128 DelayUserUpdateWalkee(DelayUserBucket::Pointer const &current, void *state)
129 {
130 DelayUserUpdater *t = (DelayUserUpdater *)state;
131 /* This doesn't change the value of the DelayUserBucket, so is safe */
132 const_cast<DelayUserBucket *>(current.getRaw())->theBucket.update(t->spec, t->incr);
133 }
134 void
135 DelayUser::update(int incr)
136 {
137 DelayUserUpdater updater(spec, incr);
138 buckets.head->walk (DelayUserUpdateWalkee, &updater);
139 }
140
141 void
142 DelayUser::parse()
143 {
144 spec.parse();
145 }
146
147 DelayIdComposite::Pointer
148 DelayUser::id(struct in_addr &src_addr, AuthUserRequest *authRequest)
149 {
150 if (!authRequest)
151 return new NullDelayId;
152 return new Id(this, authRequest->auth_user);
153 }
154
155 void *
156 DelayUser::Id::operator new(size_t size)
157 {
158 DelayPools::MemoryUsed += sizeof (Id);
159 return ::operator new (size);
160 }
161
162 void
163 DelayUser::Id::operator delete (void *address)
164 {
165 DelayPools::MemoryUsed -= sizeof (Id);
166 ::operator delete (address);
167 }
168
169 void
170 DelayUser::Id::deleteSelf() const
171 {
172 delete this;
173 }
174
175 void *
176 DelayUserBucket::operator new(size_t size)
177 {
178 DelayPools::MemoryUsed += sizeof (DelayUserBucket);
179 return ::operator new (size);
180 }
181
182 void
183 DelayUserBucket::operator delete (void *address)
184 {
185 DelayPools::MemoryUsed -= sizeof (DelayUserBucket);
186 ::operator delete (address);
187 }
188
189 DelayUserBucket::DelayUserBucket(AuthUser *aUser) : authUser (aUser)
190 {
191 debug (77,3) ("DelayUserBucket::DelayUserBucket\n");
192 authenticateAuthUserLock (authUser);
193 }
194
195 DelayUserBucket::~DelayUserBucket()
196 {
197 authenticateAuthUserUnlock(authUser);
198 debug (77,3) ("DelayUserBucket::~DelayUserBucket\n");
199 }
200
201 void
202 DelayUserBucket::stats (StoreEntry *entry) const
203 {
204 storeAppendPrintf(entry, " %s:", authUser->username());
205 theBucket.stats (entry);
206 }
207
208 DelayUser::Id::Id(DelayUser::Pointer aDelayUser,AuthUser *aUser) : theUser(aDelayUser)
209 {
210 theBucket = new DelayUserBucket(aUser);
211 DelayUserBucket::Pointer const *existing = theUser->buckets.find(theBucket, DelayUserCmp);
212 if (existing) {
213 theBucket = *existing;
214 return;
215 }
216 theBucket->theBucket.init(theUser->spec);
217 theUser->buckets.head = theUser->buckets.head->insert (theBucket, DelayUserCmp);
218 }
219
220 DelayUser::Id::~Id()
221 {
222 debug (77,3) ("DelayUser::Id::~Id\n");
223 }
224
225 int
226 DelayUser::Id::bytesWanted (int min, int max) const
227 {
228 return theBucket->theBucket.bytesWanted(min,max);
229 }
230
231 void
232 DelayUser::Id::bytesIn(int qty)
233 {
234 theBucket->theBucket.bytesIn(qty);
235 }
236 #endif