Title: [114564] releases/WebKitGTK/webkit-1.8
Revision
114564
Author
x...@webkit.org
Date
2012-04-18 14:34:51 -0700 (Wed, 18 Apr 2012)

Log Message

[Soup] DNS prefetching spams resolver, shoots self in the foot
https://bugs.webkit.org/show_bug.cgi?id=41630

Reviewed by Martin Robinson.

.:

Bump libsoup and glib dependencies.

* Source/cmake/OptionsEfl.cmake:
* configure.ac:

Source/WebCore:

Added generic DNSResolveQueue class to throttle DNS
prefetches. It's an abstract refactoring of CFNET's
DNSResolveQueue. Platform specific methods implemented for soup
and CFNET backends.

No new tests required as we're just refactoring existing code to
be used by two different ports.

* CMakeLists.txt: added new file.
* GNUmakefile.list.am: ditto.
* WebCore.vcproj/WebCore.vcproj: ditto.
* WebCore.xcodeproj/project.pbxproj: ditto.
* platform/network/DNSResolveQueue.cpp: Added.
(WebCore):
(WebCore::DNSResolveQueue::add): adds a new host to be prefetched.
(WebCore::DNSResolveQueue::fired): by using a delay we coalesce
several prefetch requests and try to resolve them all here.
* platform/network/DNSResolveQueue.h: Added.
(WebCore):
(DNSResolveQueue): class that implements DNS prefetch
throttling using a template pattern.
(WebCore::DNSResolveQueue::shared):
(WebCore::DNSResolveQueue::decrementRequestCount):
* platform/network/cf/DNSCFNet.cpp:
(WebCore::DNSResolveQueue::platformProxyIsEnabledInSystemPreferences):
(WebCore::DNSResolveQueue::platformResolve):
* platform/network/soup/DNSSoup.cpp:
(WebCore):
(WebCore::DNSResolveQueue::platformProxyIsEnabledInSystemPreferences):
(WebCore::resolvedCallback):
(WebCore::DNSResolveQueue::platformResolve):
(WebCore::prefetchDNS):

Tools:

Bump libsoup and glib dependencies.

* efl/jhbuild.modules:
* gtk/jhbuild.modules:


Conflicts:

	Tools/efl/jhbuild.modules

Modified Paths

Added Paths

Diff

Modified: releases/WebKitGTK/webkit-1.8/ChangeLog (114563 => 114564)


--- releases/WebKitGTK/webkit-1.8/ChangeLog	2012-04-18 21:34:25 UTC (rev 114563)
+++ releases/WebKitGTK/webkit-1.8/ChangeLog	2012-04-18 21:34:51 UTC (rev 114564)
@@ -1,3 +1,15 @@
+2012-03-28  Sergio Villar Senin  <svil...@igalia.com>
+
+        [Soup] DNS prefetching spams resolver, shoots self in the foot
+        https://bugs.webkit.org/show_bug.cgi?id=41630
+
+        Reviewed by Martin Robinson.
+
+        Bump libsoup and glib dependencies.
+
+        * Source/cmake/OptionsEfl.cmake:
+        * configure.ac:
+
 2012-04-09  Martin Robinson  <mrobin...@igalia.com>
 
         [soup] Crash while loading http://www.jusco.cn

Modified: releases/WebKitGTK/webkit-1.8/Source/WebCore/CMakeLists.txt (114563 => 114564)


--- releases/WebKitGTK/webkit-1.8/Source/WebCore/CMakeLists.txt	2012-04-18 21:34:25 UTC (rev 114563)
+++ releases/WebKitGTK/webkit-1.8/Source/WebCore/CMakeLists.txt	2012-04-18 21:34:51 UTC (rev 114564)
@@ -1199,6 +1199,7 @@
     platform/network/CredentialStorage.cpp
     platform/network/ContentTypeParser.cpp
     platform/network/DataURL.cpp
