From 13ce41de83b1311dab2b312885b03ecb397dd78e Mon Sep 17 00:00:00 2001 From: Oskar Hahn Date: Thu, 16 Jun 2022 21:57:39 +0200 Subject: [PATCH 1/2] Use compression --- cmd/connect.go | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/cmd/connect.go b/cmd/connect.go index 5df4256..87f6a42 100644 --- a/cmd/connect.go +++ b/cmd/connect.go @@ -9,6 +9,7 @@ import ( "log" "net/http" "strings" + "time" "github.com/OpenSlides/openslides-performance/client" "github.com/spf13/cobra" @@ -55,10 +56,23 @@ func cmdConnect(cfg *config) *cobra.Command { for i := 0; i < *connectionCount; i++ { go func(i int) { - r, err := keepOpen(ctx, c, "/system/autoupdate", strings.NewReader(*autoupdateBody)) - if err != nil { - log.Printf("Can not send request %d: %v", i, err) - return + var r io.ReadCloser + for tries := 0; ; tries++ { + if tries > 100 { + return + } + + r, err = keepOpen(ctx, c, "/system/autoupdate?compress=1", strings.NewReader(*autoupdateBody)) + if err != nil { + if ctx.Err() != nil { + return + } + + log.Printf("Can not send request %d: %v", i, err) + time.Sleep(time.Second) + continue + } + break } defer r.Close() From ff0adb7186102b9fce675eac5c972d9f58446341 Mon Sep 17 00:00:00 2001 From: Oskar Hahn Date: Fri, 17 Jun 2022 08:15:11 +0200 Subject: [PATCH 2/2] Add flag to use the skip_first attribute --- cmd/connect.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/cmd/connect.go b/cmd/connect.go index 87f6a42..422d582 100644 --- a/cmd/connect.go +++ b/cmd/connect.go @@ -37,6 +37,7 @@ func cmdConnect(cfg *config) *cobra.Command { `[{"collection":"organization","ids":[1],"fields":{"committee_ids":{"type":"relation-list","collection":"committee","fields":{"name":null}}}}]`, "Amount of users to use.", ) + skipFirst := cmd.Flags().Bool("skip_first", false, "Use skip first flag to save traffic") cmd.RunE = func(cmd *cobra.Command, args []string) error { ctx, cancel := interruptContext() @@ -62,7 +63,12 @@ func cmdConnect(cfg *config) *cobra.Command { return } - r, err = keepOpen(ctx, c, "/system/autoupdate?compress=1", strings.NewReader(*autoupdateBody)) + skipFirstAttr := "" + if *skipFirst { + skipFirstAttr = "&skip_first=1" + } + + r, err = keepOpen(ctx, c, "/system/autoupdate?compress=1"+skipFirstAttr, strings.NewReader(*autoupdateBody)) if err != nil { if ctx.Err() != nil { return