paritytech / jsonrpc

Rust JSON-RPC implementation
MIT License
787 stars 274 forks source link

Implement the HTTP/2 protocol to increase the number of concurrent requests #673

Open steveluscher opened 2 years ago

steveluscher commented 2 years ago

Background

I work on a system that offers an API over JSON RPC using this library. A couple of folks were advocating for advanced batching in our client library. Turns out what they were trying to solve was fundamentally a performance problem. This is when I discovered that our RPC nodes are running in HTTP/1.1 mode.

Problem

Because the RPC operates in HTTP/1.1 mode it's unable to pipeline more than 6 requests at a time.

image

When you make more than 6 RPC requests in parallel, the browser produces this nightmare of a waterfall, where each request has to wait on a CORS preflight in batches of 6, and then resolve the data in batches of 6. This imposes a massive delay on getting your answer, and is making our apps many times slower and less responsive than they could be.

image

If you put a proxy in front of paritytech/jsonrpc that supports HTTP/3 it yields parallel request resolution like this.

image

Playground: https://codesandbox.io/s/sweet-surf-qu60i3?file=/src/index.js

Proposed Solution

linuskendall commented 2 years ago

Particularly relevant for CLI tools - browsers will follow whatever the proxy/frontend provides in terms of hints but on the CLI Node seems to always use HTTP/1.1 unless HTTP/2 is specifically implemented.