Skip to content

Commit

Permalink
Switched HB generator to exponential delay
Browse files Browse the repository at this point in the history
  • Loading branch information
hoh committed Aug 13, 2014
1 parent 8a711ed commit 9ee3988
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions hubbub/generator/heartbeat.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,15 @@ class HeartBeatGenerator(Generator):
Generates new messages at relatively constant time intervals.
(relatively = random around an average)
'''
period = 2 # average period between messages, in seconds
period = 5 # average period between messages, in seconds

def delay(self):
random()**2 * self.period * 2 # TODO: Add exponential delay

def run(self):
while True:
print('generator: new loop')
delay = random()**2 * self.period * 2 # TODO: Add exponential delay
delay = self.delay()
try:
# We get a real message
# TODO: Distinguish between received and sent messages !!!
Expand All @@ -59,7 +62,8 @@ class HeartBeatSimulator(Simulator):
period = 5

def delay(self):
return self.period * 2 * random()**2
#return self.period * 2 * random()**2
return instance.period * 1 * -log(random.random())

def run(self, delay=None):
delay = delay or self.delay
Expand Down

0 comments on commit 9ee3988

Please sign in to comment.