Bug 1471280 - Add new pref for how much longer resolver threads should remain idle r=bagder
authorValentin Gosu <valentin.gosu@gmail.com>
Wed, 04 Jul 2018 21:25:28 +0200
changeset 425157 d7788f2fd8a2d23d5cdd179115b2d7258d6d4f02
parent 425156 db553cb4218deaae330d6a0692b7a00e22ecc03e
child 425158 3bc036e4200bc188c75f23340c9615bc980660f1
push id34237
push userapavel@mozilla.com
push dateThu, 05 Jul 2018 16:28:59 +0000
treeherdermozilla-central@ce32b59b5a49 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbagder
bugs1471280
milestone63.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1471280 - Add new pref for how much longer resolver threads should remain idle r=bagder The new pref is "network.dns.resolver-thread-extra-idle-time-seconds" The default is 60 seconds. This means that threads will stay idle for an extra 60 seconds, after which they are shutdown. Setting the pref to 0 would preserve the behaviour before the threads were swiched to use nsThreadPool - meaning that they would be shutdown immediately after ThreadFunc completes. Setting the pref to -1 would keep the threads alive forever. MozReview-Commit-ID: CoUB5gan4MR
modules/libpref/init/all.js
netwerk/dns/nsHostResolver.cpp
--- a/modules/libpref/init/all.js
+++ b/modules/libpref/init/all.js
@@ -2038,16 +2038,20 @@ pref("network.dns.localDomains", "");
 // When non empty all non-localhost DNS queries (including IP addresses)
 // resolve to this value. The value can be a name or an IP address.
 // domains mapped to localhost with localDomains stay localhost.
 pref("network.dns.forceResolve", "");
 
 // Contols whether or not "localhost" should resolve when offline
 pref("network.dns.offline-localhost", true);
 
+// Defines how much longer resolver threads should stay idle before are shut down.
+// A negative value will keep the thread alive forever.
+pref("network.dns.resolver-thread-extra-idle-time-seconds", 60);
+
 // The maximum allowed length for a URL - 1MB default
 pref("network.standard-url.max-length", 1048576);
 
 // Whether nsIURI.host/.hostname/.spec should return a punycode string
 // If set to false we will revert to previous behaviour and return a unicode string.
 pref("network.standard-url.punycode-host", true);
 
 // Idle timeout for ftp control connections - 5 minute default
--- a/netwerk/dns/nsHostResolver.cpp
+++ b/netwerk/dns/nsHostResolver.cpp
@@ -504,16 +504,17 @@ nsHostRecord::RemoveOrRefresh()
     // Already resolved; not in a pending state; remove from cache
     return true;
 }
 
 //----------------------------------------------------------------------------
 
 static const char kPrefGetTtl[] = "network.dns.get-ttl";
 static const char kPrefNativeIsLocalhost[] = "network.dns.native-is-localhost";
+static const char kPrefThreadIdleTime[] = "network.dns.resolver-thread-extra-idle-time-seconds";
 static bool sGetTtlEnabled = false;
 mozilla::Atomic<bool, mozilla::Relaxed> gNativeIsLocalhost;
 
 static void DnsPrefChanged(const char* aPref, void* aClosure)
 {
     MOZ_ASSERT(NS_IsMainThread(),
                "Should be getting pref changed notification on main thread!");
 
@@ -589,19 +590,33 @@ nsHostResolver::Init()
     // during application startup.
     static int initCount = 0;
     if (initCount++ > 0) {
         LOG(("Calling 'res_ninit'.\n"));
         res_ninit(&_res);
     }
 #endif
 
+    // We can configure the threadpool to keep threads alive for a while after
+    // the last ThreadFunc task has been executed.
+    int32_t poolTimeoutSecs = Preferences::GetInt(kPrefThreadIdleTime, 60);
+    uint32_t poolTimeoutMs;
+    if (poolTimeoutSecs < 0) {
+        // This means never shut down the idle threads
+        poolTimeoutMs = UINT32_MAX;
+    } else {
+        // We clamp down the idle time between 0 and one hour.
+        poolTimeoutMs = mozilla::clamped<uint32_t>(poolTimeoutSecs * 1000,
+                                                   0, 3600 * 1000);
+    }
+
     nsCOMPtr<nsIThreadPool> threadPool = do_CreateInstance(NS_THREADPOOL_CONTRACTID);
     MOZ_ALWAYS_SUCCEEDS(threadPool->SetThreadLimit(MAX_RESOLVER_THREADS));
     MOZ_ALWAYS_SUCCEEDS(threadPool->SetIdleThreadLimit(MAX_RESOLVER_THREADS));
+    MOZ_ALWAYS_SUCCEEDS(threadPool->SetIdleThreadTimeout(poolTimeoutMs));
     MOZ_ALWAYS_SUCCEEDS(threadPool->SetThreadStackSize(nsIThreadManager::kThreadPoolStackSize));
     MOZ_ALWAYS_SUCCEEDS(threadPool->SetName(NS_LITERAL_CSTRING("DNS Resolver")));
     mResolverThreads = threadPool.forget();
 
     return NS_OK;
 }
 
 void