From cce34d58dbec10d9d499e6b54e4a15d9fa66fcba Mon Sep 17 00:00:00 2001 From: rtenneti Date: Fri, 5 Jun 2015 16:36:29 -0700 Subject: [PATCH] HttpServerProperties - Don't persist if SetServerNetworkStats is called with the same origin (HostPortPair) and value (ServerNetworkStats). This change reduces the number of times SetServerNetworkStats tries to persist HttpServerProperties to disk (currently 17% of persist calls are due to SetServerNetworkStats). BUG=451256 R=rch@chromium.org Review URL: https://codereview.chromium.org/1158823005 Cr-Commit-Position: refs/heads/master@{#333173} --- net/http/http_server_properties.h | 9 +++++++++ net/http/http_server_properties_manager.cc | 10 +++++++++- net/http/http_server_properties_manager_unittest.cc | 2 ++ 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/net/http/http_server_properties.h b/net/http/http_server_properties.h index 417a1d6b152a..4192361187cd 100644 --- a/net/http/http_server_properties.h +++ b/net/http/http_server_properties.h @@ -187,6 +187,14 @@ struct NET_EXPORT SupportsQuic { struct NET_EXPORT ServerNetworkStats { ServerNetworkStats() : bandwidth_estimate(QuicBandwidth::Zero()) {} + bool operator==(const ServerNetworkStats& other) const { + return srtt == other.srtt && bandwidth_estimate == other.bandwidth_estimate; + } + + bool operator!=(const ServerNetworkStats& other) const { + return !this->operator==(other); + } + base::TimeDelta srtt; QuicBandwidth bandwidth_estimate; }; @@ -313,6 +321,7 @@ class NET_EXPORT HttpServerProperties { virtual void SetSupportsQuic(bool used_quic, const IPAddressNumber& last_address) = 0; + // Sets |stats| for |host_port_pair|. virtual void SetServerNetworkStats(const HostPortPair& host_port_pair, ServerNetworkStats stats) = 0; diff --git a/net/http/http_server_properties_manager.cc b/net/http/http_server_properties_manager.cc index d4faf0ee8a64..26ce850dff02 100644 --- a/net/http/http_server_properties_manager.cc +++ b/net/http/http_server_properties_manager.cc @@ -345,8 +345,16 @@ void HttpServerPropertiesManager::SetServerNetworkStats( const HostPortPair& host_port_pair, ServerNetworkStats stats) { DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); + ServerNetworkStats old_stats; + const ServerNetworkStats* old_stats_ptr = + http_server_properties_impl_->GetServerNetworkStats(host_port_pair); + if (http_server_properties_impl_->GetServerNetworkStats(host_port_pair)) + old_stats = *old_stats_ptr; http_server_properties_impl_->SetServerNetworkStats(host_port_pair, stats); - ScheduleUpdatePrefsOnNetworkThread(SET_SERVER_NETWORK_STATS); + ServerNetworkStats new_stats = + *(http_server_properties_impl_->GetServerNetworkStats(host_port_pair)); + if (old_stats != new_stats) + ScheduleUpdatePrefsOnNetworkThread(SET_SERVER_NETWORK_STATS); } const ServerNetworkStats* HttpServerPropertiesManager::GetServerNetworkStats( diff --git a/net/http/http_server_properties_manager_unittest.cc b/net/http/http_server_properties_manager_unittest.cc index 8aaa9d1dcf90..77c476881316 100644 --- a/net/http/http_server_properties_manager_unittest.cc +++ b/net/http/http_server_properties_manager_unittest.cc @@ -625,6 +625,8 @@ TEST_F(HttpServerPropertiesManagerTest, ServerNetworkStats) { ServerNetworkStats stats1; stats1.srtt = base::TimeDelta::FromMicroseconds(10); http_server_props_manager_->SetServerNetworkStats(mail_server, stats1); + // ExpectScheduleUpdatePrefsOnNetworkThread() should be called only once. + http_server_props_manager_->SetServerNetworkStats(mail_server, stats1); // Run the task. base::RunLoop().RunUntilIdle(); -- 2.11.4.GIT