improve upsert perfomance
This commit is contained in:
@ -2,9 +2,11 @@ package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"log"
|
||||
"os"
|
||||
"os/signal"
|
||||
"runtime"
|
||||
"strconv"
|
||||
"sync/atomic"
|
||||
"time"
|
||||
@ -38,18 +40,26 @@ func main() {
|
||||
deviceCountStr := os.Getenv("DEVSIM_DEVICE_COUNT")
|
||||
delayStr := os.Getenv("DEVSIM_REQUEST_DELAY")
|
||||
|
||||
deviceCount, err := strconv.Atoi(deviceCountStr)
|
||||
if err != nil {
|
||||
log.Fatalf("parsing device count: %v", err)
|
||||
deviceCount := runtime.GOMAXPROCS(0)
|
||||
if deviceCountStr != "" {
|
||||
var err error
|
||||
deviceCount, err = strconv.Atoi(deviceCountStr)
|
||||
if err != nil {
|
||||
log.Fatalf("parsing device count: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
if dstAddr == "" {
|
||||
log.Fatal("no destination address provided")
|
||||
}
|
||||
|
||||
delay, err := time.ParseDuration(delayStr)
|
||||
if err != nil {
|
||||
log.Fatalf("parsing delay duration: %v", err)
|
||||
delay := time.Millisecond * 20
|
||||
if delayStr != "" {
|
||||
var err error
|
||||
delay, err = time.ParseDuration(delayStr)
|
||||
if err != nil {
|
||||
log.Fatalf("parsing delay duration: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
log.Printf("running application with settings: destination=%s device_count=%d delay=%s", dstAddr, deviceCount, delay)
|
||||
@ -113,6 +123,10 @@ func (h *deviceHandler) loop(ctx context.Context) {
|
||||
|
||||
err := h.client.Upsert(ctx, h.stats)
|
||||
if err != nil {
|
||||
if errors.Is(err, context.Canceled) {
|
||||
return
|
||||
}
|
||||
|
||||
log.Printf("%q: unable to upsert metrics: %v", h.stats.ID, err)
|
||||
failedCount++
|
||||
if failedCount > 10 {
|
||||
|
||||
Reference in New Issue
Block a user