all: improving DoH query performance

Previously, for each DoH query, we use the net/http default transport
with DialContext function re-assigned. This has some problems:

 - The first query to server will be slow.
 - Using the default transport for all upstreams can have race condition
   in case of multiple queries to multiple DoH upstreams

This commit fixes those issues, by initializing a separate transport for
each DoH upstream, the warming up the transport by doing a test query.
Later queries can take the advantage and re-use the connection.
This commit is contained in:
Cuong Manh Le
2022-12-17 23:03:48 +07:00
committed by Cuong Manh Le
parent 924304a13d
commit ebcc545547
3 changed files with 54 additions and 22 deletions

View File

@@ -48,7 +48,6 @@ func (p *prog) run() {
for n := range p.cfg.Upstream {
uc := p.cfg.Upstream[n]
uc.Init()
if uc.BootstrapIP == "" {
// resolve it manually and set the bootstrap ip
c := new(dns.Client)
@@ -71,6 +70,7 @@ func (p *prog) run() {
}
}
}
uc.SetupTransport()
}
for listenerNum := range p.cfg.Listener {