-
Notifications
You must be signed in to change notification settings - Fork 9.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: configurable page timeout #1672
Conversation
lighthouse-core/gather/driver.js
Outdated
* @return {!Promise} | ||
* @private | ||
*/ | ||
_waitForFullyLoaded(pauseAfterLoadMs) { | ||
_waitForFullyLoaded(pauseAfterLoadMs, maxTimeoutMs) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
naming: i prefer the clarity of the old name.. how about maxWaitForLoadedMs
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
will do
lighthouse-core/gather/driver.js
Outdated
@@ -477,11 +478,15 @@ class Driver { | |||
const waitForLoad = _options.waitForLoad || false; | |||
const disableJS = _options.disableJavaScript || false; | |||
const pauseAfterLoadMs = (_options.flags && _options.flags.pauseAfterLoad) || PAUSE_AFTER_LOAD; | |||
let maxWaitMs = MAX_WAIT_FOR_FULLY_LOADED; | |||
if (_options.flags && _options.flags.timeout) { | |||
maxWaitMs = 1000 * _options.flags.timeout; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
x = y * 1000
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
will do, anything magic I'm not aware of or just style? I know in this case it doesn't matter but I developed a habit of putting the type to coerce to first when dealing with potentially unknown types to avoid {} + ''
vs '' + {}
scenarios :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah i see. totally a style thing.. I'm just used to seeing the integers on the right side.
but good call on doing this for protection with +.
nbd either way
lighthouse-cli/bin.ts
Outdated
@@ -114,6 +116,7 @@ Example: --output-path=./lighthouse-results.html` | |||
.default('output', Printer.GetValidOutputOptions()[Printer.OutputMode.pretty]) | |||
.default('output-path', 'stdout') | |||
.default('port', 9222) | |||
.default('timeout', 25) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
since the MAX_WAIT_FOR_FULLY_LOADED
is still in driver, seems like we should let this value fall through as undefined
? wdyt
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we double default disableCpuThrottling as well and the extra yargs hints to users won't hurt IMO
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
main benefit of having it here is the --help
printing, but if we want a default it has to happen internally as well for anyone using lighthouse as a module.
What about exposing on Driver as a constant, so it would still be single source of truth .default('timeout', Driver.MAX_WAIT_FOR_FULLY_LOADED)
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A bit overkill to bring in driver just for the constant to me. I don't think it's even that crazy that programmatic access and CLI access could have different sensible defaults at some point either, but I'm fine with removing if we like.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think in general (at least from a documentation perspective) it's better to make sure they're the same, but in this case my main problem would be development in driver, where you'd have to remember why changes to MAX_WAIT_FOR_FULLY_LOADED
aren't doing anything when the CLI is run.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
k, done
lighthouse-cli/bin.ts
Outdated
@@ -62,7 +62,8 @@ const cliFlags = yargs | |||
'list-trace-categories', | |||
'config-path', | |||
'perf', | |||
'port' | |||
'port', | |||
'timeout' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
timeout
makes me think of a timeout for the whole run or something. Maybe some non-awkward version of page-load-timeout
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah I started with that but it felt so clunky and didn't make a ton of sense to have any other timeout, what about adopting the max-wait-for-load
name from within if we change?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thinking about this now, I wouldn't think timeout
was the whole run, and there are better tools to accomplish that if you do want to limit that on the command line.
The only other thing I would guess as a user of this would be that timeout
would apply to the entirety of each pass, as in not just page load but (∑beforePass()
es + page load + ∑afterPass()
es), to make sure a particular pass doesn't go on forever. As long as our gatherers are relatively bounded, though, these are roughly the same thing.
(I guess custom gatherers could go crazy, but that's on them)
I think I'm good with going with --timeout
, but since it's such prime flag real estate (and not necessarily self-descriptive) maybe @paulirish and @ebidel want to weigh in.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should be more specific. --timeout
feels too generic and it's clear from this discussion, that it's ambiguous what it could mean :) page-load-timeout
or max-wait-for-load
would be cool.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
alright sounds good, I'll go with max-wait-for-load
for consistency
One more thing to note, this can get dangerous if you always set it very high. Testing the verge leads to ugly OOM crashes if you actually try and wait for it when a particularly nasty ad loads... |
what does WPT do in those cases? Is it possible to cleanly wrap up the trace before load has finished? |
AFAICT there's nothing preventing it from also suffering from the OOM case, it just has a timeout that's a little more reasonable that's more likely to contain the events we care about and doesn't process the traces in the same process (does it incrementally in a separate python process) |
2bdfc93
to
e47b102
Compare
PTAL :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looking good
lighthouse-cli/bin.ts
Outdated
@@ -62,7 +62,8 @@ const cliFlags = yargs | |||
'list-trace-categories', | |||
'config-path', | |||
'perf', | |||
'port' | |||
'port', | |||
'timeout' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thinking about this now, I wouldn't think timeout
was the whole run, and there are better tools to accomplish that if you do want to limit that on the command line.
The only other thing I would guess as a user of this would be that timeout
would apply to the entirety of each pass, as in not just page load but (∑beforePass()
es + page load + ∑afterPass()
es), to make sure a particular pass doesn't go on forever. As long as our gatherers are relatively bounded, though, these are roughly the same thing.
(I guess custom gatherers could go crazy, but that's on them)
I think I'm good with going with --timeout
, but since it's such prime flag real estate (and not necessarily self-descriptive) maybe @paulirish and @ebidel want to weigh in.
lighthouse-cli/bin.ts
Outdated
@@ -75,6 +77,7 @@ const cliFlags = yargs | |||
'config-path': 'The path to the config JSON.', | |||
'perf': 'Use a performance-test-only configuration', | |||
'port': 'The port to use for the debugging protocol. Use 0 for a random port', | |||
'timeout': 'The timeout in seconds to wait for the page to load before continuing', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we add a warning about large traces and OOM? If you're frustrated with slow page loads (#1464), a large number might be the first thing you try. A full warning may be more appropriate for the readme but more people will see something brief written here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
lighthouse-cli/bin.ts
Outdated
@@ -114,6 +117,7 @@ Example: --output-path=./lighthouse-results.html` | |||
.default('output', Printer.GetValidOutputOptions()[Printer.OutputMode.pretty]) | |||
.default('output-path', 'stdout') | |||
.default('port', 9222) | |||
.default('timeout', Driver.MAX_WAIT_FOR_FULLY_LOADED / 1000) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
are seconds the usual thing for command line timeouts? (obvs most of the js world tends towards ms)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When it's a CLI interface for something whose order of magnitude is nearly always measured in seconds I've seen seconds more often than ms, but with a name change to more reflect that it's an internal code setting I think a move to ms is more reasonable.
lighthouse-core/gather/driver.js
Outdated
@@ -477,11 +480,15 @@ class Driver { | |||
const waitForLoad = _options.waitForLoad || false; | |||
const disableJS = _options.disableJavaScript || false; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
while you're in here, do you want to get rid of _options
and make options
a default {}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
will do
lighthouse-cli/bin.ts
Outdated
@@ -278,7 +282,8 @@ function saveResults(results: Results, | |||
|
|||
function runLighthouse(url: string, | |||
flags: {port: number, skipAutolaunch: boolean, selectChrome: boolean, output: any, | |||
outputPath: string, interactive: boolean, saveArtifacts: boolean, saveAssets: boolean}, | |||
outputPath: string, interactive: boolean, saveArtifacts: boolean, saveAssets: boolean | |||
timeout: number}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this just for documentation? I wouldn't think TS would care since we don't use it here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah just for documentation.
lighthouse-cli/bin.ts
Outdated
@@ -143,6 +147,10 @@ if (!cliFlags.outputPath && cliFlags['output-path']) { | |||
cliFlags.outputPath = cliFlags['output-path']; | |||
} | |||
|
|||
if (!cliFlags.maxWaitForLoad && cliFlags['max-wait-for-load']) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
how would this be possible? AFAIK, yargs creates the former and makes sure they match at this point.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The bug as mentioned in the above identical check makes this happen when the default is used.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How do we feel about updating yargs? Current is 6.6.0 :(
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What was the google3 dependency on yargs that kept us here, are they game to update?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suspect that's it. Just complaining out loud that that restriction continues to hold us back.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's bump yargs from our 3.30.0 to 3.32.0.
It has the fix for these: yargs/yargs@51c0063
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done, from the looks of it google3 is still on lighthouse ~1.1 so we likely will have quite a few other issues to iron out when they want to upgrade anyway...
lighthouse-cli/bin.ts
Outdated
@@ -75,6 +77,7 @@ const cliFlags = yargs | |||
'config-path': 'The path to the config JSON.', | |||
'perf': 'Use a performance-test-only configuration', | |||
'port': 'The port to use for the debugging protocol. Use 0 for a random port', | |||
'max-wait-for-load': 'The timeout in milliseconds to wait for the page to load before continuing. WARNING: Very high values can lead to large traces and instability', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: The timeout (in milliseconds) to wait before the page is considered done loading and the run should continue. WARNING:...`
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
const waitForLoad = options.waitForLoad || false; | ||
const disableJS = options.disableJavaScript || false; | ||
const pauseAfterLoadMs = (options.flags && options.flags.pauseAfterLoad) || PAUSE_AFTER_LOAD; | ||
const maxWaitMs = (options.flags && options.flags.maxWaitForLoad) || |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we support --max-wait-for-load = 0
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would say that would lead to a useless lighthouse run that wouldn't return any results so filling in default is fine with me :)
readme.md
Outdated
@@ -149,6 +149,11 @@ Configuration: | |||
--list-trace-categories Prints a list of all required trace categories and exits [boolean] | |||
--config-path The path to the config JSON. | |||
--perf Use a performance-test-only configuration [boolean] | |||
--port The port to use for the debugging protocol. Use 0 for a | |||
random port. [default: 9222] | |||
--max-wait-for-load The timeout in milliseconds to wait for the page to |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you'll want to update this description too to match the CLI help
Thanks guys 🎉 |
fixes #1671