From 93fa1f6f492914dac9739ded1fdf0f39bfb16d53 Mon Sep 17 00:00:00 2001
From: Pierre Souchay
Date: Fri, 9 Mar 2018 18:25:29 +0100
Subject: [PATCH] Optimize size for SRV records, should improve performance a
bit
Stricter Unit tests that checks if truncation was OK.
---
agent/dns.go | 8 ++++++--
agent/dns_test.go | 6 +++---
2 files changed, 9 insertions(+), 5 deletions(-)
diff --git a/agent/dns.go b/agent/dns.go
index 73d6a30a00..2b1845b549 100644
--- a/agent/dns.go
+++ b/agent/dns.go
@@ -732,8 +732,12 @@ func (d *DNSServer) trimTCPResponse(req, resp *dns.Msg) (trimmed bool) {
// 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]
+ truncateAt := 2048
+ if req.Question[0].Qtype == dns.TypeSRV {
+ truncateAt = 640
+ }
+ if len(resp.Answer) > truncateAt {
+ resp.Answer = resp.Answer[:truncateAt]
}
if hasExtra {
index = make(map[string]dns.RR, len(resp.Extra))
diff --git a/agent/dns_test.go b/agent/dns_test.go
index 06216759d2..8de2396988 100644
--- a/agent/dns_test.go
+++ b/agent/dns_test.go
@@ -2818,9 +2818,9 @@ func TestDNS_TCP_and_UDP_Truncate(t *testing.T) {
// Check for the truncate bit
shouldBeTruncated := numServices > 4095
- if shouldBeTruncated != in.Truncated {
- info := fmt.Sprintf("service %s question:=%s (%s) (%d total records) in %v",
- service, question, protocol, numServices, out)
+ if shouldBeTruncated != in.Truncated || len(in.Answer) > 2000 || len(in.Answer) < 1 || in.Len() > 65535 {
+ info := fmt.Sprintf("service %s question:=%s (%s) (%d total records) sz:= %d in %v",
+ service, question, protocol, numServices, len(in.Answer), out)
t.Fatalf("Should have truncate:=%v for %s", shouldBeTruncated, info)
}
})