Index: trunk/willow/src/lib/wlog/wlog.c |
— | — | @@ -34,6 +34,7 @@ |
35 | 35 | |
36 | 36 | static const int syslog_pri[] = { |
37 | 37 | LOG_INFO, |
| 38 | + LOG_INFO, |
38 | 39 | LOG_WARNING, |
39 | 40 | LOG_ERR, |
40 | 41 | }; |
Index: trunk/willow/src/bin/willow/wbackend.c |
— | — | @@ -29,7 +29,7 @@ |
30 | 30 | #include "confparse.h" |
31 | 31 | #include "wconfig.h" |
32 | 32 | |
33 | | -#define rotl(i,r) ((i) << (r) | (i) >> sizeof(i)*CHAR_BIT-(r)); |
| 33 | +#define rotl(i,r) (((i) << (r)) | ((i) >> (sizeof(i)*CHAR_BIT-(r)))) |
34 | 34 | |
35 | 35 | static struct backend **backends; |
36 | 36 | int nbackends; |
— | — | @@ -41,7 +41,8 @@ |
42 | 42 | static uint32_t carp_hosthash(const char *); |
43 | 43 | static uint32_t carp_combine(const char *url, uint32_t host); |
44 | 44 | static void carp_recalc(const char *url); |
45 | | -static int becalc_cmp(const struct backend *a, const struct backend *b); |
| 45 | +static void carp_calc(void); |
| 46 | +static int becalc_cmp(const struct backend **a, const struct backend **b); |
46 | 47 | |
47 | 48 | struct backend_cb_data { |
48 | 49 | struct backend *bc_backend; |
— | — | @@ -86,6 +87,7 @@ |
87 | 88 | if ((backends = wrealloc(backends, sizeof(struct backend*) * ++nbackends)) == NULL) |
88 | 89 | outofmemory(); |
89 | 90 | backends[nbackends - 1] = new_backend(addr, addr, port); |
| 91 | + carp_calc(); |
90 | 92 | wlog(WLOG_NOTICE, "backend: %s:%d", addr, port); |
91 | 93 | } |
92 | 94 | |
— | — | @@ -209,9 +211,13 @@ |
210 | 212 | static int cur = 0; |
211 | 213 | int tried = 0; |
212 | 214 | |
213 | | - if (config.use_carp) |
| 215 | + if (config.use_carp) { |
214 | 216 | carp_recalc(url); |
| 217 | + // cur = 0; |
| 218 | + } |
215 | 219 | |
| 220 | + WDEBUG((WLOG_DEBUG, "next_backend: url=[%s]", url)); |
| 221 | + |
216 | 222 | while (tried++ <= nbackends) { |
217 | 223 | time_t now = time(NULL); |
218 | 224 | |
— | — | @@ -226,6 +232,8 @@ |
227 | 233 | continue; |
228 | 234 | } |
229 | 235 | |
| 236 | + if (config.use_carp) |
| 237 | + cur = 0; |
230 | 238 | return backends[cur++]; |
231 | 239 | } |
232 | 240 | |
— | — | @@ -236,9 +244,11 @@ |
237 | 245 | carp_urlhash(str) |
238 | 246 | const char *str; |
239 | 247 | { |
| 248 | + const char *ostr = str; |
240 | 249 | uint32_t h = 0; |
241 | 250 | for (; *str; ++str) |
242 | | - h += rotl(h, 19) + *str; |
| 251 | + h += (rotl(h, 19) + *str); |
| 252 | + WDEBUG((WLOG_DEBUG, "hash(%s) = %d", ostr, h)); |
243 | 253 | return h; |
244 | 254 | } |
245 | 255 | |
— | — | @@ -267,11 +277,13 @@ |
268 | 278 | int i, j; |
269 | 279 | |
270 | 280 | backends[0]->be_carp = pow((nbackends * backends[0]->be_load), 1.0 / nbackends); |
| 281 | + backends[0]->be_carplfm = 1.0; |
271 | 282 | for (i = 1; i < nbackends; ++i) { |
272 | 283 | float l = 0; |
273 | 284 | be = backends[i]; |
274 | 285 | prev = backends[i - 1]; |
275 | | - be->be_carplfm = ((nbackends-i+1) * (be->be_load - prev->be_load)); |
| 286 | + be->be_carplfm = 1.0 + ((nbackends-i+1) * (be->be_load - prev->be_load)); |
| 287 | + WDEBUG((WLOG_DEBUG, "carp_calc: %s lfm = %f", be->be_name, be->be_carplfm)); |
276 | 288 | for (j = 0; j < i; ++j) |
277 | 289 | l *= backends[j]->be_carp; |
278 | 290 | be->be_carp /= l; |
— | — | @@ -291,14 +303,21 @@ |
292 | 304 | hash += hash * 0x62531965; |
293 | 305 | hash = rotl(hash, 21); |
294 | 306 | hash *= backends[i]->be_carplfm; |
| 307 | + WDEBUG((WLOG_DEBUG, "%s: hash = %lu, lfm = %f", backends[i]->be_name, hash, backends[i]->be_carplfm)); |
295 | 308 | backends[i]->be_carp = hash; |
296 | 309 | } |
297 | 310 | qsort(backends, nbackends, sizeof(struct backend *), becalc_cmp); |
| 311 | + WDEBUG((WLOG_DEBUG, "first backend = %s", backends[0]->be_name)); |
298 | 312 | } |
299 | 313 | |
300 | 314 | static int |
301 | 315 | becalc_cmp(a, b) |
302 | | -const struct backend *a, *b; |
| 316 | +const struct backend **a, **b; |
303 | 317 | { |
304 | | - return a->be_carp - b->be_carp; |
| 318 | + WDEBUG((WLOG_DEBUG, "compare %s(%lu)/%s(%lu)", (*a)->be_name, (*a)->be_carp, (*b)->be_name, (*b)->be_carp)); |
| 319 | + if ((*a)->be_carp < (*b)->be_carp) |
| 320 | + return -1; |
| 321 | + else if ((*a)->be_carp == (*b)->be_carp) |
| 322 | + return 0; |
| 323 | + return 1; |
305 | 324 | } |
Index: trunk/willow/src/bin/willow/whttp_entity.c |
— | — | @@ -972,8 +972,8 @@ |
973 | 973 | char *line; |
974 | 974 | |
975 | 975 | while (line = evbuffer_readline(entity->_he_frombuf->input)) { |
976 | | - char **hdr; |
977 | | - char *value; |
| 976 | + char **hdr = NULL; |
| 977 | + char *value = NULL; |
978 | 978 | int error = 1; |
979 | 979 | |
980 | 980 | if (!line) |
Index: trunk/willow/src/bin/willow/whttp.c |
— | — | @@ -321,7 +321,7 @@ |
322 | 322 | /* |
323 | 323 | * Check for cached object. |
324 | 324 | */ |
325 | | - if (client->cl_reqtype == REQTYPE_GET) { |
| 325 | + if (config.ncaches && client->cl_reqtype == REQTYPE_GET) { |
326 | 326 | if (cacheable) |
327 | 327 | client->cl_co = wcache_find_object(client->cl_path, &client->cl_cfd, |
328 | 328 | WCACHE_RDWR); |