| Differences between
and this patch
- a/Source/WebCore/ChangeLog +39 lines
Lines 1-3 a/Source/WebCore/ChangeLog_sec1
1
2012-03-22  Sergio Villar Senin  <svillar@igalia.com>
2
3
        [Soup] DNS prefetching spams resolver, shoots self in the foot
4
        https://bugs.webkit.org/show_bug.cgi?id=41630
5
6
        Reviewed by NOBODY (OOPS!).
7
8
        Added generic DNSResolveQueue class to throttle DNS
9
        prefetches. It's an abstract refactoring of CFNET's
10
        DNSResolveQueue. Platform specific methods implemented for soup
11
        and CFNET backends.
12
13
        No new tests required as we're just refactoring existing code to
14
        be used by two different ports.
15
16
        * GNUmakefile.list.am: added new file.
17
        * WebCore.vcproj/WebCore.vcproj: ditto.
18
        * WebCore.xcodeproj/project.pbxproj: ditto.
19
        * platform/network/DNSResolveQueue.cpp: Added.
20
        (WebCore):
21
        (WebCore::DNSResolveQueue::add): adds a new host to be prefetched.
22
        (WebCore::DNSResolveQueue::fired): by using a delay we coalesce
23
        several prefetch requests and try to resolve them all here.
24
        * platform/network/DNSResolveQueue.h: Added.
25
        (WebCore):
26
        (DNSResolveQueue): class that implements DNS prefetch
27
        throttling using a template pattern.
28
        (WebCore::DNSResolveQueue::shared):
29
        (WebCore::DNSResolveQueue::decrementRequestCount):
30
        * platform/network/cf/DNSCFNet.cpp:
31
        (WebCore::DNSResolveQueue::platformProxyIsEnabledInSystemPreferences):
32
        (WebCore::DNSResolveQueue::platformResolve):
33
        * platform/network/soup/DNSSoup.cpp:
34
        (WebCore):
35
        (WebCore::DNSResolveQueue::platformProxyIsEnabledInSystemPreferences):
36
        (WebCore::resolvedCallback):
37
        (WebCore::DNSResolveQueue::platformResolve):
38
        (WebCore::prefetchDNS):
39
1
2012-03-21  Ilya Tikhonovsky  <loislo@chromium.org>
40
2012-03-21  Ilya Tikhonovsky  <loislo@chromium.org>
2
41
3
        Web Inspector: HeapProfiler: Heap snapshot worker has to report the errors to the front-end
42
        Web Inspector: HeapProfiler: Heap snapshot worker has to report the errors to the front-end
- a/Source/WebCore/GNUmakefile.list.am +2 lines
Lines 3379-3384 webcore_sources += \ a/Source/WebCore/GNUmakefile.list.am_sec1
3379
	Source/WebCore/platform/network/CredentialStorage.cpp \
3379
	Source/WebCore/platform/network/CredentialStorage.cpp \
3380
	Source/WebCore/platform/network/CredentialStorage.h \
3380
	Source/WebCore/platform/network/CredentialStorage.h \
3381
	Source/WebCore/platform/network/DNS.h \
3381
	Source/WebCore/platform/network/DNS.h \
3382
	Source/WebCore/platform/network/DNSResolveQueue.cpp \
3383
	Source/WebCore/platform/network/DNSResolveQueue.h \
3382
	Source/WebCore/platform/network/FormDataBuilder.cpp \
3384
	Source/WebCore/platform/network/FormDataBuilder.cpp \
3383
	Source/WebCore/platform/network/FormDataBuilder.h \
3385
	Source/WebCore/platform/network/FormDataBuilder.h \
3384
	Source/WebCore/platform/network/FormData.cpp \
3386
	Source/WebCore/platform/network/FormData.cpp \
- a/Source/WebCore/WebCore.vcproj/WebCore.vcproj +8 lines
Lines 31249-31254 a/Source/WebCore/WebCore.vcproj/WebCore.vcproj_sec1
31249
					>
31249
					>
31250
				</File>
31250
				</File>
31251
				<File
31251
				<File
31252
					RelativePath="..\platform\network\DNSResolveQueue.cpp"
31253
					>
31254
				</File>
31255
				<File
31256
					RelativePath="..\platform\network\DNSResolveQueue.h"
31257
					>
31258
				</File>
31259
				<File
31252
					RelativePath="..\platform\network\FormData.cpp"
31260
					RelativePath="..\platform\network\FormData.cpp"
31253
					>
31261
					>
31254
				</File>
31262
				</File>
