forked from cfadmin-cn/cfadmin
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_dns.lua
More file actions
71 lines (63 loc) · 1.85 KB
/
test_dns.lua
File metadata and controls
71 lines (63 loc) · 1.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
local LOG = require "logging"
local dns = require "protocol.dns"
local dns_resolve = dns.resolve
local cf = require "cf"
local fork = cf.fork
local wait = cf.wait
local system = require "system"
local now = system.now
local fmt = string.format
local find = string.find
local match = string.match
local pairs = pairs
-- 去除ipv4->ipv6映射前缀
local function delete_ipv4_prefix (ip)
if system.is_ipv4(ip) then
return ip
end
return find(ip or "", '::ffff') and match(ip, "::[fF]+:([%d%.]+)") or ip
end
local domains = {
["百度"] = "www.baidu.com",
["腾讯"] = "www.qq.com",
["淘宝"] = "www.taobao.com",
["谷歌"] = "www.google.com",
["网易"] = "www.163.com",
["京东"] = "www.jd.com",
["唯品会"] = "www.vip.com",
["盛大"] = "www.sdo.com",
["测试"] = "pwaj.dwauidwa.raw"
}
--[[
计算方式
(min - max + 1) * 1 为单个域名查询总次数
(min - max + 1) * #domain 为所有域名查询总次数
]]
local min, max = 1, 1
--[[
测试方式: 每隔3秒后为每个域名建立1万个协程进行并发查询测试;
空间消耗: 内存消耗预计在250MB左右;
时间消耗: 每次网络查询应该在0.1/Sec左右, 每次缓存查询应该在0.001/Sec左右;
]]
cf.at(3, function ( )
for company, domain in pairs(domains) do
local start = now()
local total = 0
for i = min, max do
fork(function (...)
local t1 = now()
local ok, ip = dns_resolve(domain)
if not ok then
LOG:WARN(fmt("测试失败: <%s>[%s]的结果:[%s]", company, domain, ip))
return
end
total = total + (now() - t1)
if i == max then
LOG:DEBUG(fmt("测试完成 : <%s>[%s]的结果:[%s]; 平均消耗: %0.5f, 总计消耗: %0.8f", company, domain, delete_ipv4_prefix(ip), total / max, now() - start))
end
end)
end
end
collectgarbage()
end)
wait()