+    platform/network/DNSResolveQueue.cpp
     platform/network/FormDataBuilder.cpp
     platform/network/FormData.cpp
     platform/network/HTTPHeaderMap.cpp

Modified: releases/WebKitGTK/webkit-1.8/Source/WebCore/ChangeLog (114563 => 114564)


--- releases/WebKitGTK/webkit-1.8/Source/WebCore/ChangeLog	2012-04-18 21:34:25 UTC (rev 114563)
+++ releases/WebKitGTK/webkit-1.8/Source/WebCore/ChangeLog	2012-04-18 21:34:51 UTC (rev 114564)
@@ -1,3 +1,43 @@
+2012-03-28  Sergio Villar Senin  <svil...@igalia.com>
+
+        [Soup] DNS prefetching spams resolver, shoots self in the foot
+        https://bugs.webkit.org/show_bug.cgi?id=41630
+
+        Reviewed by Martin Robinson.
+
+        Added generic DNSResolveQueue class to throttle DNS
+        prefetches. It's an abstract refactoring of CFNET's
+        DNSResolveQueue. Platform specific methods implemented for soup
+        and CFNET backends.
+
+        No new tests required as we're just refactoring existing code to
+        be used by two different ports.
+
+        * CMakeLists.txt: added new file.
+        * GNUmakefile.list.am: ditto.
+        * WebCore.vcproj/WebCore.vcproj: ditto.
+        * WebCore.xcodeproj/project.pbxproj: ditto.
+        * platform/network/DNSResolveQueue.cpp: Added.
+        (WebCore):
+        (WebCore::DNSResolveQueue::add): adds a new host to be prefetched.
+        (WebCore::DNSResolveQueue::fired): by using a delay we coalesce
+        several prefetch requests and try to resolve them all here.
+        * platform/network/DNSResolveQueue.h: Added.
+        (WebCore):
+        (DNSResolveQueue): class that implements DNS prefetch
+        throttling using a template pattern.
+        (WebCore::DNSResolveQueue::shared):
+        (WebCore::DNSResolveQueue::decrementRequestCount):
+        * platform/network/cf/DNSCFNet.cpp:
+        (WebCore::DNSResolveQueue::platformProxyIsEnabledInSystemPreferences):
+        (WebCore::DNSResolveQueue::platformResolve):
+        * platform/network/soup/DNSSoup.cpp:
+        (WebCore):
+        (WebCore::DNSResolveQueue::platformProxyIsEnabledInSystemPreferences):
+        (WebCore::resolvedCallback):
+        (WebCore::DNSResolveQueue::platformResolve):
+        (WebCore::prefetchDNS):
+
 2012-03-14  Sudarsana Nagineni  <sudarsana.nagin...@linux.intel.com>
 
         Build error: DNSSoup.cpp:30: fatal error: CString.h: No such file or

Modified: releases/WebKitGTK/webkit-1.8/Source/WebCore/GNUmakefile.list.am (114563 => 114564)


--- releases/WebKitGTK/webkit-1.8/Source/WebCore/GNUmakefile.list.am	2012-04-18 21:34:25 UTC (rev 114563)
+++ releases/WebKitGTK/webkit-1.8/Source/WebCore/GNUmakefile.list.am	2012-04-18 21:34:51 UTC (rev 114564)
@@ -3189,6 +3189,8 @@
 	Source/WebCore/platform/network/CredentialStorage.cpp \
 	Source/WebCore/platform/network/CredentialStorage.h \
 	Source/WebCore/platform/network/DNS.h \
+	Source/WebCore/platform/network/DNSResolveQueue.cpp \
+	Source/WebCore/platform/network/DNSResolveQueue.h \
 	Source/WebCore/platform/network/FormDataBuilder.cpp \
 	Source/WebCore/platform/network/FormDataBuilder.h \
 	Source/WebCore/platform/network/FormData.cpp \

Modified: releases/WebKitGTK/webkit-1.8/Source/WebCore/WebCore.vcproj/WebCore.vcproj (114563 => 114564)