- a/Source/WebCore/WebCore.xcodeproj/project.pbxproj +6 lines
Lines 5970-5975 a/Source/WebCore/WebCore.xcodeproj/project.pbxproj_sec1
5970
		ED501DC60B249F2900AE18D9 /* EditorMac.mm in Sources */ = {isa = PBXBuildFile; fileRef = ED501DC50B249F2900AE18D9 /* EditorMac.mm */; };
5970
		ED501DC60B249F2900AE18D9 /* EditorMac.mm in Sources */ = {isa = PBXBuildFile; fileRef = ED501DC50B249F2900AE18D9 /* EditorMac.mm */; };
5971
		EDE3A5000C7A430600956A37 /* ColorMac.h in Headers */ = {isa = PBXBuildFile; fileRef = EDE3A4FF0C7A430600956A37 /* ColorMac.h */; settings = {ATTRIBUTES = (Private, ); }; };
5971
		EDE3A5000C7A430600956A37 /* ColorMac.h in Headers */ = {isa = PBXBuildFile; fileRef = EDE3A4FF0C7A430600956A37 /* ColorMac.h */; settings = {ATTRIBUTES = (Private, ); }; };
5972
		EDEC98030AED7E170059137F /* WebCorePrefix.h in Headers */ = {isa = PBXBuildFile; fileRef = EDEC98020AED7E170059137F /* WebCorePrefix.h */; };
5972
		EDEC98030AED7E170059137F /* WebCorePrefix.h in Headers */ = {isa = PBXBuildFile; fileRef = EDEC98020AED7E170059137F /* WebCorePrefix.h */; };
5973
		F293B27E56C112F373FFF27E /* DNSResolveQueue.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7C60128060078BB70E367A95 /* DNSResolveQueue.cpp */; };
5973
		F316396B1329481A00A649CB /* InjectedScriptManager.cpp in Sources */ = {isa = PBXBuildFile; fileRef = F31639691329481A00A649CB /* InjectedScriptManager.cpp */; };
5974
		F316396B1329481A00A649CB /* InjectedScriptManager.cpp in Sources */ = {isa = PBXBuildFile; fileRef = F31639691329481A00A649CB /* InjectedScriptManager.cpp */; };
5974
		F316396C1329481A00A649CB /* InjectedScriptManager.h in Headers */ = {isa = PBXBuildFile; fileRef = F316396A1329481A00A649CB /* InjectedScriptManager.h */; };
5975
		F316396C1329481A00A649CB /* InjectedScriptManager.h in Headers */ = {isa = PBXBuildFile; fileRef = F316396A1329481A00A649CB /* InjectedScriptManager.h */; };
5975
		F316396E1329487600A649CB /* JSInjectedScriptManager.cpp in Sources */ = {isa = PBXBuildFile; fileRef = F316396D1329487600A649CB /* JSInjectedScriptManager.cpp */; };
5976
		F316396E1329487600A649CB /* JSInjectedScriptManager.cpp in Sources */ = {isa = PBXBuildFile; fileRef = F316396D1329487600A649CB /* JSInjectedScriptManager.cpp */; };
Lines 8864-8869 a/Source/WebCore/WebCore.xcodeproj/project.pbxproj_sec2
8864
		7AF11A5912E727490061F23C /* InspectorRuntimeAgent.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = InspectorRuntimeAgent.h; sourceTree = "<group>"; };
8865
		7AF11A5912E727490061F23C /* InspectorRuntimeAgent.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = InspectorRuntimeAgent.h; sourceTree = "<group>"; };
8865
		7AFD4A8A1131C2760035B883 /* ScriptBreakpoint.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ScriptBreakpoint.h; sourceTree = "<group>"; };
8866
		7AFD4A8A1131C2760035B883 /* ScriptBreakpoint.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ScriptBreakpoint.h; sourceTree = "<group>"; };
8866
		7AFD4FF3113277B60035B883 /* ScriptDebugListener.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ScriptDebugListener.h; sourceTree = "<group>"; };
8867
		7AFD4FF3113277B60035B883 /* ScriptDebugListener.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ScriptDebugListener.h; sourceTree = "<group>"; };
8868
		7C60128060078BB70E367A95 /* DNSResolveQueue.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = DNSResolveQueue.cpp; sourceTree = "<group>"; };
8867
		7E33CD00127F340D00BE8F17 /* PurgePriority.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PurgePriority.h; sourceTree = "<group>"; };
8869
		7E33CD00127F340D00BE8F17 /* PurgePriority.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PurgePriority.h; sourceTree = "<group>"; };
8868
		7E37EF2D1339208800B29250 /* SubresourceLoaderCF.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = SubresourceLoaderCF.cpp; path = cf/SubresourceLoaderCF.cpp; sourceTree = "<group>"; };
8870
		7E37EF2D1339208800B29250 /* SubresourceLoaderCF.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = SubresourceLoaderCF.cpp; path = cf/SubresourceLoaderCF.cpp; sourceTree = "<group>"; };
8869
		7EE6844C12D26E3800E79415 /* AuthenticationCF.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = AuthenticationCF.cpp; sourceTree = "<group>"; };
8871
		7EE6844C12D26E3800E79415 /* AuthenticationCF.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = AuthenticationCF.cpp; sourceTree = "<group>"; };
Lines 13236-13241 a/Source/WebCore/WebCore.xcodeproj/project.pbxproj_sec3
13236
		FA654A671108ABE2002615E0 /* mathattrs.in */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = mathattrs.in; sourceTree = "<group>"; };
