Created
March 19, 2023 06:07
-
-
Save myesn/4ae5f9fa831722f64a25d46b611bdd88 to your computer and use it in GitHub Desktop.
指定 dns 服务器,测试该 dns 服务器的 A 记录每秒解析速率
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const { Resolver } = require('node:dns').promises; | |
const { performance } = require('perf_hooks'); | |
const domain = 'giao.com'; | |
const resolver = new Resolver(); | |
resolver.setServers(['192.168.31.117']); | |
async function main() { | |
const numIterations = 1; | |
const taskOfInteration = 2000; | |
let totalTime = 0; | |
// for (let index = 0; index < numIterations; index++) { | |
const tasks = []; | |
Array(taskOfInteration) | |
.fill(undefined) | |
.forEach((x) => tasks.push(resolveDnsARecord(domain))); | |
const t0 = performance.now(); | |
await Promise.all(tasks); | |
const t1 = performance.now(); | |
totalTime += t1 - t0; | |
// } | |
const averageTime = totalTime / (numIterations * taskOfInteration); | |
const executionsPerSecond = 1000 / averageTime; | |
console.log('executionsPerSecond = ', executionsPerSecond); | |
} | |
function resolveDnsARecord(domain) { | |
return resolver.resolve4(domain, { ttl: 0 }); | |
} | |
main() | |
//setInterval(main, 3000); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment