in cmd/bench/bench.go [53:107]
func runBenchmark(start chan<- struct{}) {
var (
wg sync.WaitGroup
totalBytes int64
)
for i := 0; i < 15; i++ {
wg.Add(1)
go func() {
cnx, err := net.Dial("tcp", redplexAddress)
if err != nil {
logrus.WithError(err).Fatal("redplex/bench: error dialing to server")
}
if _, err := cnx.Write(subscribe); err != nil {
logrus.WithError(err).Fatal("redplex/bench: error subscribing")
}
wg.Done()
wg.Wait()
buf := make([]byte, 32*1024)
for {
n, err := cnx.Read(buf)
atomic.AddInt64(&totalBytes, int64(n))
if err != nil {
logrus.WithError(err).Fatal("redplex/bench: error in reader")
}
}
}()
}
wg.Wait()
start <- struct{}{}
time.Sleep(time.Second) // give it a second to ramp up
atomic.StoreInt64(&totalBytes, 0)
go func() {
last := int64(0)
for {
time.Sleep(time.Second)
next := atomic.LoadInt64(&totalBytes)
fmt.Println("delta", next-last)
last = next
}
}()
started := time.Now()
time.Sleep(15 * time.Second)
delta := time.Now().Sub(started)
seconds := float64(delta) / float64(time.Second)
gigabits := float64(totalBytes) / 1024 / 1024 * 8
fmt.Printf("Read %d bytes in %.2fs (%.0f Mbps)\n", totalBytes, seconds, gigabits/seconds)
}