feat: Use Keep-Alive connection to connect to server
Description
Previously every API request to GitLab took extra time to set up a TLS connection with every request. To improve connection reuse, we need to:
-
Add a custom fetcher for graphql-request since GraphQL calls were not using the agent. This also has the side benefit of adding log messages that measure the latency of each GraphQL request.
-
Work around an issue identified in https://github.com/microsoft/vscode/issues/173861 where the
Connection: keep-alive
header does not appear to be sent, even if the agent'skeepAlive
option is enabled. We manually add this header to every request.
Note that this commit only fixes the case when http.proxySupport
is
set to off
. The default setting (override
) needs a special patch
for HTTP keepalives to work: !1265 (merged)
How has this been tested?
- In VSCode set
Settings
->Settings
-> enterhttp:proxysupport
. - Set to
off
. - Close down all your browsers to GitLab.com.
- Record all HTTPS traffic going to GitLab.com. If you are using macOS on WiFi, the interface will be
en0
:
sudo tcpdump -s 0 -w /tmp/gitlab.pcap host gitlab.com
Tip: you can check whether traffic is idle to gitlab.com by running sudo tcpdump -s 0 host gitlab.com
first and then hit CTRL-C to stop.
- Open VSCode and a GitLab.com project.
- As suggested by
@msmiley
, measure the number of TLS handshakes in the capture:
tshark -r /tmp/gitlab.pcap -Y 'tls.handshake.type == 1 && tls.handshake.extensions_server_name == "gitlab.com"' -T fields -e ip.dst -e tcp.srcport -e tls.handshake.extensions_server_name | sort | uniq -c | wc -l
This number should remain < 10 and not grow over time.
Screenshots (if appropriate):
Types of changes
-
Bug fix (non-breaking change which fixes an issue) -
New feature (non-breaking change which adds functionality) -
Breaking change (fix or feature that would cause existing functionality to change) -
Documentation -
Chore (Related to CI or Packaging to platforms) -
Test gap