Performance optimization for services having more than 2k records

This commit is contained in:
Pierre Souchay 2018-03-08 00:26:41 +01:00
parent 1085d5a7b4
commit c3713dbbf1
1 changed files with 9 additions and 3 deletions

View File

@ -726,12 +726,19 @@ func (d *DNSServer) trimTCPResponse(req, resp *dns.Msg) (trimmed bool) {
// We avoid some function calls and allocations by only handling the // We avoid some function calls and allocations by only handling the
// extra data when necessary. // extra data when necessary.
var index map[string]dns.RR var index map[string]dns.RR
originalSize := resp.Len()
originalNumRecords := len(resp.Answer)
// Beyond 2500 records, performance gets bad
// Limit the number of records at once, anyway, it won't fit in 64k
// For SRV Records, the max is around 500 records, for A, less than 2k
if len(resp.Answer) > 2048 {
resp.Answer = resp.Answer[:2048]
}
if hasExtra { if hasExtra {
index = make(map[string]dns.RR, len(resp.Extra)) index = make(map[string]dns.RR, len(resp.Extra))
indexRRs(resp.Extra, index) indexRRs(resp.Extra, index)
} }
originalSize := resp.Len()
originalNumRecords := len(resp.Answer)
truncated := false truncated := false
// This enforces the given limit on 64k, the max limit for DNS messages // This enforces the given limit on 64k, the max limit for DNS messages
@ -746,7 +753,6 @@ func (d *DNSServer) trimTCPResponse(req, resp *dns.Msg) (trimmed bool) {
d.logger.Printf("[DEBUG] dns: TCP answer to %v too large truncated recs:=%d/%d, size:=%d/%d", d.logger.Printf("[DEBUG] dns: TCP answer to %v too large truncated recs:=%d/%d, size:=%d/%d",
req.Question, req.Question,
len(resp.Answer), originalNumRecords, resp.Len(), originalSize) len(resp.Answer), originalNumRecords, resp.Len(), originalSize)
} }
// Restore compression if any // Restore compression if any
resp.Compress = compressed resp.Compress = compressed