Skip to content
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

Merged
merged 6 commits into from
Feb 16, 2017
Merged

feat: configurable page timeout #1672

merged 6 commits into from
Feb 16, 2017

Conversation

patrickhulce
Copy link
Collaborator

fixes #1671

* @return {!Promise}
* @private
*/
_waitForFullyLoaded(pauseAfterLoadMs) {
_waitForFullyLoaded(pauseAfterLoadMs, maxTimeoutMs) {
Copy link
Member

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 ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will do

@@ -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;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

x = y * 1000

Copy link
Collaborator Author

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 :)

Copy link
Member

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

@@ -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)
Copy link
Member

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

Copy link
Collaborator Author

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

Copy link
Member

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)?

Copy link
Collaborator Author

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.

Copy link
Member

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.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

k, done

@@ -62,7 +62,8 @@ const cliFlags = yargs
'list-trace-categories',
'config-path',
'perf',
'port'
'port',
'timeout'
Copy link
Member

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?

Copy link
Collaborator Author

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?

Copy link
Member

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.

Copy link
Contributor

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.

Copy link
Collaborator Author

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

@patrickhulce
Copy link
Collaborator Author

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...

@brendankenny
Copy link
Member

what does WPT do in those cases? Is it possible to cleanly wrap up the trace before load has finished?

@patrickhulce
Copy link
Collaborator Author

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)

@patrickhulce
Copy link
Collaborator Author

PTAL :)

Copy link
Member

@brendankenny brendankenny left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looking good

@@ -62,7 +62,8 @@ const cliFlags = yargs
'list-trace-categories',
'config-path',
'perf',
'port'
'port',
'timeout'
Copy link
Member

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.

@@ -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',
Copy link
Member

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.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@@ -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)
Copy link
Member

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)

Copy link
Collaborator Author

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.

@@ -477,11 +480,15 @@ class Driver {
const waitForLoad = _options.waitForLoad || false;
const disableJS = _options.disableJavaScript || false;
Copy link
Member

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 {}

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will do

@@ -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},
Copy link
Member

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

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah just for documentation.

@denar90 denar90 mentioned this pull request Feb 11, 2017
12 tasks
@@ -143,6 +147,10 @@ if (!cliFlags.outputPath && cliFlags['output-path']) {
cliFlags.outputPath = cliFlags['output-path'];
}

if (!cliFlags.maxWaitForLoad && cliFlags['max-wait-for-load']) {
Copy link
Member

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.

Copy link
Collaborator Author

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.

Copy link
Contributor

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 :(

Copy link
Collaborator Author

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?

Copy link
Contributor

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.

Copy link
Member

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

Copy link
Collaborator Author

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...

@@ -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',
Copy link
Contributor

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:...`

Copy link
Collaborator Author

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) ||
Copy link
Contributor

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?

Copy link
Collaborator Author

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
Copy link
Contributor

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

@paulirish paulirish merged commit 59bc945 into master Feb 16, 2017
@paulirish paulirish deleted the page_timeout branch February 16, 2017 00:07
@denar90
Copy link
Contributor

denar90 commented Feb 16, 2017

Thanks guys 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

WPT compat: configurable page timeout
5 participants