coredns: coredns doesn't perform better despite having more cores
We are running CoreDNS 1.9.3 (retrieved from the official releases on GitHub), and have been having difficulty with increasing performance of a single instance of coredns.
With GOMAXPROCS set to 1, we observe ~60k qps and full utilization of one core.
With GOMAXPROCS set to 2, we seem to hit a performance limit of ~90-100k qps, but it consumes almost entirely two cores.
With GOMAXPROCS set to 4, we observe that coredns will use all 4 cores - but throughput does not increase, and latency seems to be the same.
With GOMAXPROCS set to 8-64, we observe the same CPU usage and throughput.
We have the following corefile:
.:55 {
file db.example.org example.org
cache 100
whoami
}
db.example.org
$ORIGIN example.org.
@ 3600 IN SOA sns.dns.icann.org. noc.dns.icann.org. 2017042745 7200 3600 1209600 3600
3600 IN NS a.iana-servers.net.
3600 IN NS b.iana-servers.net.
www IN A 127.0.0.1
IN AAAA ::1
We are using dnsperf: https://github.com/DNS-OARC/dnsperf
And the following command:
dnsperf -d test.txt -s 127.0.0.1 -p 55 -Q 10000000 -c 1 -l 10000000 -S .1 -t 8
test.txt:
www.example.com AAAA
Is there anything we could be missing?
Thanks!
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 2
- Comments: 31 (19 by maintainers)
yes @lobshunter that is correct. I think lwn article explain the improvements and few caveats (esp. with TCP) of using
SO_REUSEPORToption. Last week, I had validated the improvements by simply starting multiple servers on same port (as we’ve already set above option atListenPacketas seen here) after making following code changes:Essentially, I’ve just exposed an env var
NUM_SOCKrepresenting no. of socket (therebyservers) one wants to use for serving requests. For validating the improvements, I’ve used similar Corefile as mentioned at issue description above:1. With single listen socket, I’m able to achieve ~130K qps throughput from dnsperf on some private cloud instance.
2. With two listen socket, I’m able to achieve ~235K qps throughput from dnsperf.
3. With 4 listen socket, I’m able to achieve ~400K qps throughput from dnsperf.
So, I think bottleneck was indeed due to throughput limitation on single socket & we are able to scale throughput almost linearly as we increase no. of listen socket. I’ll create a pull request after validating the tcp traffic (non tls based) as I gets some more time. Thanks.
Based on your stacktrace, we have a lock for FD
poll.(*FD).writeLock. You have single socket file, single FD and lock works great for your case.But in my test I have a single socket file and multiple FD. And it looks like we doesn’t have any locks in that case between FD. It’s not clear how this approach will work from concurrency perspective.
By the way, we decided to use numsockets approach. Based on this test https://github.com/coredns/coredns/pull/6882#discussion_r1818522596 we decided that it works pretty good. With numsockets and SO_REUSEPORT we will have multiple sockets and single FD for each socket. Kernel will distribute load between these sockets and we doesn’t have any issues with concurrency in that case.
I ran into the same problem and checked the solution suggested by @iyashu.
Yes, it works, but there are a few problems.
Performance degrades after configuration reloading
I used a similar Corefile, but with
reload 3s.NUM_SOCK = 5 before reloading:
NUM_SOCK = 5 after reloading:
I changed
reload 3storeload 4s, so it shouldn’t have affected the result. But it affects.I compared full goroutine stack dumps before and after reloading and I didn’t find any differences. Yes, the goroutines have been restarted, but they are the same and their number is the same. There are still 5 goroutines running for UDP and 5 for TCP: goroutines-before-reload.txt goroutines-after-reload.txt
At the same time, with NUM_SOCK = 1, there is no such problem. The issue is reproducible only if we have multiple servers running on the same port. I also noticed that only the first reload affects performance. The second and next reloads do not affect the result.
Performance degrades with NUM_SOCK > 8
I also did tests with different NUM_SOCKS on environment with 96 CPU and got the following results:
The best result was achieved with NUM_SOCK = 8, then the QPS began to decrease. Yes, 232307 QPS is much better than the initial 29033, but it takes only 17 cores out of 96. Increasing the NUM_SOCK leads to a decrease in performance. This means that there is a bottleneck somewhere else.
I looked at the profiles with different NUM_SOCK, but did not see any obvious reasons why the performance is decreasing.
And the bottleneck is definitely not on my environment. I running 2 replicas of CoreDNS with NUM_SOCK = 8 on the same environment and I ran 2 dnsperf tests in parallel. I got 280k+280k QPS, despite the fact that one replica with NUM_SOCK = 8 gave 220k QPS. Which is actually surprising. Where did another 50k (280k-230k) come from? 😃
@iyashu any update here? this is pretty awesome
A memo: I found an interesting approach that uses
SO_REUSEPORTand multiplenet.ListenUDPcall. According to the author’s benchmark, it outperforms the solution of single listen, multiple ReadFromUDP.I shall give it a try when I got time.
In my understanding, https://github.com/golang/go/issues/45886 should improve the performance of UDP long connections(i.e. read a bunch of data from the same UDP socket, like QUIC). Would it help improve DNS workload? Since every DNS request-response belongs to different socket.
I could try to find a way. But I do agree with the idea of redis team:
scaling horizontally is paramount, and CoreDNS can scale horizontally pretty well. So it’s not a critical issue that it doesn’t scale vertically.PS: @Lobshunter86 is me, too.
Could be something like that.
Generally, if giving more CPU doesn’t fix it, it is because you are hitting other bottlenecks. The question is whether those are in the CoreDNS code (for example, some mutex contention or somethign), or in the underlying OS or hardware. In this case it looks like writing to the UDP socket. Look into tuning UDP performance on your kernel. You may want to look at your UDP write buffer sizes, for example.