Skip to content

Instantly share code, notes, and snippets.

@tkc
Last active February 3, 2021 02:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tkc/9b1c5280bd0f64b2939659ace638af3b to your computer and use it in GitHub Desktop.
Save tkc/9b1c5280bd0f64b2939659ace638af3b to your computer and use it in GitHub Desktop.
Find out the relationship between coredns response and frequency
package main
import (
"fmt"
"os"
"os/exec"
"strings"
"sync"
"time"
)
func main() {
record(1)
record(10)
record(100)
record(500)
record(1000)
record(1250)
record(1500)
record(1750)
record(2000)
record(2250)
record(2500)
}
func record(count float64) {
start := time.Now()
wg := sync.WaitGroup{}
for i := 0; i < int(count); i++ {
wg.Add(1)
go func() {
defer wg.Done()
execDig()
}()
}
wg.Wait()
end := time.Now()
diff := (end.Sub(start)).Seconds()
fmt.Printf("------------------------------------\n")
fmt.Printf("Number of requests:%d\n", int(count))
fmt.Printf("Total response(sec):%f\n", diff)
fmt.Printf("Average response(sec):%f\n", diff/count)
execTop()
}
func execTop() {
out,err := exec.Command("./top.sh").Output()
if err != nil {
fmt.Println(err.Error())
os.Exit(1)
}
fmt.Printf("top command: \n%s", string(out))
}
func execDig() {
args := strings.Fields("dig @127.0.0.1 -p 53 www.example.com")
_, err := exec.Command("dig", args...).Output()
if err != nil {
fmt.Println(err.Error())
os.Exit(1)
}
}
#!/bin/sh
top -l 1 -s 0 | grep coredns
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment