increasing delayfactor punishment a bit; adding speed control

This commit is contained in:
Ryan Tucker 2009-12-29 18:53:14 -05:00
parent dd0a141d5f
commit f942a2763f

View file

@ -74,7 +74,7 @@ class SlowFile:
self.encoding = None self.encoding = None
self.delayfactor = 1 self.delayfactor = 1
self.lastblocktargettime = None self.lastblocktargettime = 2**31
self.lastdebug = 0 self.lastdebug = 0
@ -111,7 +111,7 @@ class SlowFile:
self.delayfactor -= 0.02 self.delayfactor -= 0.02
else: else:
# we're late; something got slow. # we're late; something got slow.
self.delayfactor += 0.01 self.delayfactor += 0.5
if self.delayfactor < 1: if self.delayfactor < 1:
self.delayfactor = 1 self.delayfactor = 1
@ -121,8 +121,20 @@ class SlowFile:
targetspeed = self.speed/float(self.delayfactor) targetspeed = self.speed/float(self.delayfactor)
self.lastblocktargettime = time.time() + len/float(targetspeed) self.lastblocktargettime = time.time() + len/float(targetspeed)
if time.time() > self.lastdebug+60: if time.time() > self.lastdebug+300:
logger.debug('Target %i bytes/second (%i kilobits/second), delay factor %.2f, block len %i' % (targetspeed, targetspeed*8/1024, self.delayfactor, len)) logger.debug('Target %i bytes/second (%i kilobits/second), delay factor %.2f, block len %i' % (targetspeed, targetspeed*8/1024, self.delayfactor, len))
try:
newkbits = int(open('/home/rtucker/Dropbox/Semaphores/BackupPC_archiveHost_s3.maxspeed', 'r').readline())
newspeed = (newkbits/float(8))*1024
if newspeed != self.speed:
self.delayfactor = 1
self.speed = newspeed
logger.debug('Setting new speed! %i bytes/second' % newspeed)
except IOError:
logger.debug('No Semaphore file for new speed')
except ValueError:
logger.debug('Semaphore file invalid')
self.lastdebug = time.time() self.lastdebug = time.time()
return self.fd.read(len) return self.fd.read(len)