--- releases/WebKitGTK/webkit-1.8/Source/WebCore/WebCore.vcproj/WebCore.vcproj	2012-04-18 21:34:25 UTC (rev 114563)
+++ releases/WebKitGTK/webkit-1.8/Source/WebCore/WebCore.vcproj/WebCore.vcproj	2012-04-18 21:34:51 UTC (rev 114564)
@@ -30381,6 +30381,14 @@
 					>
 				</File>
 				<File
+					RelativePath="..\platform\network\DNSResolveQueue.cpp"
+					>
+				</File>
+				<File
+					RelativePath="..\platform\network\DNSResolveQueue.h"
+					>
+				</File>
+				<File
 					RelativePath="..\platform\network\FormData.cpp"
 					>
 				</File>

Modified: releases/WebKitGTK/webkit-1.8/Source/WebCore/WebCore.xcodeproj/project.pbxproj (114563 => 114564)


--- releases/WebKitGTK/webkit-1.8/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2012-04-18 21:34:25 UTC (rev 114563)
+++ releases/WebKitGTK/webkit-1.8/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2012-04-18 21:34:51 UTC (rev 114564)
@@ -5882,6 +5882,7 @@
 		ED501DC60B249F2900AE18D9 /* EditorMac.mm in Sources */ = {isa = PBXBuildFile; fileRef = ED501DC50B249F2900AE18D9 /* EditorMac.mm */; };
 		EDE3A5000C7A430600956A37 /* ColorMac.h in Headers */ = {isa = PBXBuildFile; fileRef = EDE3A4FF0C7A430600956A37 /* ColorMac.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		EDEC98030AED7E170059137F /* WebCorePrefix.h in Headers */ = {isa = PBXBuildFile; fileRef = EDEC98020AED7E170059137F /* WebCorePrefix.h */; };
+		F293B27E56C112F373FFF27E /* DNSResolveQueue.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7C60128060078BB70E367A95 /* DNSResolveQueue.cpp */; };
 		F316396B1329481A00A649CB /* InjectedScriptManager.cpp in Sources */ = {isa = PBXBuildFile; fileRef = F31639691329481A00A649CB /* InjectedScriptManager.cpp */; };
 		F316396C1329481A00A649CB /* InjectedScriptManager.h in Headers */ = {isa = PBXBuildFile; fileRef = F316396A1329481A00A649CB /* InjectedScriptManager.h */; };
 		F316396E1329487600A649CB /* JSInjectedScriptManager.cpp in Sources */ = {isa = PBXBuildFile; fileRef = F316396D1329487600A649CB /* JSInjectedScriptManager.cpp */; };
@@ -8828,6 +8829,7 @@
 		7AF11A5912E727490061F23C /* InspectorRuntimeAgent.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = InspectorRuntimeAgent.h; sourceTree = "<group>"; };
 		7AFD4A8A1131C2760035B883 /* ScriptBreakpoint.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ScriptBreakpoint.h; sourceTree = "<group>"; };
 		7AFD4FF3113277B60035B883 /* ScriptDebugListener.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ScriptDebugListener.h; sourceTree = "<group>"; };
+		7C60128060078BB70E367A95 /* DNSResolveQueue.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = DNSResolveQueue.cpp; sourceTree = "<group>"; };
 		7E33CD00127F340D00BE8F17 /* PurgePriority.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PurgePriority.h; sourceTree = "<group>"; };
 		7E37EF2D1339208800B29250 /* SubresourceLoaderCF.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = SubresourceLoaderCF.cpp; path = cf/SubresourceLoaderCF.cpp; sourceTree = "<group>"; };
 		7EE6844C12D26E3800E79415 /* AuthenticationCF.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = AuthenticationCF.cpp; sourceTree = "<group>"; };
@@ -13052,6 +13054,7 @@
 		FA654A671108ABE2002615E0 /* mathattrs.in */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = mathattrs.in; sourceTree = "<group>"; };
 		FA654A691108ABED002615E0 /* MathMLTextElement.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = MathMLTextElement.cpp; sourceTree = "<group>"; };
 		FA654A6A1108ABED002615E0 /* MathMLTextElement.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MathMLTextElement.h; sourceTree = "<group>"; };
+		FA6E466FCD0418A9966A5B60 /* DNSResolveQueue.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DNSResolveQueue.h; sourceTree = "<group>"; };
 		FABE72ED1059C1EB00D999DD /* MathMLElement.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = MathMLElement.cpp; sourceTree = "<group>"; };
 		FABE72EE1059C1EB00D999DD /* MathMLElement.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MathMLElement.h; sourceTree = "<group>"; };
 		FABE72EF1059C1EB00D999DD /* MathMLInlineContainerElement.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = MathMLInlineContainerElement.cpp; sourceTree = "<group>"; };
@@ -15013,6 +15016,8 @@
 				51A052321058774F00CC9E95 /* CredentialStorage.cpp */,
 				51A052311058774F00CC9E95 /* CredentialStorage.h */,
 				B2F34FE50E82F81400F627CD /* DNS.h */,