13238
		FA654A671108ABE2002615E0 /* mathattrs.in */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = mathattrs.in; sourceTree = "<group>"; };
13237
		FA654A691108ABED002615E0 /* MathMLTextElement.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = MathMLTextElement.cpp; sourceTree = "<group>"; };
13239
		FA654A691108ABED002615E0 /* MathMLTextElement.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = MathMLTextElement.cpp; sourceTree = "<group>"; };
13238
		FA654A6A1108ABED002615E0 /* MathMLTextElement.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MathMLTextElement.h; sourceTree = "<group>"; };
13240
		FA654A6A1108ABED002615E0 /* MathMLTextElement.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MathMLTextElement.h; sourceTree = "<group>"; };
13241
		FA6E466FCD0418A9966A5B60 /* DNSResolveQueue.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DNSResolveQueue.h; sourceTree = "<group>"; };
13239
		FABE72ED1059C1EB00D999DD /* MathMLElement.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = MathMLElement.cpp; sourceTree = "<group>"; };
13242
		FABE72ED1059C1EB00D999DD /* MathMLElement.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = MathMLElement.cpp; sourceTree = "<group>"; };
13240
		FABE72EE1059C1EB00D999DD /* MathMLElement.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MathMLElement.h; sourceTree = "<group>"; };
13243
		FABE72EE1059C1EB00D999DD /* MathMLElement.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MathMLElement.h; sourceTree = "<group>"; };
13241
		FABE72EF1059C1EB00D999DD /* MathMLInlineContainerElement.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = MathMLInlineContainerElement.cpp; sourceTree = "<group>"; };
13244
		FABE72EF1059C1EB00D999DD /* MathMLInlineContainerElement.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = MathMLInlineContainerElement.cpp; sourceTree = "<group>"; };
Lines 15042-15047 a/Source/WebCore/WebCore.xcodeproj/project.pbxproj_sec4
15042
				51A052321058774F00CC9E95 /* CredentialStorage.cpp */,
15045
				51A052321058774F00CC9E95 /* CredentialStorage.cpp */,
15043
				51A052311058774F00CC9E95 /* CredentialStorage.h */,
15046
				51A052311058774F00CC9E95 /* CredentialStorage.h */,
15044
				B2F34FE50E82F81400F627CD /* DNS.h */,
15047
				B2F34FE50E82F81400F627CD /* DNS.h */,
15048
				7C60128060078BB70E367A95 /* DNSResolveQueue.cpp */,
15049
				FA6E466FCD0418A9966A5B60 /* DNSResolveQueue.h */,
15045
				514C765A0CE923A1007EF3CD /* FormData.cpp */,
15050
				514C765A0CE923A1007EF3CD /* FormData.cpp */,
15046
				514C765B0CE923A1007EF3CD /* FormData.h */,
15051
				514C765B0CE923A1007EF3CD /* FormData.h */,
15047
				085B92B80EFDE73D00E6123C /* FormDataBuilder.cpp */,
15052
				085B92B80EFDE73D00E6123C /* FormDataBuilder.cpp */,
Lines 25275-25280 a/Source/WebCore/WebCore.xcodeproj/project.pbxproj_sec5
25275
				FD31609012B026F700C1A359 /* Distance.cpp in Sources */,
25280
				FD31609012B026F700C1A359 /* Distance.cpp in Sources */,
25276
				A1E1154413015C3D0054AC8C /* DistantLightSource.cpp in Sources */,
25281
				A1E1154413015C3D0054AC8C /* DistantLightSource.cpp in Sources */,
25277
				B2F34FE90E82F82700F627CD /* DNSCFNet.cpp in Sources */,
25282
				B2F34FE90E82F82700F627CD /* DNSCFNet.cpp in Sources */,
