I want to benchmark my DNS query speed on my machine and make it available in the browser as an application. Let's discuss the possibilities.

DNS Protocols:

My friends, there are currently three popular DNS connection protocols that you may be using:

🤔 I know, there is also the QUIC protocol, but it is still in the proposal state and not supported by many OS/devices.

DNS over UDP is the most widely used traditional protocol, while DoH and DoT are newly proposed protocols that provide greater security and privacy.

Now, let's discuss the idea of building a built-in DNS benchmark browser. It is currently not possible, at least for DNS over UDP, which is the most commonly used protocol.

The Problems:

The challenge of building an in-browser built-in DNS benchmark is the absence of a UDP/TCP layer stack. This means that the DNS layer is non-existent. To benchmark DNS performance, we need to make DNS calls from the actual machine itself.

However, by using a backend framework like Node.js to perform DNS queries, we can set the DNS server. For instance:

import dns from 'dns' // or node:dns

dns.setServers([your_dns_servers])
// let's resolve a domain
dns.promises.resolvev4(<hostname>, <options>).then(res => console.log(res))

The code above requires c-ares. It utilizes the grpc library and parses /etc/resolv.conf and /etc/nsswitch.conf to determine sources to consult. This code only exists in POSIX systems. Therefore, the benchmark must be deployed on a cloud instance.

How about dnsperf.com?

dnsperf.com is a third-party website that collects data on DNS query speed by running measurements on its own servers. Users can access the results via the website. This approach is useful for obtaining a broad view of DNS performance across different regions and network conditions. However, it does not provide information on the performance of a specific machine or client.

A trial solution:

Alternatively, there is an idea to use WebContainers. However, an error is thrown since even the latest innovation of browser-based runtime doesn't support the DNS layer inside.

You can check out a preview proof-of-concept (PoC) at https://jplxx2-5173.csb.app/. The source code is available at https://codesandbox.io/p/sandbox/dns-bench-webcontainers-jplxx2?file=%2Fsrc%2FApp.tsx%3A1%2C1. Due to cross-origin problems, the CodeSandbox preview may not work. Simply open the preview in a new tab to make it work.