From 2b4e0766741a9f9242edb66bc99cbf04d5f17dbc Mon Sep 17 00:00:00 2001 From: kenshin Date: Thu, 25 Jul 2013 12:32:57 +0800 Subject: [PATCH] add benchmark test --- README.MD | 55 ++++++++++++++++++++++++++++++++++++++++++++++----- godns_test.go | 25 +++++++++++++++++++++++ main.go | 7 +++++++ 3 files changed, 82 insertions(+), 5 deletions(-) create mode 100644 godns_test.go diff --git a/README.MD b/README.MD index 3829c7c..a2b1857 100644 --- a/README.MD +++ b/README.MD @@ -1,23 +1,41 @@ GODNS ==== -A tiny dns cache server written by go. +A simple and fast dns cache server written by go. Similar as [dnsmasq](http://www.thekelleys.org.uk/dnsmasq/doc.html) ,but support some difference features: -* Keep hosts configuration in redis instead of local file /etc/hosts - So can be updated from remote server +* Keep hosts records in redis instead of the local file /etc/hosts * Atuo-Reload when hosts configuration changed. (Yes,dnsmasq need restart) * Cache records save in memory or redis configurable -## Install +## Install & Running -## Running +1. Install + + $ go get github.com/kenshinx/godns + + +2. Build + + $ cd $GOPATH/src/github.com/kenshinx/godns + $ go build -o godns *.go + + +3. Running + + $ sudo ./godns -c godns.conf + + +4. Use + + $ sudo vi /etc/resolv.conf + nameserver 127.0.0.1 @@ -56,6 +74,33 @@ maxcount = 100000 ``` +## Benchmak + +``` +$ go test -bench=. + +testing: warning: no tests to run +PASS +BenchmarkDig-4 5000 435141 ns/op +ok _/Users/kenshin/workspace/godns 2.270s +``` + +The result : 2200 queries/per second + +The enviroment of test: + +MacBook Air + +* CPU: +Inter Core i5 1.7G +Double cores + +* MEM: +8G + + + + ## TODO * The redis cache backend diff --git a/godns_test.go b/godns_test.go new file mode 100644 index 0000000..daf5d1d --- /dev/null +++ b/godns_test.go @@ -0,0 +1,25 @@ +package main + +import ( + "github.com/miekg/dns" + "testing" +) + +const ( + nameserver = "127.0.0.1:53" + domain = "www.sina.com.cn" +) + +func BenchmarkDig(b *testing.B) { + m := new(dns.Msg) + m.SetQuestion(dns.Fqdn(domain), dns.TypeA) + + c := new(dns.Client) + + b.ResetTimer() + + for i := 0; i < b.N; i++ { + c.Exchange(m, nameserver) + } + +} diff --git a/main.go b/main.go index e7da0f8..3a584e1 100644 --- a/main.go +++ b/main.go @@ -4,6 +4,7 @@ import ( "log" "os" "os/signal" + "runtime" "time" ) @@ -24,6 +25,8 @@ func main() { server.Run() + logger.Printf("godns %s start", settings.Version) + sig := make(chan os.Signal) signal.Notify(sig, os.Interrupt) @@ -57,3 +60,7 @@ func initLogger(log_file string) (logger *log.Logger) { return logger } + +func init() { + runtime.GOMAXPROCS(runtime.NumCPU()) +}