| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 // The tests in this file attempt to verify the following through simulation: | 5 // The tests in this file attempt to verify the following through simulation: |
| 6 // a) That a server experiencing overload will actually benefit from the | 6 // a) That a server experiencing overload will actually benefit from the |
| 7 // anti-DDoS throttling logic, i.e. that its traffic spike will subside | 7 // anti-DDoS throttling logic, i.e. that its traffic spike will subside |
| 8 // and be distributed over a longer period of time; | 8 // and be distributed over a longer period of time; |
| 9 // b) That "well-behaved" clients of a server under DDoS attack actually | 9 // b) That "well-behaved" clients of a server under DDoS attack actually |
| 10 // benefit from the anti-DDoS throttling logic; and | 10 // benefit from the anti-DDoS throttling logic; and |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 128 num_overloaded_ticks_(0), | 128 num_overloaded_ticks_(0), |
| 129 max_experienced_queries_per_tick_(0), | 129 max_experienced_queries_per_tick_(0), |
| 130 mock_request_(context_.CreateRequest( | 130 mock_request_(context_.CreateRequest( |
| 131 GURL(), DEFAULT_PRIORITY, NULL, NULL)) {} | 131 GURL(), DEFAULT_PRIORITY, NULL, NULL)) {} |
| 132 | 132 |
| 133 void SetDowntime(const TimeTicks& start_time, const TimeDelta& duration) { | 133 void SetDowntime(const TimeTicks& start_time, const TimeDelta& duration) { |
| 134 start_downtime_ = start_time; | 134 start_downtime_ = start_time; |
| 135 end_downtime_ = start_time + duration; | 135 end_downtime_ = start_time + duration; |
| 136 } | 136 } |
| 137 | 137 |
| 138 virtual void AdvanceTime(const TimeTicks& absolute_time) OVERRIDE { | 138 virtual void AdvanceTime(const TimeTicks& absolute_time) override { |
| 139 now_ = absolute_time; | 139 now_ = absolute_time; |
| 140 } | 140 } |
| 141 | 141 |
| 142 virtual void PerformAction() OVERRIDE { | 142 virtual void PerformAction() override { |
| 143 // We are inserted at the end of the actor's list, so all Requester | 143 // We are inserted at the end of the actor's list, so all Requester |
| 144 // instances have already done their bit. | 144 // instances have already done their bit. |
| 145 if (num_current_tick_queries_ > max_experienced_queries_per_tick_) | 145 if (num_current_tick_queries_ > max_experienced_queries_per_tick_) |
| 146 max_experienced_queries_per_tick_ = num_current_tick_queries_; | 146 max_experienced_queries_per_tick_ = num_current_tick_queries_; |
| 147 | 147 |
| 148 if (num_current_tick_queries_ > max_queries_per_tick_) { | 148 if (num_current_tick_queries_ > max_queries_per_tick_) { |
| 149 // We pretend the server fails for the next several ticks after it | 149 // We pretend the server fails for the next several ticks after it |
| 150 // gets overloaded. | 150 // gets overloaded. |
| 151 num_overloaded_ticks_remaining_ = 5; | 151 num_overloaded_ticks_remaining_ = 5; |
| 152 ++num_overloaded_ticks_; | 152 ++num_overloaded_ticks_; |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 299 DISALLOW_COPY_AND_ASSIGN(Server); | 299 DISALLOW_COPY_AND_ASSIGN(Server); |
| 300 }; | 300 }; |
| 301 | 301 |
| 302 // Mock throttler entry used by Requester class. | 302 // Mock throttler entry used by Requester class. |
| 303 class MockURLRequestThrottlerEntry : public URLRequestThrottlerEntry { | 303 class MockURLRequestThrottlerEntry : public URLRequestThrottlerEntry { |
| 304 public: | 304 public: |
| 305 explicit MockURLRequestThrottlerEntry(URLRequestThrottlerManager* manager) | 305 explicit MockURLRequestThrottlerEntry(URLRequestThrottlerManager* manager) |
| 306 : URLRequestThrottlerEntry(manager, std::string()), | 306 : URLRequestThrottlerEntry(manager, std::string()), |
| 307 mock_backoff_entry_(&backoff_policy_) {} | 307 mock_backoff_entry_(&backoff_policy_) {} |
| 308 | 308 |
| 309 virtual const BackoffEntry* GetBackoffEntry() const OVERRIDE { | 309 virtual const BackoffEntry* GetBackoffEntry() const override { |
| 310 return &mock_backoff_entry_; | 310 return &mock_backoff_entry_; |
| 311 } | 311 } |
| 312 | 312 |
| 313 virtual BackoffEntry* GetBackoffEntry() OVERRIDE { | 313 virtual BackoffEntry* GetBackoffEntry() override { |
| 314 return &mock_backoff_entry_; | 314 return &mock_backoff_entry_; |
| 315 } | 315 } |
| 316 | 316 |
| 317 virtual TimeTicks ImplGetTimeNow() const OVERRIDE { | 317 virtual TimeTicks ImplGetTimeNow() const override { |
| 318 return fake_now_; | 318 return fake_now_; |
| 319 } | 319 } |
| 320 | 320 |
| 321 void SetFakeNow(const TimeTicks& fake_time) { | 321 void SetFakeNow(const TimeTicks& fake_time) { |
| 322 fake_now_ = fake_time; | 322 fake_now_ = fake_time; |
| 323 mock_backoff_entry_.set_fake_now(fake_time); | 323 mock_backoff_entry_.set_fake_now(fake_time); |
| 324 } | 324 } |
| 325 | 325 |
| 326 TimeTicks fake_now() const { | 326 TimeTicks fake_now() const { |
| 327 return fake_now_; | 327 return fake_now_; |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 407 Server* server, | 407 Server* server, |
| 408 RequesterResults* results) | 408 RequesterResults* results) |
| 409 : throttler_entry_(throttler_entry), | 409 : throttler_entry_(throttler_entry), |
| 410 time_between_requests_(time_between_requests), | 410 time_between_requests_(time_between_requests), |
| 411 last_attempt_was_failure_(false), | 411 last_attempt_was_failure_(false), |
| 412 server_(server), | 412 server_(server), |
| 413 results_(results) { | 413 results_(results) { |
| 414 DCHECK(server_); | 414 DCHECK(server_); |
| 415 } | 415 } |
| 416 | 416 |
| 417 virtual void AdvanceTime(const TimeTicks& absolute_time) OVERRIDE { | 417 virtual void AdvanceTime(const TimeTicks& absolute_time) override { |
| 418 if (time_of_last_success_.is_null()) | 418 if (time_of_last_success_.is_null()) |
| 419 time_of_last_success_ = absolute_time; | 419 time_of_last_success_ = absolute_time; |
| 420 | 420 |
| 421 throttler_entry_->SetFakeNow(absolute_time); | 421 throttler_entry_->SetFakeNow(absolute_time); |
| 422 } | 422 } |
| 423 | 423 |
| 424 virtual void PerformAction() OVERRIDE { | 424 virtual void PerformAction() override { |
| 425 TimeDelta effective_delay = time_between_requests_; | 425 TimeDelta effective_delay = time_between_requests_; |
| 426 TimeDelta current_jitter = TimeDelta::FromMilliseconds( | 426 TimeDelta current_jitter = TimeDelta::FromMilliseconds( |
| 427 request_jitter_.InMilliseconds() * base::RandDouble()); | 427 request_jitter_.InMilliseconds() * base::RandDouble()); |
| 428 if (base::RandInt(0, 1)) { | 428 if (base::RandInt(0, 1)) { |
| 429 effective_delay -= current_jitter; | 429 effective_delay -= current_jitter; |
| 430 } else { | 430 } else { |
| 431 effective_delay += current_jitter; | 431 effective_delay += current_jitter; |
| 432 } | 432 } |
| 433 | 433 |
| 434 if (throttler_entry_->fake_now() - time_of_last_attempt_ > | 434 if (throttler_entry_->fake_now() - time_of_last_attempt_ > |
| (...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 753 trials[i].PrintTrialDescription(); | 753 trials[i].PrintTrialDescription(); |
| 754 trials[i].stats.ReportTrialResult(increase_ratio); | 754 trials[i].stats.ReportTrialResult(increase_ratio); |
| 755 } | 755 } |
| 756 | 756 |
| 757 VerboseOut("Average increase ratio was %.4f\n", average_increase_ratio); | 757 VerboseOut("Average increase ratio was %.4f\n", average_increase_ratio); |
| 758 VerboseOut("Maximum increase ratio was %.4f\n", max_increase_ratio); | 758 VerboseOut("Maximum increase ratio was %.4f\n", max_increase_ratio); |
| 759 } | 759 } |
| 760 | 760 |
| 761 } // namespace | 761 } // namespace |
| 762 } // namespace net | 762 } // namespace net |
| OLD | NEW |