calculate is called when an ack for a bdp ping is received. Here we calculate the current bdp and bandwidth sample and decide if the flow control windows should go up.
(d [8]byte)
| 103 | // Here we calculate the current bdp and bandwidth sample and |
| 104 | // decide if the flow control windows should go up. |
| 105 | func (b *bdpEstimator) calculate(d [8]byte) { |
| 106 | // Check if the ping acked for was the bdp ping. |
| 107 | if bdpPing.data != d { |
| 108 | return |
| 109 | } |
| 110 | b.mu.Lock() |
| 111 | rttSample := time.Since(b.sentAt).Seconds() |
| 112 | if b.sampleCount < 10 { |
| 113 | // Bootstrap rtt with an average of first 10 rtt samples. |
| 114 | b.rtt += (rttSample - b.rtt) / float64(b.sampleCount) |
| 115 | } else { |
| 116 | // Heed to the recent past more. |
| 117 | b.rtt += (rttSample - b.rtt) * float64(alpha) |
| 118 | } |
| 119 | b.isSent = false |
| 120 | // The number of bytes accumulated so far in the sample is smaller |
| 121 | // than or equal to 1.5 times the real BDP on a saturated connection. |
| 122 | bwCurrent := float64(b.sample) / (b.rtt * float64(1.5)) |
| 123 | if bwCurrent > b.bwMax { |
| 124 | b.bwMax = bwCurrent |
| 125 | } |
| 126 | // If the current sample (which is smaller than or equal to the 1.5 times the real BDP) is |
| 127 | // greater than or equal to 2/3rd our perceived bdp AND this is the maximum bandwidth seen so far, we |
| 128 | // should update our perception of the network BDP. |
| 129 | if float64(b.sample) >= beta*float64(b.bdp) && bwCurrent == b.bwMax && b.bdp != bdpLimit { |
| 130 | sampleFloat := float64(b.sample) |
| 131 | b.bdp = uint32(gamma * sampleFloat) |
| 132 | if b.bdp > bdpLimit { |
| 133 | b.bdp = bdpLimit |
| 134 | } |
| 135 | bdp := b.bdp |
| 136 | b.mu.Unlock() |
| 137 | b.updateFlowControl(bdp) |
| 138 | return |
| 139 | } |
| 140 | b.mu.Unlock() |
| 141 | } |
no test coverage detected