Changeset 7fe430
- Timestamp:
- 01/18/08 16:37:01 (4 years ago)
- Branches:
- master-v0.7, master-v0.6, memcached_hash, upstream_count_limit
- Children:
- 1e6e0c
- Parents:
- cab62c
- git-author:
- Tomash Brechko <tomash.brechko@…> (01/18/08 16:37:01)
- git-committer:
- Tomash Brechko <tomash.brechko@…> (01/18/08 16:37:01)
- Location:
- memcached_hash
- Files:
-
- 2 edited
-
TODO (modified) (1 diff)
-
ngx_http_upstream_memcached_hash_module.c (modified) (12 diffs)
Legend:
- Unmodified
- Added
- Removed
-
memcached_hash/TODO
r4cec36 r7fe430 5 5 - Add populate.pl to the distribution. 6 6 7 - Rename bins to buckets.7 - Implement cache of open connections to upstreams. -
memcached_hash/ngx_http_upstream_memcached_hash_module.c
rc90b2b r7fe430 36 36 struct memcached_hash 37 37 { 38 struct memcached_hash_continuum *b ins;38 struct memcached_hash_continuum *buckets; 39 39 struct memcached_hash_peer *peers; 40 unsigned int b ins_count;40 unsigned int buckets_count; 41 41 unsigned int peer_count; 42 42 unsigned int total_weight; … … 56 56 static 57 57 unsigned int 58 memcached_hash_find_b in(struct memcached_hash *memd, unsigned int point)58 memcached_hash_find_bucket(struct memcached_hash *memd, unsigned int point) 59 59 { 60 60 struct memcached_hash_continuum *left, *right; 61 61 62 left = memd->b ins;63 right = memd->b ins + memd->bins_count;62 left = memd->buckets; 63 right = memd->buckets + memd->buckets_count; 64 64 65 65 while (left < right) … … 71 71 right = middle; 72 72 else 73 return (middle - memd->b ins);73 return (middle - memd->buckets); 74 74 } 75 75 76 76 /* Wrap around. */ 77 if (left == memd->b ins + memd->bins_count)78 left = memd->b ins;79 80 return (left - memd->b ins);77 if (left == memd->buckets + memd->buckets_count) 78 left = memd->buckets; 79 80 return (left - memd->buckets); 81 81 } 82 82 … … 125 125 u_char *key; 126 126 size_t len; 127 unsigned int point, b in, index;127 unsigned int point, bucket, index; 128 128 129 129 if (memd->peer_count == 1) … … 153 153 /* 154 154 Shift point one step forward to possibly get from the 155 border point which belongs to the previous b in.155 border point which belongs to the previous bucket. 156 156 */ 157 157 point += 1; 158 158 } 159 159 160 b in = memcached_hash_find_bin(memd, point);161 index = memd->b ins[bin].index;160 bucket = memcached_hash_find_bucket(memd, point); 161 index = memd->buckets[bucket].index; 162 162 } 163 163 … … 241 241 struct memcached_hash *memd = us->peer.data; 242 242 ngx_http_upstream_server_t *server; 243 unsigned int b ins_count, i;243 unsigned int buckets_count, i; 244 244 245 245 if (! us->servers) … … 267 267 if (memd->ketama_points == 0) 268 268 { 269 b ins_count = us->servers->nelts;269 buckets_count = us->servers->nelts; 270 270 } 271 271 else 272 272 { 273 b ins_count = 0;273 buckets_count = 0; 274 274 for (i = 0; i < us->servers->nelts; ++i) 275 b ins_count += (memd->ketama_points * server[i].weight276 + memd->scale / 2) / memd->scale;277 } 278 279 memd->b ins = ngx_palloc(cf->pool, sizeof(*memd->bins) * bins_count);280 if (! memd->b ins)275 buckets_count += (memd->ketama_points * server[i].weight 276 + memd->scale / 2) / memd->scale; 277 } 278 279 memd->buckets = ngx_palloc(cf->pool, sizeof(*memd->buckets) * buckets_count); 280 if (! memd->buckets) 281 281 return NGX_ERROR; 282 282 … … 291 291 for (j = 0; j < i; ++j) 292 292 { 293 memd->b ins[j].point =294 (memd->b ins[j].point295 - ((uint64_t) memd->b ins[j].point * server[i].weight293 memd->buckets[j].point = 294 (memd->buckets[j].point 295 - ((uint64_t) memd->buckets[j].point * server[i].weight 296 296 + total_weight / 2) / total_weight); 297 297 } 298 298 299 memd->b ins[i].point = CONTINUUM_MAX_POINT;300 memd->b ins[i].index = i;301 } 302 memd->b ins_count = bins_count;299 memd->buckets[i].point = CONTINUUM_MAX_POINT; 300 memd->buckets[i].index = i; 301 } 302 memd->buckets_count = buckets_count; 303 303 } 304 304 else 305 305 { 306 memd->b ins_count = 0;306 memd->buckets_count = 0; 307 307 for (i = 0; i < us->servers->nelts; ++i) 308 308 { … … 344 344 { 345 345 u_char buf[4]; 346 unsigned int point = crc32, b in;346 unsigned int point = crc32, bucket; 347 347 348 348 /* … … 358 358 ngx_crc32_final(point); 359 359 360 if (memd->b ins_count > 0)360 if (memd->buckets_count > 0) 361 361 { 362 b in = memcached_hash_find_bin(memd, point);362 bucket = memcached_hash_find_bucket(memd, point); 363 363 364 364 /* … … 366 366 max point. 367 367 */ 368 if (b in == 0 && point > memd->bins[0].point)368 if (bucket == 0 && point > memd->buckets[0].point) 369 369 { 370 b in = memd->bins_count;370 bucket = memd->buckets_count; 371 371 } 372 372 else 373 373 { 374 if (point == memd->b ins[bin].point)374 if (point == memd->buckets[bucket].point) 375 375 { 376 376 /* … … 381 381 server for not to change key distribution. 382 382 */ 383 ++b in;383 ++bucket; 384 384 } 385 385 386 386 /* Move the tail one position forward. */ 387 ngx_memmove(memd->bins + bin + 1, memd->bins + bin, 388 ((memd->bins_count - bin) 389 * sizeof(*memd->bins))); 387 ngx_memmove(memd->buckets + bucket + 1, 388 memd->buckets + bucket, 389 ((memd->buckets_count - bucket) 390 * sizeof(*memd->buckets))); 390 391 } 391 392 } 392 393 else 393 394 { 394 b in= 0;395 bucket = 0; 395 396 } 396 397 397 memd->b ins[bin].point = point;398 memd->b ins[bin].index = i;399 400 ++memd->b ins_count;398 memd->buckets[bucket].point = point; 399 memd->buckets[bucket].index = i; 400 401 ++memd->buckets_count; 401 402 } 402 403 }
Note: See TracChangeset
for help on using the changeset viewer.
