-
Notifications
You must be signed in to change notification settings - Fork 9.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
core(simulator): add DNS timing (#5607)
- Loading branch information
1 parent
ff7d162
commit acea63d
Showing
45 changed files
with
621 additions
and
245 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
83 changes: 83 additions & 0 deletions
83
lighthouse-core/lib/dependency-graph/simulator/dns-cache.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
/** | ||
* @license Copyright 2018 Google Inc. All Rights Reserved. | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 | ||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. | ||
*/ | ||
'use strict'; | ||
|
||
// A DNS lookup will usually take ~1-2 roundtrips of connection latency plus the extra DNS routing time. | ||
// Example: https://www.webpagetest.org/result/180703_3A_e33ec79747c002ed4d7bcbfc81462203/1/details/#waterfall_view_step1 | ||
// Example: https://www.webpagetest.org/result/180707_1M_89673eb633b5d98386de95dfcf9b33d5/1/details/#waterfall_view_step1 | ||
// DNS is highly variable though, many times it's a little more than 1, but can easily be 4-5x RTT. | ||
// We'll use 2 since it seems to give the most accurate results on average, but this can be tweaked. | ||
const DNS_RESOLUTION_RTT_MULTIPLIER = 2; | ||
|
||
class DNSCache { | ||
/** | ||
* @param {{rtt: number}} options | ||
*/ | ||
constructor(options) { | ||
this._options = Object.assign( | ||
{ | ||
rtt: undefined, | ||
}, | ||
options | ||
); | ||
|
||
if (!this._options.rtt) { | ||
throw new Error('Cannot create DNS cache with no rtt'); | ||
} | ||
|
||
this._rtt = this._options.rtt; | ||
/** @type {Map<string, {resolvedAt: number}>} */ | ||
this._resolvedDomainNames = new Map(); | ||
} | ||
|
||
/** | ||
* @param {LH.Artifacts.NetworkRequest} request | ||
* @param {{requestedAt: number, shouldUpdateCache: boolean}=} options | ||
* @return {number} | ||
*/ | ||
getTimeUntilResolution(request, options) { | ||
const {requestedAt = 0, shouldUpdateCache = false} = options || {}; | ||
|
||
const domain = request.parsedURL.host; | ||
const cacheEntry = this._resolvedDomainNames.get(domain); | ||
let timeUntilResolved = this._rtt * DNSCache.RTT_MULTIPLIER; | ||
if (cacheEntry) { | ||
const timeUntilCachedIsResolved = Math.max(cacheEntry.resolvedAt - requestedAt, 0); | ||
timeUntilResolved = Math.min(timeUntilCachedIsResolved, timeUntilResolved); | ||
} | ||
|
||
const resolvedAt = requestedAt + timeUntilResolved; | ||
if (shouldUpdateCache) this._updateCacheResolvedAtIfNeeded(request, resolvedAt); | ||
|
||
return timeUntilResolved; | ||
} | ||
|
||
/** | ||
* @param {LH.Artifacts.NetworkRequest} request | ||
* @param {number} resolvedAt | ||
*/ | ||
_updateCacheResolvedAtIfNeeded(request, resolvedAt) { | ||
const domain = request.parsedURL.host; | ||
const cacheEntry = this._resolvedDomainNames.get(domain) || {resolvedAt}; | ||
cacheEntry.resolvedAt = Math.min(cacheEntry.resolvedAt, resolvedAt); | ||
this._resolvedDomainNames.set(domain, cacheEntry); | ||
} | ||
|
||
/** | ||
* Forcefully sets the DNS resolution time for a record. | ||
* Useful for testing and alternate execution simulations. | ||
* | ||
* @param {string} domain | ||
* @param {number} resolvedAt | ||
*/ | ||
setResolvedAt(domain, resolvedAt) { | ||
this._resolvedDomainNames.set(domain, {resolvedAt}); | ||
} | ||
} | ||
|
||
DNSCache.RTT_MULTIPLIER = DNS_RESOLUTION_RTT_MULTIPLIER; | ||
|
||
module.exports = DNSCache; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
lighthouse-core/test/audits/__snapshots__/load-fast-enough-for-pwa-test.js.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`PWA: load-fast-enough-for-pwa audit overrides with simulated result when throttling is modified 1`] = `3427`; |
38 changes: 38 additions & 0 deletions
38
lighthouse-core/test/audits/__snapshots__/metrics-test.js.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`Performance: metrics evaluates valid input correctly 1`] = ` | ||
Object { | ||
"estimatedInputLatency": 104, | ||
"estimatedInputLatencyTs": undefined, | ||
"firstCPUIdle": 3351, | ||
"firstCPUIdleTs": undefined, | ||
"firstContentfulPaint": 911, | ||
"firstContentfulPaintTs": undefined, | ||
"firstMeaningfulPaint": 1355, | ||
"firstMeaningfulPaintTs": undefined, | ||
"interactive": 3427, | ||
"interactiveTs": undefined, | ||
"observedDomContentLoaded": 560, | ||
"observedDomContentLoadedTs": 225414732309, | ||
"observedFirstContentfulPaint": 499, | ||
"observedFirstContentfulPaintTs": 225414670885, | ||
"observedFirstMeaningfulPaint": 783, | ||
"observedFirstMeaningfulPaintTs": 225414955343, | ||
"observedFirstPaint": 499, | ||
"observedFirstPaintTs": 225414670868, | ||
"observedFirstVisualChange": 520, | ||
"observedFirstVisualChangeTs": 225414692015, | ||
"observedLastVisualChange": 818, | ||
"observedLastVisualChangeTs": 225414990015, | ||
"observedLoad": 2199, | ||
"observedLoadTs": 225416370913, | ||
"observedNavigationStart": 0, | ||
"observedNavigationStartTs": 225414172015, | ||
"observedSpeedIndex": 605, | ||
"observedSpeedIndexTs": 225414776724, | ||
"observedTraceEnd": 12540, | ||
"observedTraceEndTs": 225426711887, | ||
"speedIndex": 1656, | ||
"speedIndexTs": undefined, | ||
} | ||
`; |
24 changes: 24 additions & 0 deletions
24
lighthouse-core/test/audits/__snapshots__/predictive-perf-test.js.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`Performance: predictive performance audit should compute the predicted values 1`] = ` | ||
Object { | ||
"optimisticEIL": 101, | ||
"optimisticFCP": 911, | ||
"optimisticFMP": 1211, | ||
"optimisticSI": 605, | ||
"optimisticTTFCPUI": 3351, | ||
"optimisticTTI": 3351, | ||
"pessimisticEIL": 158, | ||
"pessimisticFCP": 911, | ||
"pessimisticFMP": 1498, | ||
"pessimisticSI": 1630, | ||
"pessimisticTTFCPUI": 3502, | ||
"pessimisticTTI": 3502, | ||
"roughEstimateOfEIL": 104, | ||
"roughEstimateOfFCP": 911, | ||
"roughEstimateOfFMP": 1355, | ||
"roughEstimateOfSI": 1656, | ||
"roughEstimateOfTTFCPUI": 3351, | ||
"roughEstimateOfTTI": 3427, | ||
} | ||
`; |
12 changes: 12 additions & 0 deletions
12
lighthouse-core/test/audits/byte-efficiency/__snapshots__/byte-efficiency-audit-test.js.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`Byte efficiency base audit should allow overriding of computeWasteWithTTIGraph 1`] = ` | ||
Object { | ||
"default": 1330, | ||
"justTTI": 950, | ||
} | ||
`; | ||
|
||
exports[`Byte efficiency base audit should create load simulator with the specified settings 1`] = `1330`; | ||
|
||
exports[`Byte efficiency base audit should create load simulator with the specified settings 2`] = `22950`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.