Meitu DNS Optimization Practice: LocalDNS vs HTTP DNS and Non-Intrusive SDK Implementation
Meitu improves mobile app performance by combining HTTP DNS for critical domains with fallback LocalDNS, employing lazy cache updates and a non‑intrusive SDK that injects custom resolution via Java reflection and native ELF redirection, resulting in roughly 100 ms latency reduction and fewer unknown‑host errors.
In the mobile internet era, App vendors face intense competition, and excellent user experience is crucial. Meitu, known for its visually appealing products, has invested significantly in technical optimization, with DNS optimization being a key component in client experience enhancement.
DNS service operates before network connection, translating domain names to IP addresses. During DNS queries, the system first checks local cache before making recursive queries to ISP DNS servers. This process can lead to issues like DNS hijacking and resolution delays, causing network requests to be hijacked or fail.
LocalDNS vs HTTP DNS:
LocalDNS has several problems: domain caching by ISPs directing users to internal cache servers, and DNS forwarding/NAT issues causing traffic scheduling failures. HTTP DNS solves these by having users send HTTP requests with the domain name and IP address directly to an HTTP web server, which returns the resolved IP.
HTTP DNS advantages include: eliminating DNS resolution anomalies by bypassing ISP DNS, precise traffic routing by directly obtaining user IPs, and strong extensibility based on HTTP protocol.
Meitu's DNS Optimization Strategy:
Meitu designed flexible strategy control for different product scenarios. They don't completely abandon LocalDNS - core API domains use HTTP DNS while non-core requests try LocalDNS first and upgrade to HTTP DNS only when anomalies are detected.
Quality indicators for DNS servers include: IP record TTL time (abnormally high TTL may indicate hijacking), resolution latency, and connectivity of returned IPs.
For cache optimization, Meitu implements lazy update strategy - when finding expired cache records, return the expired record to users while asynchronously initiating DNS queries to update the cache. This ensures cache hit on second resolution, greatly reducing DNS resolution time.
Non-Intrusive SDK Implementation:
The biggest challenge was integrating the DNS SDK into actual App products. The industry commonly uses IP direct connection, which requires manual Host header configuration for HTTP and complex SSL/TLS handling for HTTPS, including domain verification and SNI (Server Name Indication) scenarios.
Meitu explored a non-intrusive approach:
For Java layer: By analyzing InetAddress's workflow, they found it uses a static AddressCache map. They created a custom AddressCache that retrieves resolution records from their SDK, then used reflection to replace the system's AddressCache. This allows HttpUrlConnection to use their DNS resolution without URL modifications.
For Native layer: WebView and media players perform DNS resolution in native layer using getaddrinfo/gethostbyname2. They modified the ELF .rel.plt table to redirect getaddrinfo calls to their custom function, achieving DNS interception at the native level.
Results:
After deployment, DNS resolution latency was reduced, and complete network request latency improved by approximately 100ms. Network request success rate improved with decreased "unknown host" errors.
Meitu Technology
Curating Meitu's technical expertise, valuable case studies, and innovation insights. We deliver quality technical content to foster knowledge sharing between Meitu's tech team and outstanding developers worldwide.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.