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

ConfigureTransport: enable compression for non unix/npipe protos #106

Merged
merged 1 commit into from
Oct 31, 2023

Conversation

akerouanton
Copy link
Member

@akerouanton akerouanton commented Oct 31, 2023

ConfigureTransport is used by the official Docker client to set up its http.Transport:

  • NewClientWithOpts() starts by calling defaultHTTPClient() which creates a new http.Transport and call ConfigureTransport with either the default unix socket address, or the default npipe socket address (see here). This first call to ConfigureTransport will set DisableCompression to false.
  • Then, when WithHost() is called, ConfigureTransport is called once again with the same http.Transport instance. If that hostURL uses tcp proto, we fall in ConfigureTransport's default switch case, which doesn't reset DisableCompression. This effectively means that the Docker client has (presumably) never been using HTTP compression for TCP hosts.

Note that WithHost is called whenever the WithHostFromEnv or FromEnv option funcs are used.

We think it does make sense to keep compression disabled for unix / npipe sockets (it would just make the CPU needlessly spin more if we enable it), and we think it generally also makes sense to enable it for HTTP over TCP.

We discussed creating a new http.Transport in Docker client codebase whenever ConfigureTransport is called, but we can't do that without introducing major side-effects (see here). So we still have to leave in a world where multiple calls to ConfigureTransport might be made for the same http.Transport.

As such, this commit make sure compression is enabled for non unix / npipe protos.

If ConfigureTransport callers really want to make sure compression is disabled, they should set DisableCompression only after all subsequent calls to ConfigureTransport have been made. The comment on that function has also been updated to reflect that.

For the record, DisableCompression = true was first introduced in this repo by 88d5fb2, which can be tracked down to this initial change in moby/moby: moby/moby@fb7ceeb

`ConfigureTransport` is used by the official Docker client to set up its
`http.Transport`:

* [`NewClientWithOpts()`][1] starts by calling `defaultHTTPClient()`
  which creates a new `http.Transport` and call `ConfigureTransport`
  with either the default unix socket address, or the default npipe
  socket address (see [here][2]). This first call to
  `ConfigureTransport` will set `DisableCompression` to false.
* Then, when [`WithHost()`][3] is called, `ConfigureTransport` is called
  once again with the same `http.Transport` instance. If that hostURL
  uses tcp proto, we fall in `ConfigureTransport`'s default switch case,
  which doesn't reset `DisableCompression`. This effectively means that
  **the Docker client has (presumably) never been using HTTP compression
  for TCP hosts.**

Note that `WithHost` is called whenever the `WithHostFromEnv` or
`FromEnv` option funcs are used.

We think it _does_ make sense to keep compression disabled for unix /
npipe sockets (it would just make the CPU needlessly spin more if we
enable it), and we think it generally also makes sense to enable it for
HTTP over TCP.

We discussed creating a new `http.Transport` in Docker client codebase
whenever `ConfigureTransport` is called, but we can't do that without
introducing major side-effects (see [here][4]). So we still have to
leave in a world where multiple calls to `ConfigureTransport` might be
made for the same `http.Transport`.

As such, this commit make sure compression is enabled for non unix /
npipe protos.

If `ConfigureTransport` callers really want to make sure compression is
disabled, they should set `DisableCompression` _only after_ all
subsequent calls to `ConfigureTransport` have been made. The comment on
that function has also been updated to reflect that.

For the record, `DisableCompression = true` was first introduced in
this repo by 88d5fb2, which can be tracked down to this initial change
in moby/moby: moby/moby@fb7ceeb

[1]: https://github.com/moby/moby/blob/e9efc0a361de39903d47fe12f628c92fc095397b/client/client.go#L181-L197
[2]: https://github.com/moby/moby/blob/e9efc0a361de39903d47fe12f628c92fc095397b/client/client.go#L237-L238
[3]: https://github.com/moby/moby/blob/e9efc0a361de39903d47fe12f628c92fc095397b/client/options.go#L71-L73
[4]: docker#103 (comment)

Signed-off-by: Albin Kerouanton <[email protected]>
@akerouanton akerouanton force-pushed the fix-DisableCompression branch from e6e0adf to 2573a15 Compare October 31, 2023 17:35
Copy link
Member

@rumpl rumpl left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Member

@thaJeztah thaJeztah left a comment

Choose a reason for hiding this comment

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

LGTM

@thaJeztah thaJeztah merged commit 0b8c1f4 into docker:master Oct 31, 2023
13 checks passed
@akerouanton akerouanton deleted the fix-DisableCompression branch October 31, 2023 18:58
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.

3 participants