Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "net/base/backoff_entry.h" | 5 #include "net/base/backoff_entry.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <cmath> | 8 #include <cmath> |
| 9 | 9 |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 22 } | 22 } |
| 23 | 23 |
| 24 BackoffEntry::~BackoffEntry() { | 24 BackoffEntry::~BackoffEntry() { |
| 25 // TODO(joi): Remove this once our clients (e.g. URLRequestThrottlerManager) | 25 // TODO(joi): Remove this once our clients (e.g. URLRequestThrottlerManager) |
| 26 // always destroy from the I/O thread. | 26 // always destroy from the I/O thread. |
| 27 DetachFromThread(); | 27 DetachFromThread(); |
| 28 } | 28 } |
| 29 | 29 |
| 30 void BackoffEntry::InformOfRequest(bool succeeded) { | 30 void BackoffEntry::InformOfRequest(bool succeeded) { |
| 31 if (!succeeded) { | 31 if (!succeeded) { |
| 32 failure_count_++; | 32 ++failure_count_; |
| 33 exponential_backoff_release_time_ = CalculateReleaseTime(); | 33 exponential_backoff_release_time_ = CalculateReleaseTime(); |
| 34 } else { | 34 } else { |
| 35 failure_count_ = 0; | 35 // We slowly decay the number of times delayed instead of resetting it to 0 |
| 36 // in order to stay stable if we receive successes interleaved between lots | |
| 37 // of failures. | |
| 38 failure_count_ = std::max(0, --failure_count_); | |
|
sanjeevr
2011/05/04 20:23:09
I think we need to think of a better fix in the lo
Jói
2011/05/04 20:30:14
Added a TODO to revisit this.
| |
| 36 | 39 |
| 37 // The reason why we are not just cutting the release time to GetTimeNow() | 40 // The reason why we are not just cutting the release time to GetTimeNow() |
| 38 // is on the one hand, it would unset a release time set by | 41 // is on the one hand, it would unset a release time set by |
| 39 // SetCustomReleaseTime and on the other we would like to push every | 42 // SetCustomReleaseTime and on the other we would like to push every |
| 40 // request up to our "horizon" when dealing with multiple in-flight | 43 // request up to our "horizon" when dealing with multiple in-flight |
| 41 // requests. Ex: If we send three requests and we receive 2 failures and | 44 // requests. Ex: If we send three requests and we receive 2 failures and |
| 42 // 1 success. The success that follows those failures will not reset the | 45 // 1 success. The success that follows those failures will not reset the |
| 43 // release time, further requests will then need to wait the delay caused | 46 // release time, further requests will then need to wait the delay caused |
| 44 // by the 2 failures. | 47 // by the 2 failures. |
| 45 exponential_backoff_release_time_ = std::max( | 48 exponential_backoff_release_time_ = std::max( |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 109 delay_int = std::min(delay_int, | 112 delay_int = std::min(delay_int, |
| 110 static_cast<int64>(policy_->maximum_backoff_ms)); | 113 static_cast<int64>(policy_->maximum_backoff_ms)); |
| 111 | 114 |
| 112 // Never reduce previously set release horizon, e.g. due to Retry-After | 115 // Never reduce previously set release horizon, e.g. due to Retry-After |
| 113 // header. | 116 // header. |
| 114 return std::max(GetTimeNow() + base::TimeDelta::FromMilliseconds(delay_int), | 117 return std::max(GetTimeNow() + base::TimeDelta::FromMilliseconds(delay_int), |
| 115 exponential_backoff_release_time_); | 118 exponential_backoff_release_time_); |
| 116 } | 119 } |
| 117 | 120 |
| 118 } // namespace net | 121 } // namespace net |
| OLD | NEW |