From: csagan5 <32685696+csagan5@users.noreply.github.com> Date: Sun, 8 Jul 2018 22:42:04 +0200 Subject: Add flag to configure maximum connections per host With the introduction of this flag it is possible to increase the maximum allowed connections per host; this can however be detrimental to devices with limited CPU/memory resources and it is disabled by default. --- chrome/browser/about_flags.cc | 8 ++++++++ chrome/browser/flag_descriptions.cc | 4 ++++ chrome/browser/flag_descriptions.h | 3 +++ .../common/network_features.cc | 3 +++ .../common/network_features.h | 4 ++++ .../common/network_switch_list.h | 4 ++++ net/socket/client_socket_pool_manager.cc | 16 ++++++++++++++++ 7 files changed, 42 insertions(+) --- a/chrome/browser/about_flags.cc +++ b/chrome/browser/about_flags.cc @@ -756,6 +756,11 @@ const FeatureEntry::Choice kForceEffecti net::kEffectiveConnectionType4G}, }; +const FeatureEntry::Choice kMaxConnectionsPerHostChoices[] = { + {features::kMaxConnectionsPerHostChoiceDefault, "", ""}, + {features::kMaxConnectionsPerHostChoice15, switches::kMaxConnectionsPerHost, "15"}, +}; + // Ensure that all effective connection types returned by Network Quality // Estimator (NQE) are also exposed via flags. static_assert(net::EFFECTIVE_CONNECTION_TYPE_LAST + 2 == @@ -2166,6 +2171,9 @@ const FeatureEntry kFeatureEntries[] = { flag_descriptions::kAutofillCreditCardUploadDescription, kOsAll, FEATURE_VALUE_TYPE(autofill::features::kAutofillUpstream)}, #endif // TOOLKIT_VIEWS || OS_ANDROID + {"max-connections-per-host", flag_descriptions::kMaxConnectionsPerHostName, + flag_descriptions::kMaxConnectionsPerHostDescription, kOsAll, + MULTI_VALUE_TYPE(kMaxConnectionsPerHostChoices)}, {"safe-search-url-reporting", flag_descriptions::kSafeSearchUrlReportingName, flag_descriptions::kSafeSearchUrlReportingDescription, kOsAll, --- a/chrome/browser/flag_descriptions.cc +++ b/chrome/browser/flag_descriptions.cc @@ -1232,6 +1232,10 @@ const char kLookalikeUrlNavigationSugges const char kMarkHttpAsName[] = "Mark non-secure origins as non-secure"; const char kMarkHttpAsDescription[] = "Change the UI treatment for HTTP pages"; +const char kMaxConnectionsPerHostName[] = "Maximum connections per host"; +const char kMaxConnectionsPerHostDescription[] = + "Customize maximum allowed connections per host."; + const char kMediaRouterCastAllowAllIPsName[] = "Connect to Cast devices on all IP addresses"; const char kMediaRouterCastAllowAllIPsDescription[] = --- a/chrome/browser/flag_descriptions.h +++ b/chrome/browser/flag_descriptions.h @@ -739,6 +739,9 @@ extern const char kMarkHttpAsWarning[]; extern const char kMarkHttpAsWarningAndDangerousOnFormEdits[]; extern const char kMarkHttpAsWarningAndDangerousOnPasswordsAndCreditCards[]; +extern const char kMaxConnectionsPerHostName[]; +extern const char kMaxConnectionsPerHostDescription[]; + extern const char kMediaRouterCastAllowAllIPsName[]; extern const char kMediaRouterCastAllowAllIPsDescription[]; --- a/components/network_session_configurator/common/network_features.cc +++ b/components/network_session_configurator/common/network_features.cc @@ -8,6 +8,9 @@ namespace features { +const char kMaxConnectionsPerHostChoiceDefault[] = "6", + kMaxConnectionsPerHostChoice15[] = "15"; + const base::Feature kDnsOverHttps{"dns-over-https", base::FEATURE_DISABLED_BY_DEFAULT}; --- a/components/network_session_configurator/common/network_features.h +++ b/components/network_session_configurator/common/network_features.h @@ -10,6 +10,10 @@ namespace features { +NETWORK_SESSION_CONFIGURATOR_EXPORT extern const char kMaxConnectionsPerHostChoiceDefault[], + kMaxConnectionsPerHostChoice6[], + kMaxConnectionsPerHostChoice15[]; + // Enabled DNS over HTTPS // (https://tools.ietf.org/id/draft-ietf-doh-dns-over-https-12.txt). NETWORK_SESSION_CONFIGURATOR_EXPORT extern const base::Feature kDnsOverHttps; --- a/components/network_session_configurator/common/network_switch_list.h +++ b/components/network_session_configurator/common/network_switch_list.h @@ -22,6 +22,10 @@ NETWORK_SWITCH(kEnableUserAlternateProto // Enables the QUIC protocol. This is a temporary testing flag. NETWORK_SWITCH(kEnableQuic, "enable-quic") +// Allows specifying a higher number of maximum connections per host +// (15 instead of 6, mirroring the value Mozilla uses). +NETWORK_SWITCH(kMaxConnectionsPerHost, "max-connections-per-host") + // Ignores certificate-related errors. NETWORK_SWITCH(kIgnoreCertificateErrors, "ignore-certificate-errors") --- a/chrome/browser/browser_process_impl.cc +++ b/chrome/browser/browser_process_impl.cc @@ -18,12 +18,14 @@ #include "base/debug/leak_annotations.h" #include "base/files/file_path.h" #include "base/location.h" +#include "base/logging.h" #include "base/macros.h" #include "base/memory/ptr_util.h" #include "base/metrics/histogram_macros.h" #include "base/path_service.h" #include "base/run_loop.h" #include "base/single_thread_task_runner.h" +#include "base/strings/string_number_conversions.h" #include "base/synchronization/waitable_event.h" #include "base/task/post_task.h" #include "base/task/task_traits.h" @@ -98,6 +100,7 @@ #include "components/metrics_services_manager/metrics_services_manager.h" #include "components/metrics_services_manager/metrics_services_manager_client.h" #include "components/net_log/chrome_net_log.h" +#include "components/network_session_configurator/common/network_switches.h" #include "components/network_time/network_time_tracker.h" #include "components/optimization_guide/optimization_guide_service.h" #include "components/policy/core/common/policy_service.h" @@ -310,6 +313,18 @@ void BrowserProcessImpl::Init() { base::Bind(&ApplyMetricsReportingPolicy)); #endif + int max_connections_per_host = 0; + auto switch_value = base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( + switches::kMaxConnectionsPerHost); + if (!switch_value.empty() && !base::StringToInt(switch_value, &max_connections_per_host)) { + LOG(DFATAL) << "--" << switches::kMaxConnectionsPerHost + << " expected integer; got (\"" << switch_value << "\" instead)"; + } + if (max_connections_per_host != 0) { + net::ClientSocketPoolManager::set_max_sockets_per_group( + net::HttpNetworkSession::NORMAL_SOCKET_POOL, max_connections_per_host); + } + int max_per_proxy = local_state_->GetInteger(prefs::kMaxConnectionsPerProxy); net::ClientSocketPoolManager::set_max_sockets_per_proxy_server( net::HttpNetworkSession::NORMAL_SOCKET_POOL, --- a/chrome/browser/BUILD.gn +++ b/chrome/browser/BUILD.gn @@ -1914,6 +1914,7 @@ jumbo_split_static_library("browser") { "//components/net_log", "//components/network_hints/common", "//components/network_session_configurator/browser", + "//components/network_session_configurator/common", "//components/network_time", "//components/ntp_snippets", "//components/ntp_tiles",