~mcfletch/pyqnet/jsonencoded

« back to all changes in this revision

Viewing changes to qnet/messageset.py

  • Committer: Mike C. Fletcher
  • Date: 2008-08-08 22:30:14 UTC
  • Revision ID: mcfletch@vrplumber.com-20080808223014-53c37f6xodig42wl
Rework the ack period stuff so that it can actually adapt things...

Show diffs side-by-side

added added

removed removed

Lines of Context:
72
72
                self.in_flight_packages[ package.id ] = package
73
73
                self.channel.send_raw( package.encode() )
74
74
        _current_ack_wait = None
75
 
        _last_ack_time = 0
76
 
        _ack_last_time = 0
 
75
        _last_ack_time = 0 # last time we were acked
 
76
        _current_ack_wait_count = 0
77
77
        def ack_wait_period( self ):
78
78
                """Calculate a reasonable acknowledgement wait period (period before retry)"""
79
79
                # TODO better reset period calculation...
80
 
                if self._current_ack_wait is None or self.channel.statistics.total_count > self._ack_last_time + 100:
81
 
                        self._current_ack_wait = self.channel.statistics.ack_wait_time()
 
80
                current_count = self.channel.statistics.package_count
 
81
                if (
 
82
                        self._current_ack_wait is None or 
 
83
                        current_count > self._current_ack_wait_count + 100
 
84
                ):
 
85
                        self._current_ack_wait = wait = self.channel.statistics.ack_wait_time()
 
86
                        self._current_ack_wait_count = current_count
 
87
                        if wait > self.channel.protocol.CONGESTION_PERIOD:
 
88
                                if self.channel.sender:
 
89
                                        self.channel.sender.congestion_warning( self.channel )
 
90
                                log.warn( """Mean round-trip for channel %s is %0.5f"""%(
 
91
                                        self.channel,wait,
 
92
                                ))
82
93
                return self._current_ack_wait
83
94
        
84
95
        def has_pending( self ):