Commit 2086649
authored
refactor(http): inject same http handler into each sdk client. (#6690)
## Problem
From #6664, we have
persistent connections.
However, each SDK client creates its own http handler. If we have N
distinct service clients we maintain, then we could have up to N http
handlers, with N distinct connection pools. This does not affect
persistent connections since each service maintains its own endpoints,
however, there is a small overhead in initiating each connection pool.
Additionally, there is no guarantee for consistent behavior across
handlers with regards to configuration options (Ex. requestTimeout).
## Solution
- inject the same HTTP handler into each SDK client, unless explicitly
given a different one.
- use fetch-http-handler on web and `node-http-handler` on node.
- We don't want to use `fetch-http-handler` in node because it still has
experimental support and is not recommended.
[docs](https://github.com/aws/aws-sdk-js-v3/blob/main/supplemental-docs/CLIENTS.md#request-handler-requesthandler)
and
[comment](aws/aws-sdk-js-v3#4619 (comment))
from SDK team. When trying to, there were issues with persistent
connections.
- install `http2` to resolve web deps issue. This is part of nodes
standard library, but needed as explicit dependency for web.
### Trying `fetch-http-handler` in node.
- confirmed `fetch-http-handler` with `keep-alive: true` option is
sending `keepAlive` headers, but closing the connection after doing so
in node, both in VSCode environment, and outside of it in a pure node
environment. This implies it is not related to
microsoft/vscode#173861.
## Verification
The request times seemed unaffected by this change, but there was a
noticeable impact on sdk client initialization speed. The results below
are from creating 1000 SSM clients with and without the same HTTP
Handler.
<img width="304" alt="image"
src="https://github.com/user-attachments/assets/9b28af43-795c-4dcb-9bb1-752c118a3247"
/>
Because we usually cache the SDK clients under each service, the
important statistic is that this speeds up 0.131 ms per SDK client
creation. If we always use the cache and only create a client once per
service, then this also suggests a 0.131 ms per service speedup. We
interact with at least 20 services, and 16 in the explorer alone, so
this could result in 2-2.5 ms improvement in initialization time for all
these SDK clients depending on how they are created.
Could be interesting to revisit after the migration to see if this
reduces start-up time.
---
- Treat all work as PUBLIC. Private `feature/x` branches will not be
squash-merged at release time.
- Your code changes must meet the guidelines in
[CONTRIBUTING.md](https://github.com/aws/aws-toolkit-vscode/blob/master/CONTRIBUTING.md#guidelines).
- License: I confirm that my contribution is made under the terms of the
Apache 2.0 license.1 parent eaadd25 commit 2086649
4 files changed
+162
-1
lines changedSome generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
521 | 521 | | |
522 | 522 | | |
523 | 523 | | |
| 524 | + | |
| 525 | + | |
524 | 526 | | |
525 | 527 | | |
526 | 528 | | |
| |||
560 | 562 | | |
561 | 563 | | |
562 | 564 | | |
563 | | - | |
| 565 | + | |
| 566 | + | |
564 | 567 | | |
565 | 568 | | |
566 | 569 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
25 | 25 | | |
26 | 26 | | |
27 | 27 | | |
| 28 | + | |
28 | 29 | | |
29 | 30 | | |
30 | 31 | | |
| |||
33 | 34 | | |
34 | 35 | | |
35 | 36 | | |
| 37 | + | |
| 38 | + | |
36 | 39 | | |
37 | 40 | | |
38 | 41 | | |
| |||
88 | 91 | | |
89 | 92 | | |
90 | 93 | | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
91 | 108 | | |
92 | 109 | | |
93 | 110 | | |
| |||
129 | 146 | | |
130 | 147 | | |
131 | 148 | | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
132 | 153 | | |
133 | 154 | | |
134 | 155 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
32 | 32 | | |
33 | 33 | | |
34 | 34 | | |
| 35 | + | |
35 | 36 | | |
36 | 37 | | |
37 | 38 | | |
| |||
77 | 78 | | |
78 | 79 | | |
79 | 80 | | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
80 | 113 | | |
81 | 114 | | |
82 | 115 | | |
| |||
0 commit comments