| 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 |
| 11 // c) That the approximate increase in "perceived downtime" introduced by | 11 // c) That the approximate increase in "perceived downtime" introduced by |
| 12 // anti-DDoS throttling for various different actual downtimes is what | 12 // anti-DDoS throttling for various different actual downtimes is what |
| 13 // we expect it to be. | 13 // we expect it to be. |
| 14 | 14 |
| 15 #include <cmath> | 15 #include <cmath> |
| 16 #include <limits> | 16 #include <limits> |
| 17 #include <vector> | 17 #include <vector> |
| 18 | 18 |
| 19 #include "base/environment.h" | 19 #include "base/environment.h" |
| 20 #include "base/memory/scoped_vector.h" | 20 #include "base/memory/scoped_vector.h" |
| 21 #include "base/rand_util.h" | 21 #include "base/rand_util.h" |
| 22 #include "base/time/time.h" | 22 #include "base/time/time.h" |
| 23 #include "net/base/request_priority.h" | 23 #include "net/base/request_priority.h" |
| 24 #include "net/url_request/url_request_context.h" |
| 24 #include "net/url_request/url_request_test_util.h" | 25 #include "net/url_request/url_request_test_util.h" |
| 25 #include "net/url_request/url_request_throttler_manager.h" | 26 #include "net/url_request/url_request_throttler_manager.h" |
| 26 #include "net/url_request/url_request_throttler_test_support.h" | 27 #include "net/url_request/url_request_throttler_test_support.h" |
| 27 #include "testing/gtest/include/gtest/gtest.h" | 28 #include "testing/gtest/include/gtest/gtest.h" |
| 28 | 29 |
| 29 using base::TimeDelta; | 30 using base::TimeDelta; |
| 30 using base::TimeTicks; | 31 using base::TimeTicks; |
| 31 | 32 |
| 32 namespace net { | 33 namespace net { |
| 33 namespace { | 34 namespace { |
| (...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 268 output.append(1, block); | 269 output.append(1, block); |
| 269 } | 270 } |
| 270 output.append("\n"); | 271 output.append("\n"); |
| 271 } | 272 } |
| 272 output.append("|"); | 273 output.append("|"); |
| 273 output.append(num_printed_columns, '='); | 274 output.append(num_printed_columns, '='); |
| 274 | 275 |
| 275 return output; | 276 return output; |
| 276 } | 277 } |
| 277 | 278 |
| 279 const URLRequestContext& context() const { return context_; } |
| 280 |
| 278 private: | 281 private: |
| 279 TimeTicks now_; | 282 TimeTicks now_; |
| 280 TimeTicks start_downtime_; // Can be 0 to say "no downtime". | 283 TimeTicks start_downtime_; // Can be 0 to say "no downtime". |
| 281 TimeTicks end_downtime_; | 284 TimeTicks end_downtime_; |
| 282 const int max_queries_per_tick_; | 285 const int max_queries_per_tick_; |
| 283 const double request_drop_ratio_; // Ratio of requests to 503 when failing. | 286 const double request_drop_ratio_; // Ratio of requests to 503 when failing. |
| 284 int num_overloaded_ticks_remaining_; | 287 int num_overloaded_ticks_remaining_; |
| 285 int num_current_tick_queries_; | 288 int num_current_tick_queries_; |
| 286 int num_overloaded_ticks_; | 289 int num_overloaded_ticks_; |
| 287 int max_experienced_queries_per_tick_; | 290 int max_experienced_queries_per_tick_; |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 420 TimeDelta current_jitter = TimeDelta::FromMilliseconds( | 423 TimeDelta current_jitter = TimeDelta::FromMilliseconds( |
| 421 request_jitter_.InMilliseconds() * base::RandDouble()); | 424 request_jitter_.InMilliseconds() * base::RandDouble()); |
| 422 if (base::RandInt(0, 1)) { | 425 if (base::RandInt(0, 1)) { |
| 423 effective_delay -= current_jitter; | 426 effective_delay -= current_jitter; |
| 424 } else { | 427 } else { |
| 425 effective_delay += current_jitter; | 428 effective_delay += current_jitter; |
| 426 } | 429 } |
| 427 | 430 |
| 428 if (throttler_entry_->fake_now() - time_of_last_attempt_ > | 431 if (throttler_entry_->fake_now() - time_of_last_attempt_ > |
| 429 effective_delay) { | 432 effective_delay) { |
| 430 if (!throttler_entry_->ShouldRejectRequest(server_->mock_request())) { | 433 if (!throttler_entry_->ShouldRejectRequest( |
| 434 server_->mock_request(), |
| 435 server_->context().network_delegate())) { |
| 431 int status_code = server_->HandleRequest(); | 436 int status_code = server_->HandleRequest(); |
| 432 MockURLRequestThrottlerHeaderAdapter response_headers(status_code); | 437 MockURLRequestThrottlerHeaderAdapter response_headers(status_code); |
| 433 throttler_entry_->UpdateWithResponse(std::string(), &response_headers); | 438 throttler_entry_->UpdateWithResponse(std::string(), &response_headers); |
| 434 | 439 |
| 435 if (status_code == 200) { | 440 if (status_code == 200) { |
| 436 if (results_) | 441 if (results_) |
| 437 results_->AddSuccess(); | 442 results_->AddSuccess(); |
| 438 | 443 |
| 439 if (last_attempt_was_failure_) { | 444 if (last_attempt_was_failure_) { |
| 440 last_downtime_duration_ = | 445 last_downtime_duration_ = |
| (...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 745 trials[i].PrintTrialDescription(); | 750 trials[i].PrintTrialDescription(); |
| 746 trials[i].stats.ReportTrialResult(increase_ratio); | 751 trials[i].stats.ReportTrialResult(increase_ratio); |
| 747 } | 752 } |
| 748 | 753 |
| 749 VerboseOut("Average increase ratio was %.4f\n", average_increase_ratio); | 754 VerboseOut("Average increase ratio was %.4f\n", average_increase_ratio); |
| 750 VerboseOut("Maximum increase ratio was %.4f\n", max_increase_ratio); | 755 VerboseOut("Maximum increase ratio was %.4f\n", max_increase_ratio); |
| 751 } | 756 } |
| 752 | 757 |
| 753 } // namespace | 758 } // namespace |
| 754 } // namespace net | 759 } // namespace net |
| OLD | NEW |