DNS polling for HTTP Keep-Alive of Node.js HTTP clients
- Support server-side traffic switch using weighted DNS routing
- Eliminate latency of making new connections (DNS query, TCP & TLS handshakes)
- Stay resilient to DNS query failures
To achieve good performance, we want to keep Keep-Alive connections as much as possible. On the over hand, DNS-based traffic switch doesn't allow us to keep connections forever because existing persistent connections can become stale when DNS records change.
This package polls DNS records and keep Keep-Alive connections using agentkeepalive as long as DNS records stay same. When DNS records change, it creates new connections with already retrieved IP addresses without making new DNS queries.
Even when DNS records change, existing connections are not immediately terminated. We can keep them for the next DNS record change (for example, DNS records can go back and forth with weighted DNS routing) with
freeSocketTimeout option of
npm install -S @shuhei/pollen# oryarn add @shuhei/pollen
const https = ;const DnsPolling HttpsAgent = ;const dnsPolling =interval: 30 * 1000 // 30 seconds by default;// Just a thin wrapper of// It accepts all the options of `agentkeepalive`.const agent = ;const hostname = 'shuheikagawa.com';const req = https;
- Only IPv4 is supported.
/etc/hosts, etc are not supported because this package internally uses
dns.resolve4(). See Node.js documentation for more details.