increasing delayfactor punishment a bit; adding speed control
This commit is contained in:
parent
dd0a141d5f
commit
f942a2763f
1 changed files with 15 additions and 3 deletions
|
@ -74,7 +74,7 @@ class SlowFile:
|
|||
self.encoding = None
|
||||
|
||||
self.delayfactor = 1
|
||||
self.lastblocktargettime = None
|
||||
self.lastblocktargettime = 2**31
|
||||
|
||||
self.lastdebug = 0
|
||||
|
||||
|
@ -111,7 +111,7 @@ class SlowFile:
|
|||
self.delayfactor -= 0.02
|
||||
else:
|
||||
# we're late; something got slow.
|
||||
self.delayfactor += 0.01
|
||||
self.delayfactor += 0.5
|
||||
|
||||
if self.delayfactor < 1:
|
||||
self.delayfactor = 1
|
||||
|
@ -121,8 +121,20 @@ class SlowFile:
|
|||
targetspeed = self.speed/float(self.delayfactor)
|
||||
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))
|
||||
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()
|
||||
|
||||
return self.fd.read(len)
|
||||
|
|
Loading…
Reference in a new issue