Changeset a2e53dc0c9ff0d9e50eb095b926924850a6c8ff8

Show
Ignore:
Timestamp:
02/02/08 23:20:43 (7 years ago)
Author:
Theo Schlossnagle <jesus@omniti.com>
git-committer:
Theo Schlossnagle <jesus@omniti.com> 1201994443 +0000
git-parent:

[57a327349609ef60a33dc6da15017c5d6642320a]

git-author:
Theo Schlossnagle <jesus@omniti.com> 1201994443 +0000
Message:

implement staggered start skilz

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • src/modules/http.c

    r57a3273 ra2e53dc  
    718718} 
    719719static int serf_schedule_next(noit_module_t *self, 
    720                               eventer_t e, noit_check_t *check, 
     720                              struct timeval *last_check, noit_check_t *check, 
    721721                              struct timeval *now) { 
    722722  eventer_t newe; 
    723   struct timeval last_check = { 0L, 0L }; 
    724723  struct timeval period, earliest; 
    725724  serf_closure_t *ccl; 
     
    734733  else 
    735734    gettimeofday(&earliest, NULL); 
    736   if(e) memcpy(&last_check, &e->whence, sizeof(last_check)); 
    737735  period.tv_sec = check->period / 1000; 
    738736  period.tv_usec = (check->period % 1000) * 1000; 
    739737 
    740738  newe = eventer_alloc(); 
    741   memcpy(&newe->whence, &last_check, sizeof(last_check)); 
     739  memcpy(&newe->whence, last_check, sizeof(*last_check)); 
    742740  add_timeval(newe->whence, period, &newe->whence); 
    743741  if(compare_timeval(newe->whence, earliest) < 0) 
     
    757755                              struct timeval *now) { 
    758756  serf_closure_t *cl = (serf_closure_t *)closure; 
    759   serf_schedule_next(cl->self, e, cl->check, now); 
     757  serf_schedule_next(cl->self, &e->whence, cl->check, now); 
    760758  serf_initiate(cl->self, cl->check); 
    761759  free(cl); 
     
    770768  } 
    771769  /* If check->fire_event, we're already scheduled... */ 
    772   if(!check->fire_event) 
    773     serf_schedule_next(self, NULL, check, NULL); 
     770  if(!check->fire_event) { 
     771    struct timeval epoch = { 0L, 0L }; 
     772    noit_check_fake_last_check(check, &epoch, NULL); 
     773    serf_schedule_next(self, &epoch, check, NULL); 
     774  } 
    774775  return 0; 
    775776} 
     
    782783    return 0; 
    783784  } 
    784   if(!check->fire_event) 
    785     serf_schedule_next(self, NULL, check, NULL); 
     785  if(!check->fire_event) { 
     786    struct timeval epoch = { 0L, 0L }; 
     787    noit_check_fake_last_check(check, &epoch, NULL); 
     788    serf_schedule_next(self, &epoch, check, NULL); 
     789  } 
    786790  return 0; 
    787791} 
  • src/modules/ping_icmp.c

    r57a3273 ra2e53dc  
    415415} 
    416416static int ping_icmp_schedule_next(noit_module_t *self, 
    417                                    eventer_t e, noit_check_t *check, 
     417                                   struct timeval *last_check, 
     418                                   noit_check_t *check, 
    418419                                   struct timeval *now) { 
    419420  eventer_t newe; 
    420   struct timeval last_check = { 0L, 0L }; 
    421421  struct timeval period, earliest; 
    422422  struct ping_closure *pcl; 
     
    431431  else 
    432432    gettimeofday(&earliest, NULL); 
    433   if(e) memcpy(&last_check, &e->whence, sizeof(last_check)); 
    434433  period.tv_sec = check->period / 1000; 
    435434  period.tv_usec = (check->period % 1000) * 1000; 
    436435 
    437436  newe = eventer_alloc(); 
    438   memcpy(&newe->whence, &last_check, sizeof(last_check)); 
     437  memcpy(&newe->whence, last_check, sizeof(*last_check)); 
    439438  add_timeval(newe->whence, period, &newe->whence); 
    440439  if(compare_timeval(newe->whence, earliest) < 0) 
     
    454453                                   struct timeval *now) { 
    455454  struct ping_closure *cl = (struct ping_closure *)closure; 
    456   ping_icmp_schedule_next(cl->self, e, cl->check, now); 
     455  ping_icmp_schedule_next(cl->self, &e->whence, cl->check, now); 
    457456  ping_icmp_send(cl->self, cl->check); 
    458457  free(cl); 
     
    466465    return 0; 
    467466  } 
    468   if(!check->fire_event) 
    469     ping_icmp_schedule_next(self, NULL, check, NULL); 
     467  if(!check->fire_event) { 
     468    struct timeval epoch; 
     469    noit_check_fake_last_check(check, &epoch, NULL); 
     470    ping_icmp_schedule_next(self, &epoch, check, NULL); 
     471  } 
    470472  return 0; 
    471473} 
  • src/noit_check.c

    r57a3273 ra2e53dc  
    77 
    88#include <stdio.h> 
     9#include <stdlib.h> 
    910#include <unistd.h> 
    1011#include <assert.h> 
     
    2021#include "eventer/eventer.h" 
    2122 
     23/* 60 seconds of possible stutter */ 
     24#define MAX_INITIAL_STUTTER (60*1000) 
     25 
    2226static noit_hash_table polls = NOIT_HASH_EMPTY; 
    2327static noit_skiplist polls_by_name = { 0 }; 
     
    5458  if((rv = strcmp(ac->name, bc->name)) != 0) return rv; 
    5559  return 0; 
     60} 
     61int 
     62noit_check_max_initial_stutter() { 
     63  return MAX_INITIAL_STUTTER; 
     64} 
     65void 
     66noit_check_fake_last_check(noit_check_t *check, 
     67                           struct timeval *lc, struct timeval *_now) { 
     68  struct timeval now, period; 
     69  double r; 
     70  int offset; 
     71 
     72  r = drand48(); 
     73  offset = r * (MIN(MAX_INITIAL_STUTTER, check->period)); 
     74  period.tv_sec = (check->period - offset) / 1000; 
     75  period.tv_usec = ((check->period - offset) % 1000) * 1000; 
     76  if(!_now) { 
     77    gettimeofday(&now, NULL); 
     78    _now = &now; 
     79  } 
     80  sub_timeval(*_now, period, lc); 
    5681} 
    5782void 
  • src/noit_check.h

    r57a3273 ra2e53dc  
    9696API_EXPORT(void) noit_poller_load_checks(); 
    9797 
     98API_EXPORT(void) 
     99  noit_check_fake_last_check(noit_check_t *check, 
     100                             struct timeval *lc, struct timeval *_now); 
     101API_EXPORT(int) noit_check_max_initial_stutter(); 
     102 
    98103API_EXPORT(int) 
    99104  noit_poller_schedule(const char *target,