DNSPod Open-Source Practice: A Deep Dive into the dnspod-sr Architecture

About dnspod-sr

dnspod-sr is a recursive DNS server software open-sourced on June 1, 2012, by DNSPod, China’s largest domain name resolution service provider. The latest update was on May 16, 2014, which fixed discovered bugs, rewrote some functional modules, and optimized partial resolution performance. Of course, our modifications to dnspod-sr are not yet complete; there will be significant changes ahead, and it will be continuously maintained.

Open Source License: BSD License

GitHub Address: https://github.com/DNSPod/dnspod-sr

dnspod-sr Performance Data

dnspod-sr Performance Test

As a high-performance recursive DNS server software running on the Linux platform, dnspod-sr boasts advantages of high performance, high load capacity, and easy scalability, significantly outperforming BIND and others. The image above shows the performance test comparison data between BIND and dnspod-sr.

Test Environment: Gigabit network card, 4-core CPU, 4G memory, Linux 64-bit system

Test Results:

Feature Introduction

  1. CNAME Resolution Acceleration: During the resolution process, dnspod-sr first loops through locally cached CNAME records. If a CNAME record is resolved, it then resolves the specified record type of the final CNAME record’s value. This can save the recursive resolution process when a CNAME exists in the request, greatly speeding up resolution. See the find_record_from_mem() interface in author.c for details.
  2. A Record Response Packet Caching: According to our resolution log statistics, over 90% of DNS resolution requests are for A records (i.e., IPv4 addresses). Therefore, dnspod-sr implements an optimization for this: if an authoritative server returns an A record, the software pre-assembles the response packet for this A record and stores it in the local cache. This eliminates the packet assembly process for subsequent client requests for the same record, accelerating resolution. However, this feature occasionally caused resolution errors in the previous version. It has been temporarily removed in the new version and will be re-added in the next version after the resolution error issue is fixed.
  3. Request Forwarding Function: By configuring the xfer: module in the sr.conf file, you can set up specific domain name resolution requests to be directly forwarded to designated resolution servers (which can be recursive or authoritative servers). See the pre_find() interface in dns.c for details.
  4. Cache Refresh Function: This function is mainly used to manually force refresh record values in the dnspod-sr local cache. It is primarily used for refreshing polluted records or when records with long TTLs have been updated and need to take effect quickly. It needs to be used in conjunction with the client tool under the tool directory.
  5. HASH Table Cache: dnspod-sr’s local caching method uses the popular HASH table approach. All data is cached in memory without any database operations. Additionally, the quizzer list also uses a HASH table method. See the relevant interfaces in storage.c for details.
  6. Memory Pool: The memory pool is a newly added feature in the new version, primarily aimed at reducing frequent memory allocation and release operations during the entire process of cache lookup and recursive resolution, thereby improving performance. See the relevant interfaces in memory.c for details.
  7. System Function Rewriting: Due to performance issues with system functions, some system functions have been self-implemented. For example, case conversion and domain name validity checks have been changed to use lookup table methods; string comparison and IP address conversion have also been re-implemented, etc.

Leave a Comment

Your email address will not be published.