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