+				7C60128060078BB70E367A95 /* DNSResolveQueue.cpp */,
+				FA6E466FCD0418A9966A5B60 /* DNSResolveQueue.h */,
 				514C765A0CE923A1007EF3CD /* FormData.cpp */,
 				514C765B0CE923A1007EF3CD /* FormData.h */,
 				085B92B80EFDE73D00E6123C /* FormDataBuilder.cpp */,
@@ -24927,6 +24932,7 @@
 				FD31609012B026F700C1A359 /* Distance.cpp in Sources */,
 				A1E1154413015C3D0054AC8C /* DistantLightSource.cpp in Sources */,
 				B2F34FE90E82F82700F627CD /* DNSCFNet.cpp in Sources */,
+				F293B27E56C112F373FFF27E /* DNSResolveQueue.cpp in Sources */,
 				A8185F3C09765766005826D9 /* Document.cpp in Sources */,
 				A3BB59F31457A40D00AC56FE /* DocumentEventQueue.cpp in Sources */,
 				A8185F3F09765766005826D9 /* DocumentFragment.cpp in Sources */,

Added: releases/WebKitGTK/webkit-1.8/Source/WebCore/platform/network/DNSResolveQueue.cpp (0 => 114564)


--- releases/WebKitGTK/webkit-1.8/Source/WebCore/platform/network/DNSResolveQueue.cpp	                        (rev 0)
+++ releases/WebKitGTK/webkit-1.8/Source/WebCore/platform/network/DNSResolveQueue.cpp	2012-04-18 21:34:51 UTC (rev 114564)
@@ -0,0 +1,93 @@
+/*
+ * Copyright (C) 2009 Apple Inc. All Rights Reserved.
+ * Copyright (C) 2012 Igalia S.L.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "DNSResolveQueue.h"
+
+namespace WebCore {
+
+// When resolve queue is empty, we fire async resolution requests immediately (which is important if the prefetch is triggered by hovering).
+// But during page parsing, we should coalesce identical requests to avoid stressing out the DNS resolver.
+static const int gNamesToResolveImmediately = 4;
+
+// Coalesce prefetch requests for this long before sending them out.
+static const double gCoalesceDelayInSeconds = 1.0;
+
+// Sending many DNS requests at once can overwhelm some gateways. See <rdar://8105550> for specific CFNET issues with CFHost throttling.
+static const int gMaxSimultaneousRequests = 8;
+
+// For a page has links to many outside sites, it is likely that the system DNS resolver won't be able to cache them all anyway, and we don't want
+// to negatively affect other applications' performance by pushing their cached entries out.
+// If we end up with lots of names to prefetch, some will be dropped.
+static const int gMaxRequestsToQueue = 64;
+
+// If there were queued names that couldn't be sent simultaneously, check the state of resolvers after this delay.
+static const double gRetryResolvingInSeconds = 0.1;
+
+void DNSResolveQueue::add(const String& hostname)
+{
+    // If there are no names queued, and few enough are in flight, resolve immediately (the mouse may be over a link).
+    if (!m_names.size()) {
+        if (platformProxyIsEnabledInSystemPreferences())
+            return;
+
+        if (atomicIncrement(&m_requestsInFlight) <= gNamesToResolveImmediately) {
+            platformResolve(hostname);
+            return;
+        }
+        atomicDecrement(&m_requestsInFlight);
+    }
+
+    // It's better to not prefetch some names than to clog the queue.
+    // Dropping the newest names, because on a single page, these are likely to be below oldest ones.
+    if (m_names.size() < gMaxRequestsToQueue) {
+        m_names.add(hostname);
+        if (!isActive())
+            startOneShot(gCoalesceDelayInSeconds);
+    }
+}
+
+void DNSResolveQueue::fired()
+{
+    if (platformProxyIsEnabledInSystemPreferences()) {
+        m_names.clear();
+        return;
+    }
+
+    int requestsAllowed = gMaxSimultaneousRequests - m_requestsInFlight;
+
+    for (; !m_names.isEmpty() && requestsAllowed > 0; --requestsAllowed) {
+        atomicIncrement(&m_requestsInFlight);
+        HashSet<String>::iterator currentName = m_names.begin();
+        platformResolve(*currentName);
+        m_names.remove(currentName);
+    }
+
+    if (!m_names.isEmpty())
+        startOneShot(gRetryResolvingInSeconds);
+}
+
+} // namespace WebCore

Copied: releases/WebKitGTK/webkit-1.8/Source/WebCore/platform/network/DNSResolveQueue.h (from rev 114563, releases/WebKitGTK/webkit-1.8/Source/WebCore/platform/network/soup/DNSSoup.cpp) (0 => 114564)


--- releases/WebKitGTK/webkit-1.8/Source/WebCore/platform/network/DNSResolveQueue.h	                        (rev 0)
+++ releases/WebKitGTK/webkit-1.8/Source/WebCore/platform/network/DNSResolveQueue.h	2012-04-18 21:34:51 UTC (rev 114564)
@@ -0,0 +1,64 @@
+/*
+ * Copyright (C) 2009 Apple Inc. All Rights Reserved.
+ * Copyright (C) 2012 Igalia S.L.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef DNSResolveQueue_h
+#define DNSResolveQueue_h
+
+#include "Timer.h"
+#include <wtf/Forward.h>
+#include <wtf/HashSet.h>
+#include <wtf/text/StringHash.h>
+
+namespace WebCore {
+
+class DNSResolveQueue : public TimerBase {
+
+public:
+    static DNSResolveQueue& shared()
+    {
+      DEFINE_STATIC_LOCAL(DNSResolveQueue, queue, ());
+      return queue;
+    }
+
+    void add(const String& hostname);
+    void decrementRequestCount()
+    {
+      atomicDecrement(&m_requestsInFlight);
+    }
+
+private:
+    bool platformProxyIsEnabledInSystemPreferences();
+    void platformResolve(const String&);
+
+    void fired();
+
+    HashSet<String> m_names;
+    int m_requestsInFlight;
+};
+
+}
+
+#endif // DNSResolveQueue_h

Modified: releases/WebKitGTK/webkit-1.8/Source/WebCore/platform/network/cf/DNSCFNet.cpp (114563 => 114564)


--- releases/WebKitGTK/webkit-1.8/Source/WebCore/platform/network/cf/DNSCFNet.cpp	2012-04-18 21:34:25 UTC (rev 114563)
+++ releases/WebKitGTK/webkit-1.8/Source/WebCore/platform/network/cf/DNSCFNet.cpp	2012-04-18 21:34:51 UTC (rev 114564)
@@ -1,6 +1,7 @@
 /*
  * Copyright (C) 2008 Collin Jackson  <coll...@webkit.org>
  * Copyright (C) 2009 Apple Inc. All Rights Reserved.
+ * Copyright (C) 2012 Igalia S.L.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -26,6 +27,7 @@
 
 #include "config.h"
 #include "DNS.h"
+#include "DNSResolveQueue.h"
 
 #include "KURL.h"
 #include "Timer.h"
@@ -47,25 +49,7 @@
 
 namespace WebCore {
 
-// When resolve queue is empty, we fire async resolution requests immediately (which is important if the prefetch is triggered by hovering).
-// But during page parsing, we should coalesce identical requests to avoid stressing out CFHost.
-const int namesToResolveImmediately = 4;
-
-// Coalesce prefetch requests for this long before sending them out.
-const double coalesceDelayInSeconds = 1.0;
-
-// Sending many DNS requests at once can overwhelm some gateways. CFHost doesn't currently throttle for us, see <rdar://8105550>.
-const int maxSimultaneousRequests = 8;
-
-// For a page has links to many outside sites, it is likely that the system DNS resolver won't be able to cache them all anyway, and we don't want
-// to negatively affect other applications' performance by pushing their cached entries out.
-// If we end up with lots of names to prefetch, some will be dropped.
-const int maxRequestsToQueue = 64;
-
-// If there were queued names that couldn't be sent simultaneously, check the state of resolvers after this delay.
-const double retryResolvingInSeconds = 0.1;
-
-static bool proxyIsEnabledInSystemPreferences()
+bool DNSResolveQueue::platformProxyIsEnabledInSystemPreferences()
 {
     // Don't do DNS prefetch if proxies are involved. For many proxy types, the user agent is never exposed
     // to the IP address during normal operation. Querying an internal DNS server may not help performance,
@@ -96,94 +80,20 @@
     return httpProxyCount || httpsProxyCount;
 }
 
-class DNSResolveQueue : public TimerBase {
-public:
-    static DNSResolveQueue& shared();
-    void add(const String&);
-    void decrementRequestCount();
-
-private:
-    DNSResolveQueue();
-
-    void resolve(const String&);
-    virtual void fired();
-    HashSet<String> m_names;
-    int m_requestsInFlight;
-};
-
-DNSResolveQueue::DNSResolveQueue()
-    : m_requestsInFlight(0)
-{
-}
-
-DNSResolveQueue& DNSResolveQueue::shared()
-{
-    DEFINE_STATIC_LOCAL(DNSResolveQueue, names, ());
-    return names;
-}
-
-void DNSResolveQueue::add(const String& name)
-{
-    // If there are no names queued, and few enough are in flight, resolve immediately (the mouse may be over a link).
-    if (!m_names.size()) {
-        if (proxyIsEnabledInSystemPreferences())
-            return;
-
-        if (atomicIncrement(&m_requestsInFlight) <= namesToResolveImmediately) {
-            resolve(name);
-            return;
-        }
-        atomicDecrement(&m_requestsInFlight);
-    }
-
-    // It's better to not prefetch some names than to clog the queue.
-    // Dropping the newest names, because on a single page, these are likely to be below oldest ones.
-    if (m_names.size() < maxRequestsToQueue) {
-        m_names.add(name);
-        if (!isActive())
-            startOneShot(coalesceDelayInSeconds);
-    }
-}
-
-void DNSResolveQueue::decrementRequestCount()
-{
-    atomicDecrement(&m_requestsInFlight);
-}
-
-void DNSResolveQueue::fired()
-{
-    if (proxyIsEnabledInSystemPreferences()) {
-        m_names.clear();
-        return;
-    }
-
-    int requestsAllowed = maxSimultaneousRequests - m_requestsInFlight;
-
-    for (; !m_names.isEmpty() && requestsAllowed > 0; --requestsAllowed) {
-        atomicIncrement(&m_requestsInFlight);
-        HashSet<String>::iterator currentName = m_names.begin();
-        resolve(*currentName);
-        m_names.remove(currentName);
-    }
-
-    if (!m_names.isEmpty())
-        startOneShot(retryResolvingInSeconds);
-}
-
 static void clientCallback(CFHostRef theHost, CFHostInfoType, const CFStreamError*, void*)
 {
     DNSResolveQueue::shared().decrementRequestCount(); // It's ok to call shared() from a secondary thread, the static variable has already been initialized by now.
     CFRelease(theHost);
 }
 
-void DNSResolveQueue::resolve(const String& hostname)
+void DNSResolveQueue::platformResolve(const String& hostname)
 {
     ASSERT(isMainThread());
 
     RetainPtr<CFStringRef> hostnameCF(AdoptCF, hostname.createCFString());
     RetainPtr<CFHostRef> host(AdoptCF, CFHostCreateWithName(0, hostnameCF.get()));
     if (!host) {
-        atomicDecrement(&m_requestsInFlight);
+        decrementRequestCount();
         return;
     }
     CFHostClientContext context = { 0, 0, 0, 0, 0 };

Modified: releases/WebKitGTK/webkit-1.8/Source/WebCore/platform/network/soup/DNSSoup.cpp (114563 => 114564)


--- releases/WebKitGTK/webkit-1.8/Source/WebCore/platform/network/soup/DNSSoup.cpp	2012-04-18 21:34:25 UTC (rev 114563)
+++ releases/WebKitGTK/webkit-1.8/Source/WebCore/platform/network/soup/DNSSoup.cpp	2012-04-18 21:34:51 UTC (rev 114564)
@@ -26,24 +26,42 @@
 
 #include "config.h"
 #include "DNS.h"
+#include "DNSResolveQueue.h"
 
 #include "GOwnPtrSoup.h"
 #include "ResourceHandle.h"
+#include <wtf/MainThread.h>
 #include <wtf/text/CString.h>
 
 namespace WebCore {
 
+// There is no current reliable way to know if we're behind a proxy at
+// this level. We'll have to implement it in
+// SoupSession/SoupProxyURIResolver/GProxyResolver
+bool DNSResolveQueue::platformProxyIsEnabledInSystemPreferences()
+{
+    return false;
+}
+
+static void resolvedCallback(SoupAddress* soupAddress, guint status, void* userData)
+{
+    DNSResolveQueue::shared().decrementRequestCount();
+}
+
+void DNSResolveQueue::platformResolve(const String& hostname)
+{
+    ASSERT(isMainThread());
+
+    soup_session_prefetch_dns(ResourceHandle::defaultSession(), hostname.utf8().data(), 0, resolvedCallback, 0);
+}
+
 void prefetchDNS(const String& hostname)
 {
+    ASSERT(isMainThread());
     if (hostname.isEmpty())
         return;
 
-    String uri = "http://" + hostname;
-    GOwnPtr<SoupURI> soupURI(soup_uri_new(uri.utf8().data()));
-    if (!soupURI)
-        return;
-
-    soup_session_prepare_for_uri(ResourceHandle::defaultSession(), soupURI.get());
+    DNSResolveQueue::shared().add(hostname);
 }
 
 }

Modified: releases/WebKitGTK/webkit-1.8/Source/cmake/OptionsEfl.cmake (114563 => 114564)


--- releases/WebKitGTK/webkit-1.8/Source/cmake/OptionsEfl.cmake	2012-04-18 21:34:25 UTC (rev 114563)
+++ releases/WebKitGTK/webkit-1.8/Source/cmake/OptionsEfl.cmake	2012-04-18 21:34:51 UTC (rev 114564)
@@ -31,9 +31,9 @@
 FIND_PACKAGE(JPEG REQUIRED)
 FIND_PACKAGE(PNG REQUIRED)
 
-FIND_PACKAGE(Glib REQUIRED)
+FIND_PACKAGE(Glib 2.31.8 REQUIRED)
 FIND_PACKAGE(Gthread REQUIRED)
-FIND_PACKAGE(LibSoup2 2.37.2.1 REQUIRED)
+FIND_PACKAGE(LibSoup2 2.37.92 REQUIRED)
 SET(ENABLE_GLIB_SUPPORT ON)
 
 SET(WTF_USE_SOUP 1)

Modified: releases/WebKitGTK/webkit-1.8/Tools/ChangeLog (114563 => 114564)


--- releases/WebKitGTK/webkit-1.8/Tools/ChangeLog	2012-04-18 21:34:25 UTC (rev 114563)
+++ releases/WebKitGTK/webkit-1.8/Tools/ChangeLog	2012-04-18 21:34:51 UTC (rev 114564)
@@ -1,3 +1,15 @@
+2012-03-28  Sergio Villar Senin  <svil...@igalia.com>
+
+        [Soup] DNS prefetching spams resolver, shoots self in the foot
+        https://bugs.webkit.org/show_bug.cgi?id=41630
+
+        Reviewed by Martin Robinson.
+
+        Bump libsoup and glib dependencies.
+
+        * efl/jhbuild.modules:
+        * gtk/jhbuild.modules:
+
 2012-03-19  Martin Robinson  <mrobin...@igalia.com>
 
         [GTK] Allow running run-gtk-tests during 'make distcheck'

Modified: releases/WebKitGTK/webkit-1.8/Tools/gtk/jhbuild.modules (114563 => 114564)


--- releases/WebKitGTK/webkit-1.8/Tools/gtk/jhbuild.modules	2012-04-18 21:34:25 UTC (rev 114563)
+++ releases/WebKitGTK/webkit-1.8/Tools/gtk/jhbuild.modules	2012-04-18 21:34:51 UTC (rev 114564)
@@ -120,10 +120,10 @@
     <dependencies>
       <dep package="libffi"/>
     </dependencies>
-    <branch module="/pub/GNOME/sources/glib/2.31/glib-2.31.2.tar.xz" version="2.31.2"
+    <branch module="/pub/GNOME/sources/glib/2.31/glib-2.31.8.tar.xz" version="2.31.8"
             repo="ftp.gnome.org"
-            hash="sha256:19d7921671a487c3c5759a57df7b8508afdbadd7764d62a47a82fff7b399032b"
-            md5sum="1cbdf314d7c87916a0c3dce83ac0285f"/>
+            hash="sha256:1ce3d275189000e1c50e92efcdb6447bc260b1e5c41699b7a1959e3e1928fbaa"
+            md5sum="6909664f29fae2f00cc3181c8c6a6aa7"/>
   </autotools>
 
   <autotools id="glib-networking">
@@ -152,9 +152,9 @@
     <dependencies>
       <dep package="glib-networking"/>
     </dependencies>
-    <branch module="libsoup" version="2.37.2.1+git"
+    <branch module="libsoup" version="2.37.92"
             repo="git.gnome.org"
-            tag="5cbfc48caf76ced2e28ee06c9e40523273601dc6"/>
+            tag="afcff7115a6c36ca3de5bc88994174f5a0e01956"/>
   </autotools>
 
   <autotools id="fontconfig" autogen-sh="configure">

Modified: releases/WebKitGTK/webkit-1.8/configure.ac (114563 => 114564)


--- releases/WebKitGTK/webkit-1.8/configure.ac	2012-04-18 21:34:25 UTC (rev 114563)
+++ releases/WebKitGTK/webkit-1.8/configure.ac	2012-04-18 21:34:51 UTC (rev 114564)
@@ -377,8 +377,8 @@
 CAIRO_REQUIRED_VERSION=1.10
 FONTCONFIG_REQUIRED_VERSION=2.4
 FREETYPE2_REQUIRED_VERSION=9.0
-GLIB_REQUIRED_VERSION=2.31.2
-LIBSOUP_REQUIRED_VERSION=2.37.2.1
+GLIB_REQUIRED_VERSION=2.31.8
+LIBSOUP_REQUIRED_VERSION=2.37.92
 LIBXML_REQUIRED_VERSION=2.6
 PANGO_REQUIRED_VERSION=1.21.0
 
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to