flag-max-connections-per-host.patch 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. From: csagan5 <32685696+csagan5@users.noreply.github.com>
  2. Date: Sun, 8 Jul 2018 22:42:04 +0200
  3. Subject: Add flag to configure maximum connections per host
  4. With the introduction of this flag it is possible to increase the maximum
  5. allowed connections per host; this can however be detrimental to devices
  6. with limited CPU/memory resources and it is disabled by default.
  7. ---
  8. chrome/browser/about_flags.cc | 8 ++++++++
  9. chrome/browser/flag_descriptions.cc | 4 ++++
  10. chrome/browser/flag_descriptions.h | 3 +++
  11. .../common/network_features.cc | 3 +++
  12. .../common/network_features.h | 4 ++++
  13. .../common/network_switch_list.h | 4 ++++
  14. net/socket/client_socket_pool_manager.cc | 16 ++++++++++++++++
  15. 7 files changed, 42 insertions(+)
  16. --- a/chrome/browser/BUILD.gn
  17. +++ b/chrome/browser/BUILD.gn
  18. @@ -2104,6 +2104,7 @@ jumbo_static_library("browser") {
  19. "//components/net_log",
  20. "//components/network_hints/common:mojo_bindings",
  21. "//components/network_session_configurator/browser",
  22. + "//components/network_session_configurator/common",
  23. "//components/network_time",
  24. "//components/ntp_tiles",
  25. "//components/offline_items_collection/core",
  26. --- a/chrome/browser/about_flags.cc
  27. +++ b/chrome/browser/about_flags.cc
  28. @@ -767,6 +767,11 @@ const FeatureEntry::Choice kForceEffecti
  29. net::kEffectiveConnectionType4G},
  30. };
  31. +const FeatureEntry::Choice kMaxConnectionsPerHostChoices[] = {
  32. + {features::kMaxConnectionsPerHostChoiceDefault, "", ""},
  33. + {features::kMaxConnectionsPerHostChoice15, switches::kMaxConnectionsPerHost, "15"},
  34. +};
  35. +
  36. // Ensure that all effective connection types returned by Network Quality
  37. // Estimator (NQE) are also exposed via flags.
  38. static_assert(net::EFFECTIVE_CONNECTION_TYPE_LAST + 2 ==
  39. @@ -2760,6 +2765,9 @@ const FeatureEntry kFeatureEntries[] = {
  40. flag_descriptions::kAutofillCreditCardUploadDescription, kOsAll,
  41. FEATURE_VALUE_TYPE(autofill::features::kAutofillUpstream)},
  42. #endif // TOOLKIT_VIEWS || OS_ANDROID
  43. + {"max-connections-per-host", flag_descriptions::kMaxConnectionsPerHostName,
  44. + flag_descriptions::kMaxConnectionsPerHostDescription, kOsAll,
  45. + MULTI_VALUE_TYPE(kMaxConnectionsPerHostChoices)},
  46. {"force-ui-direction", flag_descriptions::kForceUiDirectionName,
  47. flag_descriptions::kForceUiDirectionDescription, kOsAll,
  48. MULTI_VALUE_TYPE(kForceUIDirectionChoices)},
  49. --- a/chrome/browser/browser_process_impl.cc
  50. +++ b/chrome/browser/browser_process_impl.cc
  51. @@ -18,12 +18,14 @@
  52. #include "base/debug/leak_annotations.h"
  53. #include "base/files/file_path.h"
  54. #include "base/location.h"
  55. +#include "base/logging.h"
  56. #include "base/macros.h"
  57. #include "base/memory/ptr_util.h"
  58. #include "base/metrics/histogram_macros.h"
  59. #include "base/path_service.h"
  60. #include "base/run_loop.h"
  61. #include "base/single_thread_task_runner.h"
  62. +#include "base/strings/string_number_conversions.h"
  63. #include "base/synchronization/waitable_event.h"
  64. #include "base/task/post_task.h"
  65. #include "base/task/task_traits.h"
  66. @@ -98,6 +100,7 @@
  67. #include "components/metrics/metrics_service.h"
  68. #include "components/metrics_services_manager/metrics_services_manager.h"
  69. #include "components/metrics_services_manager/metrics_services_manager_client.h"
  70. +#include "components/network_session_configurator/common/network_switches.h"
  71. #include "components/network_time/network_time_tracker.h"
  72. #include "components/optimization_guide/optimization_guide_features.h"
  73. #include "components/optimization_guide/optimization_guide_service.h"
  74. @@ -136,6 +139,7 @@
  75. #include "media/media_buildflags.h"
  76. #include "mojo/public/cpp/bindings/pending_receiver.h"
  77. #include "net/log/net_log.h"
  78. +#include "net/socket/client_socket_pool_manager.h"
  79. #include "ppapi/buildflags/buildflags.h"
  80. #include "printing/buildflags/buildflags.h"
  81. #include "services/network/public/cpp/features.h"
  82. @@ -325,6 +329,18 @@ void BrowserProcessImpl::Init() {
  83. base::Bind(&ApplyMetricsReportingPolicy));
  84. #endif
  85. + int max_connections_per_host = 0;
  86. + auto switch_value = base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
  87. + switches::kMaxConnectionsPerHost);
  88. + if (!switch_value.empty() && !base::StringToInt(switch_value, &max_connections_per_host)) {
  89. + LOG(DFATAL) << "--" << switches::kMaxConnectionsPerHost
  90. + << " expected integer; got (\"" << switch_value << "\" instead)";
  91. + }
  92. + if (max_connections_per_host != 0) {
  93. + net::ClientSocketPoolManager::set_max_sockets_per_group(
  94. + net::HttpNetworkSession::NORMAL_SOCKET_POOL, max_connections_per_host);
  95. + }
  96. +
  97. DCHECK(!webrtc_event_log_manager_);
  98. webrtc_event_log_manager_ = WebRtcEventLogManager::CreateSingletonInstance();
  99. --- a/chrome/browser/flag_descriptions.cc
  100. +++ b/chrome/browser/flag_descriptions.cc
  101. @@ -1137,6 +1137,10 @@ const char kMediaInspectorLoggingDescrip
  102. "Move media logging from chrome://media-internals into the developer tools "
  103. "project.";
  104. +const char kMaxConnectionsPerHostName[] = "Maximum connections per host";
  105. +const char kMaxConnectionsPerHostDescription[] =
  106. + "Customize maximum allowed connections per host.";
  107. +
  108. const char kMediaRouterCastAllowAllIPsName[] =
  109. "Connect to Cast devices on all IP addresses";
  110. const char kMediaRouterCastAllowAllIPsDescription[] =
  111. --- a/chrome/browser/flag_descriptions.h
  112. +++ b/chrome/browser/flag_descriptions.h
  113. @@ -678,6 +678,9 @@ extern const char kMediaHistoryDescripti
  114. extern const char kMediaInspectorLoggingName[];
  115. extern const char kMediaInspectorLoggingDescription[];
  116. +extern const char kMaxConnectionsPerHostName[];
  117. +extern const char kMaxConnectionsPerHostDescription[];
  118. +
  119. extern const char kMediaRouterCastAllowAllIPsName[];
  120. extern const char kMediaRouterCastAllowAllIPsDescription[];
  121. --- a/components/network_session_configurator/common/network_features.cc
  122. +++ b/components/network_session_configurator/common/network_features.cc
  123. @@ -8,4 +8,7 @@
  124. namespace features {
  125. +const char kMaxConnectionsPerHostChoiceDefault[] = "6",
  126. + kMaxConnectionsPerHostChoice15[] = "15";
  127. +
  128. } // namespace features
  129. --- a/components/network_session_configurator/common/network_features.h
  130. +++ b/components/network_session_configurator/common/network_features.h
  131. @@ -10,6 +10,10 @@
  132. namespace features {
  133. +NETWORK_SESSION_CONFIGURATOR_EXPORT extern const char kMaxConnectionsPerHostChoiceDefault[],
  134. + kMaxConnectionsPerHostChoice6[],
  135. + kMaxConnectionsPerHostChoice15[];
  136. +
  137. } // namespace features
  138. #endif // COMPONENTS_NETWORK_SESSION_CONFIGURATOR_COMMON_NETWORK_FEATURES_H_
  139. --- a/components/network_session_configurator/common/network_switch_list.h
  140. +++ b/components/network_session_configurator/common/network_switch_list.h
  141. @@ -22,6 +22,10 @@ NETWORK_SWITCH(kEnableUserAlternateProto
  142. // Enables the QUIC protocol. This is a temporary testing flag.
  143. NETWORK_SWITCH(kEnableQuic, "enable-quic")
  144. +// Allows specifying a higher number of maximum connections per host
  145. +// (15 instead of 6, mirroring the value Mozilla uses).
  146. +NETWORK_SWITCH(kMaxConnectionsPerHost, "max-connections-per-host")
  147. +
  148. // Ignores certificate-related errors.
  149. NETWORK_SWITCH(kIgnoreCertificateErrors, "ignore-certificate-errors")