add max-time and max-metrics
This commit is contained in:
parent
f3abd3944d
commit
3c15273c45
|
|
@ -3,7 +3,7 @@
|
|||
TEMPLATE_NAME="zabbix-bench"
|
||||
GROUP_NAME="Linux servers"
|
||||
CLIENT_PREFIX="client"
|
||||
CLIENTS=200
|
||||
CLIENTS=40000
|
||||
|
||||
echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>
|
||||
<zabbix_export>
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
TEMPLATE_NAME="zabbix-bench"
|
||||
APPLICATION_NAME="zabbix-bench"
|
||||
METRIC_PREFIX="metric"
|
||||
METRICS=200
|
||||
METRICS=400
|
||||
|
||||
echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>
|
||||
<zabbix_export>
|
||||
|
|
|
|||
35
src/main.go
35
src/main.go
|
|
@ -3,6 +3,7 @@ package main
|
|||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"math/rand"
|
||||
"os"
|
||||
"os/signal"
|
||||
"runtime"
|
||||
|
|
@ -16,11 +17,13 @@ var (
|
|||
argClientCount = flag.Int("client", 200, "number of concurrent clients")
|
||||
argThreadCount = flag.Int("threads", runtime.NumCPU()*4, "number of threads")
|
||||
argClinetName = flag.String("client-format", "client-%d", "format of client name")
|
||||
argPacketSize = flag.Int("packet-size", 100, "count of metric in packet")
|
||||
argPacketSize = flag.Int("packet-size", 400, "count of metric in packet")
|
||||
argMetricName = flag.String("metric-format", "metric-%d", "format of metric name in packet")
|
||||
argPacketDelay = flag.Duration("packet-delay", 100*time.Millisecond, "delay of send packet")
|
||||
argSendTimeout = flag.Duration("packet-send-timeout", 10*time.Millisecond, "packet send timeout")
|
||||
argZabbix = flag.String("zabbix", "127.0.0.1:10051", "address of zabbix server")
|
||||
argMaxMetrics = flag.Int("max-metrics", 0, "max number of metrics each client sends")
|
||||
argMaxSeconds = flag.Int("max-time", 0, "max duration of benchmark test in seconds")
|
||||
|
||||
errorChannel = make(chan error, 10)
|
||||
completedChannel = make(chan int, 10)
|
||||
|
|
@ -44,15 +47,31 @@ func main() {
|
|||
go StartClient(i)
|
||||
}
|
||||
|
||||
os.Stdout.WriteString(fmt.Sprintf("Start %d clients with packet size %d metric and delay between packets %v\n", *argClientCount, *argPacketSize, *argPacketDelay))
|
||||
report_and_exit := func() {
|
||||
speed := 0
|
||||
if sec > 0 {
|
||||
speed = int(total / sec)
|
||||
}
|
||||
fmt.Printf("\n-----------------------------\n")
|
||||
fmt.Printf("Total processed: %d (%d metric/s)\n", total, speed)
|
||||
os.Exit(0)
|
||||
}
|
||||
|
||||
fmt.Printf("Start %d clients with packet size %d metric and delay between packets %v\n", *argClientCount, *argPacketSize, *argPacketDelay)
|
||||
ticker := time.Tick(time.Second)
|
||||
for {
|
||||
select {
|
||||
case <-ticker:
|
||||
mutex.Lock()
|
||||
os.Stdout.WriteString(fmt.Sprintf("progress %d s, %d metric/s\n", sec, counter))
|
||||
fmt.Printf("progress %d s, %d metric/s\n", sec, counter)
|
||||
sec += 1
|
||||
counter = 0
|
||||
if *argMaxMetrics > 0 && total > *argMaxMetrics {
|
||||
report_and_exit()
|
||||
}
|
||||
if *argMaxSeconds > 0 && sec > *argMaxSeconds {
|
||||
report_and_exit()
|
||||
}
|
||||
mutex.Unlock()
|
||||
case count := <-completedChannel:
|
||||
mutex.Lock()
|
||||
|
|
@ -60,14 +79,9 @@ func main() {
|
|||
total += count
|
||||
mutex.Unlock()
|
||||
case err := <-errorChannel:
|
||||
os.Stderr.WriteString(fmt.Sprintf("Error write metric:\t%s\n", err.Error()))
|
||||
fmt.Fprintf(os.Stderr, "Error write metric:\t%s\n", err.Error())
|
||||
case <-signalChannel:
|
||||
speed := 0
|
||||
if sec > 0 {
|
||||
speed = int(total / sec)
|
||||
}
|
||||
os.Stdout.WriteString(fmt.Sprintf("\n-----------------------------\nTotal processed: %d (%d metric/s)\n", total, speed))
|
||||
os.Exit(0)
|
||||
report_and_exit()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -91,6 +105,7 @@ func (c *client) send() error {
|
|||
}
|
||||
|
||||
func StartClient(id int) {
|
||||
time.Sleep((time.Duration(rand.Float64()*100) * *argPacketDelay) / 100)
|
||||
c := &client{
|
||||
id: id,
|
||||
host: fmt.Sprintf(*argClinetName, id),
|
||||
|
|
|
|||
|
|
@ -61,7 +61,7 @@ func (s *Sender) Send(packet *Packet) error {
|
|||
|
||||
_, err = s.read(conn)
|
||||
if err != nil {
|
||||
os.Stderr.WriteString(fmt.Sprintf("Read zabbix response error: %s\n", err.Error()))
|
||||
fmt.Fprintf(os.Stderr, "Read zabbix response error: %s\n", err.Error())
|
||||
}
|
||||
|
||||
return nil
|
||||
|
|
|
|||
Loading…
Reference in New Issue