add benchmark test

This commit is contained in:
kenshin 2013-07-25 12:32:57 +08:00
parent 84d878c03d
commit 2b4e076674
3 changed files with 82 additions and 5 deletions

View File

@ -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

25
godns_test.go Normal file
View File

@ -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)
}
}

View File

@ -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())
}