25283
				F293B27E56C112F373FFF27E /* DNSResolveQueue.cpp in Sources */,
25278
				A8185F3C09765766005826D9 /* Document.cpp in Sources */,
25284
				A8185F3C09765766005826D9 /* Document.cpp in Sources */,
25279
				A3BB59F31457A40D00AC56FE /* DocumentEventQueue.cpp in Sources */,
25285
				A3BB59F31457A40D00AC56FE /* DocumentEventQueue.cpp in Sources */,
25280
				A8185F3F09765766005826D9 /* DocumentFragment.cpp in Sources */,
25286
				A8185F3F09765766005826D9 /* DocumentFragment.cpp in Sources */,
- a/Source/WebCore/platform/network/DNSResolveQueue.cpp +93 lines
Line 0 a/Source/WebCore/platform/network/DNSResolveQueue.cpp_sec1
1
/*
2
 * Copyright (C) 2009 Apple Inc. All Rights Reserved.
3
 * Copyright (C) 2012 Igalia S.L.
4
 *
5
 * Redistribution and use in source and binary forms, with or without
6
 * modification, are permitted provided that the following conditions
7
 * are met:
8
 * 1. Redistributions of source code must retain the above copyright
9
 *    notice, this list of conditions and the following disclaimer.
10
 * 2. Redistributions in binary form must reproduce the above copyright
11
 *    notice, this list of conditions and the following disclaimer in the
12
 *    documentation and/or other materials provided with the distribution.
13
 *
14
 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
15
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
18
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
21
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
22
 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
24
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25
 */
26
27
#include "config.h"
28
#include "DNSResolveQueue.h"
29
30
namespace WebCore {
31
32
// When resolve queue is empty, we fire async resolution requests immediately (which is important if the prefetch is triggered by hovering).
33
// But during page parsing, we should coalesce identical requests to avoid stressing out the DNS resolver.
34
static const int gNamesToResolveImmediately = 4;
35
36
// Coalesce prefetch requests for this long before sending them out.
37
static const double gCoalesceDelayInSeconds = 1.0;
38
39
// Sending many DNS requests at once can overwhelm some gateways. See <rdar://8105550> for specific CFNET issues with CFHost throttling.
40
static const int gMaxSimultaneousRequests = 8;
41
42
// 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
43
// to negatively affect other applications' performance by pushing their cached entries out.
44
// If we end up with lots of names to prefetch, some will be dropped.
45
static const int gMaxRequestsToQueue = 64;
46
47
// If there were queued names that couldn't be sent simultaneously, check the state of resolvers after this delay.
48
static const double gRetryResolvingInSeconds = 0.1;
49
50
void DNSResolveQueue::add(const String& hostname)
51
{
52
    // If there are no names queued, and few enough are in flight, resolve immediately (the mouse may be over a link).
53
    if (!m_names.size()) {
54
        if (platformProxyIsEnabledInSystemPreferences())
55
            return;
56
57
        if (atomicIncrement(&m_requestsInFlight) <= gNamesToResolveImmediately) {
58
            platformResolve(hostname);
59
            return;
60
        }
61
        atomicDecrement(&m_requestsInFlight);
62
    }
63
64
    // It's better to not prefetch some names than to clog the queue.
65
    // Dropping the newest names, because on a single page, these are likely to be below oldest ones.
66
    if (m_names.size() < gMaxRequestsToQueue) {
67
        m_names.add(hostname);
68
        if (!isActive())
69
            startOneShot(gCoalesceDelayInSeconds);
70
    }
71
}
72
73
void DNSResolveQueue::fired()
74
{
75
    if (platformProxyIsEnabledInSystemPreferences()) {
76
        m_names.clear();
77
        return;
78
    }
79
80
    int requestsAllowed = gMaxSimultaneousRequests - m_requestsInFlight;
81
82
    for (; !m_names.isEmpty() && requestsAllowed > 0; --requestsAllowed) {
83
        atomicIncrement(&m_requestsInFlight);
84
        HashSet<String>::iterator currentName = m_names.begin();
85
        platformResolve(*currentName);
86
        m_names.remove(currentName);
87
    }
88
89
    if (!m_names.isEmpty())
90
        startOneShot(gRetryResolvingInSeconds);
91
}
92
93
} // namespace WebCore
- a/Source/WebCore/platform/network/DNSResolveQueue.h +64 lines
Line 0 a/Source/WebCore/platform/network/DNSResolveQueue.h_sec1
1
/*
2
 * Copyright (C) 2009 Apple Inc. All Rights Reserved.
3
 * Copyright (C) 2012 Igalia S.L.
4
 *
5
 * Redistribution and use in source and binary forms, with or without
6
 * modification, are permitted provided that the following conditions
7
 * are met:
8
 * 1. Redistributions of source code must retain the above copyright
9
 *    notice, this list of conditions and the following disclaimer.
10
 * 2. Redistributions in binary form must reproduce the above copyright
11
 *    notice, this list of conditions and the following disclaimer in the
12
 *    documentation and/or other materials provided with the distribution.
13
 *
14
 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
15
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
18
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
21
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
22
 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
24
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25
 */
