APIs to facilitate connection pools
- Dominant language
- Rust
- Stars
- 108k
- Forks
- 6.4k
- Avg merge
- 2d 20h
- Merged PRs (30d)
- 58
Description
I am unsure if [`Deno.connect`](https://doc.deno.land/deno/stable/~/Deno.connect) requires clients to implement connection pooling, because the current API surface that `Deno.Conn` exposes makes it tricky to implement one (though, [folks indeed have impl poolers atop it using `try..catch` semantics](https://github.com/denodrivers/postgres/blob/b68d3ebfd1a5805050f12e74ddaa4df3185bb86f/client.ts#L486)).
In comparing with NodeJS `net`, I believe equivalent of these two APIs are needed in [`Deno.Conn`](https://doc.deno.land/deno/stable/~/Deno.Conn) (TCP):
1. [`socket.readyState`](https://nodejs.org/api/net.html#socketreadystate) tells if conn is open or half-open.
2. [`socket.destroyed`](https://nodejs.org/api/net.html#socketdestroyed) tells if conn is open at all.
3. An adjustable [`socket.keepalive`](https://nodejs.org/api/net.html#socketsetkeepaliveenable-initialdelay).
([Here's how we use those APIs to determine health of a tcp-conn](https://github.com/serverless-dns/serverless-dns/blob/688c3110f6/src/core/dns/conns.js#L20-L22)).
NodeJS `net` also exposes [`socket.resume`](https://nodejs.org/api/net.html#socketresume) and [`socket.pause`](https://nodejs.org/api/net.html#socketpause), though those are not really required to build a pooler.
From NodeJS `dgram`, for _connected_ UDP sockets, [`Event.close`](https://nodejs.org/api/dgram.html#event-close) and `Event.error` come in handy to remove failed conns preemptively from the pool.
([Here's how we use those events to evict udp-conns from the pool](https://github.com/serverless-dns/serverless-dns/blob/688c3110f6/src/core/dns/conns.js#L152-L153)).
Of course, if Deno doesn't require client-code to pool (TCP/UDP) conns at all (like for HTTP), then that's even more awesome. [From this github discussion](https://github.com/tokio-rs/tokio/issues/1079), it is confirmed that `tokio` doesn't pool conns, but that [`tower`](https://github.com/tower-rs/tower) does... but I am not fluent in Rust to deduce anything from Deno's use of `tower`.
cc: @bartlomieju
Contributor guide
Research direction
Start with the Deno.Conn and Deno.connect documentation, then compare the requested TCP and connected-UDP behavior with NodeJS net and dgram. Review the referenced postgres client.ts and serverless-dns conns.js usage to understand the pooling needs; done requires an agreed API scope and corresponding runtime behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- node.js, rust
- Domain
- api, networking
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100