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

It takes a long time to make the first request #38

Closed
kaatt opened this issue Apr 21, 2020 · 22 comments
Closed

It takes a long time to make the first request #38

kaatt opened this issue Apr 21, 2020 · 22 comments

Comments

@kaatt
Copy link

kaatt commented Apr 21, 2020

With got v11:

> console.time('done');got('https://facebook.com').then(x => console.timeEnd('done'))
Promise { <pending> }
> done: 302.025ms
> console.time('done');got('https://facebook.com', { http2: true }).then(x => console.timeEnd('done'))
Promise { <pending> }
> done: 60188.968ms

> console.time('done');got('https://twitter.com').then(x => console.timeEnd('done'))
Promise { <pending> }
> done: 2343.526ms

> console.time('done');got('https://twitter.com', { http2: true }).then(x => console.timeEnd('done'))
Promise { <pending> }
> done: 5333.237ms

> console.time('done');got('https://google.com').then(x => console.timeEnd('done'))
Promise { <pending> }
> done: 983.180ms
> console.time('done');got('https://google.com', { http2: true }).then(x => console.timeEnd('done'))
Promise { <pending> }
> done: 1520.592ms

Not sure what's causing it. Pages are speedy when I load them in Chrome.

@szmarczak
Copy link
Owner

Try

got('https://google.com', { http2: true }).then(x => {
    console.time('done');got('https://google.com', { http2: true }).then(x => console.timeEnd('done'))
})

When you make a first HTTP2 request, it may use additional time to set up the HTTP2 session. Further requests should be faster.

@szmarczak szmarczak changed the title Significantly slower than HTTP/1 It takes a long time to make the first request Apr 21, 2020
@kaatt
Copy link
Author

kaatt commented Apr 21, 2020

Is there any fix for this? Facebook.com takes 60s for the first request.

got('https://facebook.com', { http2: true }).then(x => {
    console.time('done');got('https://facebook.com', { http2: true }).then(x => console.timeEnd('done'))
})

@szmarczak
Copy link
Owner

I'm working on it right now

@szmarczak szmarczak added the bug Something isn't working label Apr 21, 2020
@szmarczak
Copy link
Owner

Indeed. Fixed a few bugs, and for google.com (150ms compared to 360ms) it is >2x faster than HTTP1. But for facebook.com it waits always 60s for some reason.

@szmarczak
Copy link
Owner

Sometimes it gives the proper result, sometimes it waits 60s...

@szmarczak
Copy link
Owner

Nope.

	http2wrapper.request('https://facebook.com', () => {
		console.log('got response');
	}).end();

this works as expected... but it doesn't work with Got for some reason...

@szmarczak
Copy link
Owner

It has to do something with redirects or HTTP2 origins. If you add followRedirect: false it works as expected.

@szmarczak
Copy link
Owner

No. If you query https://www.facebook.com and disable redirects it also hangs.

@szmarczak
Copy link
Owner

szmarczak commented Apr 21, 2020

Hmmm.

http2wrapper.request('https://www.facebook.com', () => {
	console.log('got response');
}).end();

works as expected so I suspect it's a bug in Got.

Edit:

request('https://www.facebook.com', response => {
	response.resume();
	response.once('end', () => {
		console.log('got end');
	});
}).end();

shows it's a bug in Got. But I'm still not sure.

@szmarczak
Copy link
Owner

szmarczak commented Apr 21, 2020

maybe

@szmarczak
Copy link
Owner

http2: true, decompress: false works as expected but if you set decompress to true it hangs

@szmarczak
Copy link
Owner

Testing on http2-wrapper@master

@kaatt
Copy link
Author

kaatt commented Apr 21, 2020

you can maybe try other popular sites and see if the same issue is happening with any of them. might help in filtering out the issue with compression

@szmarczak
Copy link
Owner

request('https://www.facebook.com', {
	headers: {
		'user-agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.70 Safari/537.36',
		'accept-encoding': 'gzip, deflate, br'
	}
}, response => {
	response.resume();
	response.on('data', chunk => {
		console.log(chunk.toString().length);
	});
	response.once('end', () => {
		console.log('got end');
	});
}).end();

It's a http2-wrapper bug 10000%

@szmarczak
Copy link
Owner

Either it's a bug in Node.js, nghttp2 (the underlying HTTP2 implementation) or in Facebook itself:

const {connect} = require('http2');
const session = connect('https://www.facebook.com');
session.once('remoteSettings', () => {
	console.log('got settings');
	session.request({
		'user-agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.70 Safari/537.36',
		'accept-encoding': 'gzip, deflate, br'
	}).once('response', () => {
		console.log('got headers');
	}).on('data', chunk => {
		console.log(chunk.toString().length);
	}).on('end', () => {
		console.log('got end');
	}).resume();
});

@szmarczak
Copy link
Owner

It's a bug in Facebook, if you remove , br from accept-encoding you receive the end event.

@szmarczak szmarczak added invalid This doesn't seem right and removed bug Something isn't working invalid This doesn't seem right labels Apr 21, 2020
@szmarczak
Copy link
Owner

It may be also a bug in Node.js, I need to check that.

@kaatt
Copy link
Author

kaatt commented Apr 21, 2020

could this be an issue in proxygen? https://engineering.fb.com/production-engineering/introducing-proxygen-facebook-s-c-http-framework/

i see chrome's only sending "br" for "accept-encoding" chrome's sending accept-encoding: gzip, deflate, br for "accept-encoding"

@szmarczak
Copy link
Owner

that's what I'm sending too

@szmarczak
Copy link
Owner

It's a Node.js bug, curl --http2 -H 'accept-encoding: gzip, deflate, br' https://www.facebook.com>/dev/null works as expected.

@szmarczak
Copy link
Owner

Please see the issue above. I'll release a new beta right now.

@szmarczak
Copy link
Owner

Released 1.0.0-beta.4.4

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

No branches or pull requests

2 participants