This is a created article in which the information may have evolved or changed.
Recently wrote a DNS cache server with go, which mainly implements two functions:
- DNS Caching
There is a cache invalidation mechanism that supports setting up the upper-level recursive server when the cache misses.
- Global hosts
Maintain the global hosts setting and unify the requirements for resolving domain names to specified IP.
In addition, dynamic update of the hosts record is supported without the need to restart the server process.
The reason for a re-build of a wheel
There are many open-source software that implements the DNS cache server and supports custom hosts, such as DNSMASQ, where we write one because the hosts record of DNSMASQ is written in a local file, and after a record is updated, the restart process takes effect. And we need to be able to co-maintain a global hosts record on different servers and take effect immediately after the hosts record is modified. The implementations we can find today, including Dnsmasq,pdnsd,djbdns, have not yet been able to meet our needs completely.
Reasons for using Go
The main reason to use go is to worry about the performance of Python, just recently saw a lot of go open source projects, so you want to go to try. It is proven that go is well suited for this type of server-side application development. Program performance is also good, we in 4 core 2.5G CPU, 46G memory of the server test, probably can handle more than 1.6W requests per second, this machine also ran some other applications, if tested on a clean machine, the data should be better. In addition, the overall development efficiency is not much slower than python, almost a week to complete the development of all features.
Currently, Godns has been deployed to our production systems.
At the same time put the code on GitHub: Https://github.com/kenshinx/godns, Welcome to the students who need to try, if there is any problem can be feedback on GitHub.