Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce bun.dns.prefetch API #11176

Merged
merged 20 commits into from
May 20, 2024
Merged

Introduce bun.dns.prefetch API #11176

merged 20 commits into from
May 20, 2024

Conversation

Jarred-Sumner
Copy link
Collaborator

What does this PR do?

This adds the bun.dns.prefetch API.

import {dns} from "bun";

dns.prefetch("bun.sh", 443);
//
// ... sometime later ...
await fetch("https://bun.sh");

Like <link rel="dns-prefetch"> in browsers, the intended usecase is to amortize the cost of DNS lookups you know you'll make soon.

This also sets the DNS cache to have a TTL of 30 seconds. For reference, the Java Virtual Machine has no TTL set and AWS recommends 5 seconds.

This also introduces a dns.getCacheStats() API which exposes information about the DNS cache.

This also adds documentation.

This also makes bun install prefetch the DNS query.

How did you verify your code works?

There is a test

@Jarred-Sumner Jarred-Sumner changed the title Introduce bun.dns.prefetch API Introduce bun.dns.prefetch API May 19, 2024
Copy link

github-actions bot commented May 19, 2024

@Jarred-Sumner, your commit has failing tests :(

💪 1 failing tests Darwin AARCH64

💻 1 failing tests Darwin x64 baseline

💻 2 failing tests Darwin x64

🐧🖥 2 failing tests Linux x64 baseline

🐧🖥 1 failing tests Linux x64

🪟💻 8 failing tests Windows x64 baseline

🪟💻 9 failing tests Windows x64

View logs

src/bun.js/api/bun/dns_resolver.zig Outdated Show resolved Hide resolved
src/bun.js/api/bun/dns_resolver.zig Outdated Show resolved Hide resolved
docs/api/dns.md Outdated Show resolved Hide resolved
Comment on lines +76 to +78
cacheHitsCompleted: number;
cacheHitsInflight: number;
cacheMisses: number;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would be useful to see these values per hostname as well to see where lookup activity is concentrated. could generate some useful graphs from this too.

Jarred-Sumner and others added 6 commits May 19, 2024 16:37
@Jarred-Sumner Jarred-Sumner merged commit b15d47d into main May 20, 2024
1 check passed
@Jarred-Sumner Jarred-Sumner deleted the jarred/dns-prefetch branch May 20, 2024 01:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants