Skip to content

Conversation

@sg70
Copy link

@sg70 sg70 commented Sep 8, 2025

  • All tests passed. If this feature is not already covered by the tests, I added new tests.
  • All static analysis checks passed.
  • This pull request is on the dev branch.
  • I used gofmt for formatting the code before submitting the pull request.

Closes jfrog/jfrog-cli-artifactory#290

What does this MR do?

This MR enables the underlying http.client to reuse HTTP connections.

Why was this MR needed?

The relevant part of the HTTP client implementation has remained unchanged since 2017. It is unclear why req.Close was set to true, which forces the Go http.Client to close the connection immediately after the response is received. Reusing established HTTP(S) connections is a common best practice and can significantly improve performance.

The function createDefaultHttpTransport in http/httpclient/clientBuilder.go uses the same defaults as the original DefaultTransport implementation in the net/http package. Since ForceAttemptHTTP2 was added as a default in the net/http package after 2017, I added this option as well.

After performance testing, I set the parameter MaxIdleConnsPerHost to 6, aligning with modern web browsers’ common default and providing a balanced improvement in connection reuse, especially when HTTP/2 is not used. The previous default of 2 resulted in a high number of short-lived TCP connections under multi-threaded workloads.

Performance test case

Download a directory from Artifactory with 4591 files ranging from 100 Bytes to 21 MByte (total size 892.13 MByte) with a max connection throughput of 350 Mbit/s. Tests were conducted on the internet where the Artifactory server is hosted at AWS behind an AWS ALB. Client and AWS region are in the same country. The jfrog-cli was used with its default configuration. All test were executed multiple times.

current jfrog-cli release (2.78.10)
Download as directory using jfrog-cli with options --include-dirs --quiet --threads 3: 221 secs
Download as directory using jfrog-cli with options --include-dirs --quiet --threads 10 : 97 secs
Download as directory using jfrog-cli with options --include-dirs --quiet --threads 20 : 69 secs

with the change of the PR applied:
Download as directory using jfrog-cli with options --include-dirs --quiet --threads 3: 124 secs
Download as directory using jfrog-cli with options --include-dirs --quiet --threads 10 : 64 secs
Download as directory using jfrog-cli with options --include-dirs --quiet --threads 20 : 46 secs

During the test runs with the change of the PR applied, the number of TCP connections was stable, and TCP connections got reused. Furthermore the total amount of open TCP connections when using HTTP2 was not more than 4 connections.

Potential Drawbacks

While reusing connections generally improves performance, it's important to note that the Go http.Client has set a IdleConnTimeout of 90 seconds. This means that idle connections will be closed after 90 seconds of inactivity, preventing them from becoming stale indefinitely. Therefore, the risk of long-lived connections causing issues is mitigated by this timeout. The benefits of connection reuse are expected to outweigh any potential drawbacks in most common scenarios.

@github-actions
Copy link
Contributor

github-actions bot commented Sep 8, 2025

All contributors have signed the CLA ✍️ ✅
Posted by the CLA Assistant Lite bot.

@sg70 sg70 changed the title Improve http connection handling Improve HTTP connection handling Sep 8, 2025
@sg70 sg70 force-pushed the improve-http-connection-handling branch from e72b560 to 1d32ab7 Compare September 8, 2025 09:14
@sg70
Copy link
Author

sg70 commented Sep 8, 2025

I have read the CLA Document and I hereby sign the CLA.

@sg70 sg70 force-pushed the improve-http-connection-handling branch from 1d32ab7 to e0d2202 Compare September 11, 2025 15:43
@sg70
Copy link
Author

sg70 commented Sep 12, 2025

@ehl-jf can have a look on this PR?

@sg70 sg70 changed the base branch from dev-deprecated-please-target-master-directly to master September 12, 2025 08:21
@sg70 sg70 force-pushed the improve-http-connection-handling branch 2 times, most recently from 69baf32 to 08a05ea Compare September 15, 2025 15:19
@sg70 sg70 force-pushed the improve-http-connection-handling branch from 08a05ea to 578ebc0 Compare September 17, 2025 14:04
@sg70 sg70 force-pushed the improve-http-connection-handling branch from 578ebc0 to 57d08c2 Compare September 18, 2025 09:53
@sg70 sg70 force-pushed the improve-http-connection-handling branch from 57d08c2 to 713cf5e Compare September 25, 2025 16:14
@ehl-jf ehl-jf added the safe to test Approve running integration tests on a pull request label Sep 25, 2025
@github-actions github-actions bot removed the safe to test Approve running integration tests on a pull request label Sep 25, 2025
@sg70 sg70 force-pushed the improve-http-connection-handling branch from 713cf5e to a21cd9e Compare November 5, 2025 18:13
@ehl-jf ehl-jf added the safe to test Approve running integration tests on a pull request label Nov 5, 2025
@github-actions github-actions bot removed the safe to test Approve running integration tests on a pull request label Nov 5, 2025
@sg70 sg70 force-pushed the improve-http-connection-handling branch from a21cd9e to 7db32a0 Compare November 5, 2025 20:31
@ehl-jf ehl-jf added the safe to test Approve running integration tests on a pull request label Nov 5, 2025
@github-actions github-actions bot removed the safe to test Approve running integration tests on a pull request label Nov 5, 2025
- stop closing TCP connections after each HTTP request
- add ForceAttemptHTTP2: true as parameter for http.Transport
- increase MaxIdleConnsPerHost to 6
@sg70 sg70 force-pushed the improve-http-connection-handling branch from 7db32a0 to aaebde5 Compare November 6, 2025 09:27
@ehl-jf ehl-jf added the safe to test Approve running integration tests on a pull request label Nov 6, 2025
@github-actions github-actions bot removed the safe to test Approve running integration tests on a pull request label Nov 6, 2025
@github-actions
Copy link
Contributor

github-actions bot commented Nov 6, 2025

👍 Frogbot scanned this pull request and did not find any new security issues.


@bhanurp bhanurp added the safe to test Approve running integration tests on a pull request label Nov 13, 2025
@github-actions github-actions bot removed the safe to test Approve running integration tests on a pull request label Nov 13, 2025
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.

Download performance of a directory with a large number of files (small to medium) is slow

3 participants