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

Add HTTP transport with settings to support multiple connections #2685

Merged
merged 6 commits into from
Jan 24, 2023

Conversation

super-harsh
Copy link
Collaborator

Closes #2672

Special notes for your reviewer:

Did some manual testing around it to make 2500 successful calls using a single controller and multiple controllers. Before the change, we were running into SubscriptionRequestsThrottled error.

As confirmed by @matthchr, we can use go-armbalancer project to tackle this problem better by mid feb.

How does this PR make you feel:
gif

If applicable:

  • this PR contains documentation
  • this PR contains tests

Comment on lines 98 to 103
ForceAttemptHTTP2: false,
MaxIdleConns: 100,
MaxIdleConnsPerHost: 10,
IdleConnTimeout: 90 * time.Second,
TLSHandshakeTimeout: 10 * time.Second,
ExpectContinueTimeout: 1 * time.Second,
Copy link
Member

Choose a reason for hiding this comment

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

Suggest adding an end-of-line comment to each of these values explaining why these values were chosen.

}).DialContext,
ForceAttemptHTTP2: false, // default is true; since HTTP/2 multiplexes a single TCP connection. we'd want to use HTTP/1, which would use multiple TCP connections.
MaxIdleConns: 100, // default transport value
MaxIdleConnsPerHost: 10, // default is 2, so we want to increase the number to use establish more connections.
Copy link
Member

Choose a reason for hiding this comment

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

This is missing TLS min version, which the SDK has I think?

See https://github.com/Azure/azure-sdk-for-go/blob/main/sdk/azcore/runtime/transport_default_http_client.go#L18

	defaultTransport := &http.Transport{
		Proxy: http.ProxyFromEnvironment,
		DialContext: (&net.Dialer{
			Timeout:   30 * time.Second,
			KeepAlive: 30 * time.Second,
		}).DialContext,
		ForceAttemptHTTP2:     true,
		MaxIdleConns:          100,
		IdleConnTimeout:       90 * time.Second,
		TLSHandshakeTimeout:   10 * time.Second,
		ExpectContinueTimeout: 1 * time.Second,
		TLSClientConfig: &tls.Config{
			MinVersion: tls.VersionTLS12,
		},
	}

// to establish multiple TCP ARMClient connections to avoid throttling.
// TODO: Use https://github.com/Azure/go-armbalancer here once its prod ready.
httpTransport := &http.Transport{
Proxy: http.ProxyFromEnvironment,
Copy link
Member

Choose a reason for hiding this comment

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

Ahh one more thing -- we should have a single global one of these, not 1 per call to this function (that's how the SDK does it as well, see the transport_default_http_client link I gave below.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

So rather than having a httpClient per GenericClient, we want to share a default httpClient across all GenericClients?

Copy link
Member

Choose a reason for hiding this comment

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

Share the transport, the HTTPClient can be constructed 1 for each.

Copy link
Member

Choose a reason for hiding this comment

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

The reason for that is because the transport == connection pool == expensive to create. Golang has a single default transport and so does the Azure SDK, so we want to mirror that experience otherwise it would be easy to accidentally end up creating a lot more connections than we expected (because we constructed different GenericClient's)

@super-harsh super-harsh enabled auto-merge (squash) January 23, 2023 23:31
@super-harsh super-harsh merged commit 37a5fb6 into main Jan 24, 2023
@super-harsh super-harsh deleted the multi-httpconns branch January 24, 2023 00:17
@theunrepentantgeek theunrepentantgeek added this to the v2.0.0 beta.5 milestone Feb 23, 2023
@matthchr matthchr mentioned this pull request Oct 30, 2023
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.

Use multiple HTTP connections to ARM
3 participants