Replace constant stat polling with server-sent events
- Dominant language
- JavaScript
- Stars
- 1.6k
- Forks
- 534
- PR merge metrics
- No merged PRs in 30d
Description
At the moment webui is constantly polling following HTTP API endpoints:
- [/api/v0/stats/bw](https://docs.ipfs.io/reference/http/api/#api-v0-bitswap-stat)
- [/api/v0/swarm/peers](https://docs.ipfs.io/reference/http/api/#api-v0-swarm-peers)
- [/api/v0/repo/stat](https://docs.ipfs.io/reference/http/api/#api-v0-repo-stat)
- [/api/v0/config/show](https://docs.ipfs.io/reference/http/api/#api-v0-config-show)
This is has few unfortunate consequences:
1. Increases pressure on network IO limits that browsers have.
2. Inceases overhead on the HTTP API of IPFS node (draining battery).
3. Harms dev experience due to noise in the network panel.
**Describe the solution you'd like**
[`EventSource`](https://developer.mozilla.org/en-US/docs/Web/API/EventSource) is a standard web API that provides interface to [server-sent-events](https://html.spec.whatwg.org/multipage/server-sent-events.html) as replacement for ong-polling pattern (that browsers can optimize to discard consumed input).
**Describe alternatives you've considered**
Alternatively we could use fetch `body` to read updates from [`ReadableStream`](https://developer.mozilla.org/en-US/docs/Web/API/ReadableStream), but that is less widely supported than `EventSource` API. Also unlike `EventSource` that is push based, `ReadableStream`s are push & pull which could lead to buffering on the client if not actively consumed, which would not be the case with `EventSource`.
**Additional context**
I am realizing this conversation reaches beyond webui into IPFS HTTP API, but I'm going to fill relevant issues there as well and interlink those.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.