読者です 読者をやめる 読者になる 読者になる

Google Public DNS 使ってみた

GoogleDNS を提供するようになったそうなので、試してみた。

うちの環境は PC -> Router -> Internet という形で接続されていて、今回は Router の DNS サーバの設定を変更することでテストした。
PC の OS は Windows 7(64bit)。cygwin 上の ruby で次のスクリプトを実行。

1回の試行につき、国内/国外それぞれ 20 host、適当に生成した 40 host の正引きをやって、ip が得られたものについて時間を計測。
8回の平均値を出す。

#!/usr/bin/env ruby

require 'resolv'
require 'benchmark'

FLUSHCMD = "ipconfig /flushdns"
DUMMY = 
	["infoseek.co.jp", "cnn.com"]
FOREIGN = 
	["amazon.com", "apple.com", "acer.com", "asus.com",
	"amazon.co.uk", "whitehouse.gov", "google.com", "twitter.com",
	"microsoft.com", "yahoo.com", "www.sun.com", "ubuntu.com",
	"novell.com", "youtube.com", "redhat.com", "debian.org",
	"live.com", "en.wikipedia.org", "sourceforge.net", "bit.ly"]
DOMESTIC = 
	["amazon.co.jp", "yahoo.co.jp", "goo.ne.jp", "google.co.jp",
	"u-tokyo.ac.jp", "jaist.ac.jp", "keio.ac.jp", "kyushu-u.ac.jp",
	"sakura.ne.jp", "shinobi.jp", "geocities.jp", "xrea.com",
	"hatena.ne.jp", "livedoor.jp", "ameblo.jp", "fc2.com",
	"nicovideo.jp", "mixi.jp", "impress.co.jp", "japan.cnet.com"]
RANDOM = 
	["from.com", "coverage.com", "following.com", "which.com", 
	"considered.com", "part.com", "governed.com", "binary.com", 
	"form.com", "winsup.com", "testsuite.com", "api.com", 
	"msgtest.com", "semtest.com", "shmtest.com", "combine.com", 
	"code.com", "corresponding.com", "such.com", "combinations.com", 
	"your.com", "choice.com", "provided.com", "otherwise.com", 
	"consistent.com", "comply.com", "respect.com", "all.com", 
	"portions.com", "other.com", "than.com", "those.com", 
	"correspond.com", "derived.com", "non.com", "but.com", 
	"cygserver.com", "sysv.com", "shm.com", "alternative.com"]


def test(hosts)
	times = []
	hosts.each do |host|
		begin
			time = Benchmark.measure{ Resolv.getaddress(host) }.real
			times << time
		rescue
		end
	end
	
	return average(times)
end

def main()

	printf("%10s  %10s  %10s\n", "foreign", "domestic", "random")
	result = []
	
	8.times do |i|
		`${FLUSHCMD}`
		
		test(DUMMY)
		
		tr = [test(FOREIGN), test(DOMESTIC), test(RANDOM)]
		printf("%10fs %10fs %10fs\n", tr[0], tr[1], tr[2])
		result << tr
	end

	puts "-" * 34
	3.times do |row|
		ave = average(result.map{|i| i[row]})
		printf("%10fs ", ave)
	end
	puts ""
end

def average(array)
	return array.inject(0.0){|sum, i| next sum + i} / array.size
end

if $0 == __FILE__ then
	main()
end

biglobe(契約しているISP):

   foreign    domestic      random
  0.058950s   0.020889s   0.058000s
  0.020350s   0.018611s   0.018600s
  0.020100s   0.020444s   0.018143s
  0.019200s   0.020000s   0.019486s
  0.021450s   0.020444s   0.019057s
  0.020000s   0.018889s   0.019029s
  0.019600s   0.020000s   0.018800s
  0.018900s   0.020111s   0.018086s
----------------------------------
  0.024819s   0.019924s   0.023650s

google:

   foreign    domestic      random
  0.076200s   0.050833s   0.085686s
  0.061200s   0.054000s   0.045657s
  0.045750s   0.046833s   0.071486s
  0.045450s   0.045389s   0.044800s
  0.062050s   0.048000s   0.079429s
  0.045900s   0.045000s   0.044886s
  0.045650s   0.045778s   0.049857s
  0.053200s   0.045056s   0.044943s
----------------------------------
  0.054425s   0.047611s   0.058343s

biglobe のほうが早く見える。
テストの方法が間違っているのか、はたまたこんなものなのか。

とりあえずいったん考えるのをやめる。