-
Notifications
You must be signed in to change notification settings - Fork 772
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
Allow devs to supply a dispatcher to the Node implementation of fetch
#2178
Allow devs to supply a dispatcher to the Node implementation of fetch
#2178
Conversation
👍 Dependency issues cleared. Learn more about Socket for GitHub ↗︎ This PR previously contained dependency changes with security issues that have been resolved, removed, or ignored. |
6ac84da
to
ef8b86c
Compare
3911705
to
c52409a
Compare
cachedDispatcher = new Agent({ | ||
// FIXME: https://github.com/nodejs/undici/issues/2808 | ||
// allowH2: true, | ||
connections: 16, | ||
// One second fewer than the Solana RPC's keepalive timeout. | ||
// Read more: https://github.com/solana-labs/solana/issues/27859#issuecomment-1340097889 | ||
keepAliveTimeout: 19000, | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I made the decision to deliver a default dispatcher to everyone. This is what the current web3.js does. I really hate this, because everyone's workload is different and requires tuning, but it's also true that having no dispatching strategy has pretty awful performance.
c52409a
to
baeabbe
Compare
ef8b86c
to
4cac623
Compare
3534b9b
to
80012ba
Compare
Is there no way to bring this Dispatcher API to the browser? |
There is not. The browser doesn't let you tune its networking stack. |
80012ba
to
f6cf535
Compare
// allowH2: true, | ||
// See https://github.com/solana-labs/solana-web3.js/pull/2179 for | ||
// strategies on how to tune the number of connections through benchmarking. | ||
connections: 32, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm starting to regret this in light of my latest benchmarks in #2179.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we're not creating a more performant Agent by providing these opinionated default values then that's good right? At least we don't need to be opinionated here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I think I might tear this default Agent
out until we have evidence that undici
with no dispatcher is insufficient. The getLatestBlockhash
benchmarks would indicate that it does a fine job of scheduling requests without one.
// allowH2: true, | ||
// See https://github.com/solana-labs/solana-web3.js/pull/2179 for | ||
// strategies on how to tune the number of connections through benchmarking. | ||
connections: 32, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we're not creating a more performant Agent by providing these opinionated default values then that's good right? At least we don't need to be opinionated here.
…ntation of `fetch`
f6cf535
to
281265a
Compare
fetch
fetch
Merge activity
|
🎉 This PR is included in version 1.90.1 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Because there has been no activity on this PR for 14 days since it was merged, it has been automatically locked. Please open a new issue if it requires a follow up. |
Summary
The current version of web3.js allows folks to supply what's called an ‘HTTP Agent.’ This is a class that mediates how network requests should be fetched. One example is to establish a connection pool for a given URL, and keep connections open for a time so that TLS/SSL negotiation doesn't have to be done on every request.
The new web3.js up until this point has punted on how to reintroduce this concept. In this PR we bring it back in the form of allowing callers to create transports with custom Undici
Dispatchers
.It only works in Node. If you supply the
dispatcher_NODE_ONLY
property in non-Node environments you'll get a console warning that your config has been ignored.Alternate designs considered
I desperately wanted to avoid the situation in this PR, which was to create a config property on transports that's only usable in Node.
Alternate approaches considered:
createDefaultNodeRpcTransport()
and/orsolanaRpcFactoryForNode()
which I thought was a bridge too far.ProxyAgent
) and you might unknowingly replace itDispatcher
setter that lets you install a dispatcher accessible only to@solana/fetch-impl
. Besides having most of the bad features of #2, this would not work. We inline@solana/fetch-impl
in the build, meaning there's no longer anywhere to export such a method from.Test Plan
See benchmark tests in next PR.
Closes #2126.