26
27
#ifndef DNSResolveQueue_h
28
#define DNSResolveQueue_h
29
30
#include "Timer.h"
31
#include <wtf/Forward.h>
32
#include <wtf/HashSet.h>
33
#include <wtf/text/StringHash.h>
34
35
namespace WebCore {
36
37
class DNSResolveQueue : public TimerBase {
38
39
public:
40
    static DNSResolveQueue& shared()
41
    {
42
      DEFINE_STATIC_LOCAL(DNSResolveQueue, queue, ());
43
      return queue;
44
    }
45
46
    void add(const String& hostname);
47
    void decrementRequestCount()
48
    {
49
      atomicDecrement(&m_requestsInFlight);
50
    }
51
52
private:
53
    bool platformProxyIsEnabledInSystemPreferences();
54
    void platformResolve(const String&);
55
56
    void fired();
57
58
    HashSet<String> m_names;
59
    int m_requestsInFlight;
60
};
61
62
}
63
64
#endif // DNSResolveQueue_h
- a/Source/WebCore/platform/network/cf/DNSCFNet.cpp -95 / +4 lines
Lines 26-31 a/Source/WebCore/platform/network/cf/DNSCFNet.cpp_sec1
26
26
27
#include "config.h"
27
#include "config.h"
28
#include "DNS.h"
28
#include "DNS.h"
29
#include "DNSResolveQueue.h"
29
30
30
#include "KURL.h"
31
#include "KURL.h"
31
#include "Timer.h"
32
#include "Timer.h"
Lines 47-71 a/Source/WebCore/platform/network/cf/DNSCFNet.cpp_sec2
47
48
48
namespace WebCore {
49
namespace WebCore {
49
50
50
// When resolve queue is empty, we fire async resolution requests immediately (which is important if the prefetch is triggered by hovering).
51
bool DNSResolveQueue::platformProxyIsEnabledInSystemPreferences()
51
// But during page parsing, we should coalesce identical requests to avoid stressing out CFHost.
52
const int namesToResolveImmediately = 4;
53
54
// Coalesce prefetch requests for this long before sending them out.
55
const double coalesceDelayInSeconds = 1.0;
56
57
// Sending many DNS requests at once can overwhelm some gateways. CFHost doesn't currently throttle for us, see <rdar://8105550>.
58
const int maxSimultaneousRequests = 8;
59
60
// 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
61
// to negatively affect other applications' performance by pushing their cached entries out.
62
// If we end up with lots of names to prefetch, some will be dropped.
63
const int maxRequestsToQueue = 64;
64
65
// If there were queued names that couldn't be sent simultaneously, check the state of resolvers after this delay.
66
const double retryResolvingInSeconds = 0.1;
67
68
static bool proxyIsEnabledInSystemPreferences()
69
{
52
{
70
    // Don't do DNS prefetch if proxies are involved. For many proxy types, the user agent is never exposed
53
    // Don't do DNS prefetch if proxies are involved. For many proxy types, the user agent is never exposed
71
    // to the IP address during normal operation. Querying an internal DNS server may not help performance,
54
    // to the IP address during normal operation. Querying an internal DNS server may not help performance,
Lines 96-189 static bool proxyIsEnabledInSystemPreferences() a/Source/WebCore/platform/network/cf/DNSCFNet.cpp_sec3
96
    return httpProxyCount || httpsProxyCount;
79
    return httpProxyCount || httpsProxyCount;
97
}
80
}
98
81
99
class DNSResolveQueue : public TimerBase {
100
public:
101
    static DNSResolveQueue& shared();
102
    void add(const String&);
103
    void decrementRequestCount();
104
105
private:
106
    DNSResolveQueue();
107
108
    void resolve(const String&);
109
    virtual void fired();
110
    HashSet<String> m_names;
111
    int m_requestsInFlight;
112
};
113
114
DNSResolveQueue::DNSResolveQueue()
115
    : m_requestsInFlight(0)
116
{
117
}
118
119
DNSResolveQueue& DNSResolveQueue::shared()
120
{
121
    DEFINE_STATIC_LOCAL(DNSResolveQueue, names, ());
122
    return names;
123
}
124
125
void DNSResolveQueue::add(const String& name)
126
{
127
    // If there are no names queued, and few enough are in flight, resolve immediately (the mouse may be over a link).
128
    if (!m_names.size()) {
129
        if (proxyIsEnabledInSystemPreferences())
130
            return;
131
132
        if (atomicIncrement(&m_requestsInFlight) <= namesToResolveImmediately) {
133
            resolve(name);
134
            return;
135
        }
136
        atomicDecrement(&m_requestsInFlight);
137
    }
138
139
    // It's better to not prefetch some names than to clog the queue.
140
    // Dropping the newest names, because on a single page, these are likely to be below oldest ones.
141
    if (m_names.size() < maxRequestsToQueue) {
142
        m_names.add(name);
143
        if (!isActive())
144
            startOneShot(coalesceDelayInSeconds);
145
    }
146
}
147
148
void DNSResolveQueue::decrementRequestCount()
149
{
150
    atomicDecrement(&m_requestsInFlight);
151
}
152
153
void DNSResolveQueue::fired()
154
{
155
    if (proxyIsEnabledInSystemPreferences()) {
156
        m_names.clear();
157
        return;
158
    }
159
160
    int requestsAllowed = maxSimultaneousRequests - m_requestsInFlight;
161
162
    for (; !m_names.isEmpty() && requestsAllowed > 0; --requestsAllowed) {
163
        atomicIncrement(&m_requestsInFlight);
164
        HashSet<String>::iterator currentName = m_names.begin();
165
        resolve(*currentName);
166
        m_names.remove(currentName);
167
    }
168
169
    if (!m_names.isEmpty())
170
        startOneShot(retryResolvingInSeconds);
171
}
172
173
static void clientCallback(CFHostRef theHost, CFHostInfoType, const CFStreamError*, void*)
82
static void clientCallback(CFHostRef theHost, CFHostInfoType, const CFStreamError*, void*)
174
{
83
{
175
    DNSResolveQueue::shared().decrementRequestCount(); // It's ok to call shared() from a secondary thread, the static variable has already been initialized by now.
84
    DNSResolveQueue::shared().decrementRequestCount(); // It's ok to call shared() from a secondary thread, the static variable has already been initialized by now.
176
    CFRelease(theHost);
85
    CFRelease(theHost);
177
}
86
}
178
87
179
void DNSResolveQueue::resolve(const String& hostname)
88
void DNSResolveQueue::platformResolve(const String& hostname)
180
{
89
{
181
    ASSERT(isMainThread());
90
    ASSERT(isMainThread());
182
91
183
    RetainPtr<CFStringRef> hostnameCF(AdoptCF, hostname.createCFString());
92
    RetainPtr<CFStringRef> hostnameCF(AdoptCF, hostname.createCFString());
184
    RetainPtr<CFHostRef> host(AdoptCF, CFHostCreateWithName(0, hostnameCF.get()));
93
    RetainPtr<CFHostRef> host(AdoptCF, CFHostCreateWithName(0, hostnameCF.get()));
185
    if (!host) {
94
    if (!host) {
186
        atomicDecrement(&m_requestsInFlight);
95
        DNSResolveQueue::shared().decrementRequestCount();
187
        return;
96
        return;
188
    }
97
    }
189
    CFHostClientContext context = { 0, 0, 0, 0, 0 };
98
    CFHostClientContext context = { 0, 0, 0, 0, 0 };
- a/Source/WebCore/platform/network/soup/DNSSoup.cpp -6 / +24 lines
Lines 26-49 a/Source/WebCore/platform/network/soup/DNSSoup.cpp_sec1
26
26
27
#include "config.h"
27
#include "config.h"
28
#include "DNS.h"
28
#include "DNS.h"
29
#include "DNSResolveQueue.h"
29
30
30
#include "GOwnPtrSoup.h"
31
#include "GOwnPtrSoup.h"
31
#include "ResourceHandle.h"
32
#include "ResourceHandle.h"
33
#include <wtf/MainThread.h>
32
#include <wtf/text/CString.h>
34
#include <wtf/text/CString.h>
33
35
34
namespace WebCore {
36
namespace WebCore {
35
37
38
// There is no current reliable way to know if we're behind a proxy at
39
// this level. We'll have to implement it in
40
// SoupSession/SoupProxyURIResolver/GProxyResolver
41
bool DNSResolveQueue::platformProxyIsEnabledInSystemPreferences()
42
{
43
    return false;
44
}
45
46
static void resolvedCallback(SoupAddress* soupAddress, guint status, void* userData)
47
{
48
    DNSResolveQueue::shared().decrementRequestCount();
49
}
50
51
void DNSResolveQueue::platformResolve(const String& hostname)
52
{
53
    ASSERT(isMainThread());
54
55
    soup_session_prefetch_dns(ResourceHandle::defaultSession(), hostname.utf8().data(), 0, resolvedCallback, 0);
56
}
57
36
void prefetchDNS(const String& hostname)
58
void prefetchDNS(const String& hostname)
37
{
59
{
60
    ASSERT(isMainThread());
38
    if (hostname.isEmpty())
61
    if (hostname.isEmpty())
39
        return;
62
        return;
40
63
41
    String uri = "http://" + hostname;
64
    DNSResolveQueue::shared().add(hostname);
42
    GOwnPtr<SoupURI> soupURI(soup_uri_new(uri.utf8().data()));
43
    if (!soupURI)
44
        return;
45
46
    soup_session_prepare_for_uri(ResourceHandle::defaultSession(), soupURI.get());
47
}
65
}
48
66
49
}
67
}
- a/Source/cmake/OptionsEfl.cmake -2 / +2 lines
Lines 32-40 FIND_PACKAGE(JPEG REQUIRED) a/Source/cmake/OptionsEfl.cmake_sec1
32
FIND_PACKAGE(PNG REQUIRED)
32
FIND_PACKAGE(PNG REQUIRED)
33
FIND_PACKAGE(ZLIB REQUIRED)
33
FIND_PACKAGE(ZLIB REQUIRED)
34
34
35
FIND_PACKAGE(Glib REQUIRED)
35
FIND_PACKAGE(Glib 2.31.8 REQUIRED)
36
FIND_PACKAGE(Gthread REQUIRED)
36
FIND_PACKAGE(Gthread REQUIRED)
37
FIND_PACKAGE(LibSoup2 2.37.2.1 REQUIRED)
37
FIND_PACKAGE(LibSoup2 2.37.92 REQUIRED)
38
SET(ENABLE_GLIB_SUPPORT ON)
38
SET(ENABLE_GLIB_SUPPORT ON)
39
39
40
SET(WTF_USE_SOUP 1)
40
SET(WTF_USE_SOUP 1)
- a/Tools/ChangeLog +11 lines
Lines 1-3 a/Tools/ChangeLog_sec1
1
2012-03-22  Sergio Villar Senin  <svillar@igalia.com>
2
3
        [Soup] DNS prefetching spams resolver, shoots self in the foot
4
        https://bugs.webkit.org/show_bug.cgi?id=41630
5
6
        Reviewed by NOBODY (OOPS!).
7
8
        Bump libsoup and glib dependencies.
9
10
        * gtk/jhbuild.modules:
11
1
2012-03-22  Carlos Garcia Campos  <cgarcia@bb-webkit-rel-64.local.igalia.com>
12
2012-03-22  Carlos Garcia Campos  <cgarcia@bb-webkit-rel-64.local.igalia.com>
2
13
3
        [GTK] Use the angle-bracket form to include wtf headers
14
        [GTK] Use the angle-bracket form to include wtf headers
- a/Tools/efl/jhbuild.modules -5 / +5 lines
Lines 108-117 a/Tools/efl/jhbuild.modules_sec1
108
    <dependencies>
108
    <dependencies>
109
      <dep package="libffi"/>
109
      <dep package="libffi"/>
110
    </dependencies>
110
    </dependencies>
111
    <branch module="/pub/GNOME/sources/glib/2.31/glib-2.31.2.tar.xz" version="2.31.2"
111
    <branch module="/pub/GNOME/sources/glib/2.31/glib-2.31.8.tar.xz" version="2.31.8"
112
            repo="ftp.gnome.org"
112
            repo="ftp.gnome.org"
113
            hash="sha256:19d7921671a487c3c5759a57df7b8508afdbadd7764d62a47a82fff7b399032b"
113
            hash="sha256:1ce3d275189000e1c50e92efcdb6447bc260b1e5c41699b7a1959e3e1928fbaa"
114
            md5sum="1cbdf314d7c87916a0c3dce83ac0285f"/>
114
            md5sum="6909664f29fae2f00cc3181c8c6a6aa7"/>
115
  </autotools>
115
  </autotools>
116
116
117
  <autotools id="glib-networking">
117
  <autotools id="glib-networking">
Lines 140-148 a/Tools/efl/jhbuild.modules_sec2
140
    <dependencies>
140
    <dependencies>
141
      <dep package="glib-networking"/>
141
      <dep package="glib-networking"/>
142
    </dependencies>
142
    </dependencies>
143
    <branch module="libsoup" version="2.37.2.1+git"
143
    <branch module="libsoup" version="2.37.92"
144
            repo="git.gnome.org"
144
            repo="git.gnome.org"
145
            tag="5cbfc48caf76ced2e28ee06c9e40523273601dc6"/>
145
            tag="afcff7115a6c36ca3de5bc88994174f5a0e01956"/>
146
  </autotools>
146
  </autotools>
147
147
148
  <autotools id="fontconfig" autogen-sh="configure">
148
  <autotools id="fontconfig" autogen-sh="configure">
- a/Tools/gtk/jhbuild.modules -5 / +5 lines
Lines 122-131 a/Tools/gtk/jhbuild.modules_sec1
122
    <dependencies>
122
    <dependencies>
123
      <dep package="libffi"/>
123
      <dep package="libffi"/>
124
    </dependencies>
124
    </dependencies>
125
    <branch module="/pub/GNOME/sources/glib/2.31/glib-2.31.2.tar.xz" version="2.31.2"
125
    <branch module="/pub/GNOME/sources/glib/2.31/glib-2.31.8.tar.xz" version="2.31.8"
126
            repo="ftp.gnome.org"
126
            repo="ftp.gnome.org"
127
            hash="sha256:19d7921671a487c3c5759a57df7b8508afdbadd7764d62a47a82fff7b399032b"
127
            hash="sha256:1ce3d275189000e1c50e92efcdb6447bc260b1e5c41699b7a1959e3e1928fbaa"
128
            md5sum="1cbdf314d7c87916a0c3dce83ac0285f"/>
128
            md5sum="6909664f29fae2f00cc3181c8c6a6aa7"/>
129
  </autotools>
129
  </autotools>
130
130
131
  <autotools id="glib-networking">
131
  <autotools id="glib-networking">
Lines 154-162 a/Tools/gtk/jhbuild.modules_sec2
154
    <dependencies>
154
    <dependencies>
155
      <dep package="glib-networking"/>
155
      <dep package="glib-networking"/>
156
    </dependencies>
156
    </dependencies>
157
    <branch module="libsoup" version="2.37.2.1+git"
157
    <branch module="libsoup" version="2.37.92"
158
            repo="git.gnome.org"
158
            repo="git.gnome.org"
159
            tag="5cbfc48caf76ced2e28ee06c9e40523273601dc6"/>
159
            tag="afcff7115a6c36ca3de5bc88994174f5a0e01956"/>
160
  </autotools>
160
  </autotools>
161
161
162
  <autotools id="fontconfig" autogen-sh="configure">
162
  <autotools id="fontconfig" autogen-sh="configure">
- a/ChangeLog +12 lines
Lines 1-3 a/ChangeLog_sec1
1
2012-03-22  Sergio Villar Senin  <svillar@igalia.com>
2
3
        [Soup] DNS prefetching spams resolver, shoots self in the foot
4
        https://bugs.webkit.org/show_bug.cgi?id=41630
5
6
        Reviewed by NOBODY (OOPS!).
7
8
        Bump libsoup and glib dependencies.
9
10
        * Source/cmake/OptionsEfl.cmake:
11
        * configure.ac:
12
1
2012-03-21  Ryosuke Niwa  <rniwa@webkit.org>
13
2012-03-21  Ryosuke Niwa  <rniwa@webkit.org>
2
14
3
        Add the forgotten admin.html after r108917.
15
        Add the forgotten admin.html after r108917.
- a/configure.ac -2 / +2 lines
Lines 377-384 fi a/configure.ac_sec1
377
CAIRO_REQUIRED_VERSION=1.10
377
CAIRO_REQUIRED_VERSION=1.10
378
FONTCONFIG_REQUIRED_VERSION=2.4
378
FONTCONFIG_REQUIRED_VERSION=2.4
379
FREETYPE2_REQUIRED_VERSION=9.0
379
FREETYPE2_REQUIRED_VERSION=9.0
380
GLIB_REQUIRED_VERSION=2.31.2
380
GLIB_REQUIRED_VERSION=2.31.8
381
LIBSOUP_REQUIRED_VERSION=2.37.2.1
381
LIBSOUP_REQUIRED_VERSION=2.37.92
382
LIBXML_REQUIRED_VERSION=2.6
382
LIBXML_REQUIRED_VERSION=2.6
383
PANGO_REQUIRED_VERSION=1.21.0
383
PANGO_REQUIRED_VERSION=1.21.0
384
384

Return to Bug 41630