Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
gitpod-io
GitHub Repository: gitpod-io/gitpod
Path: blob/main/dev/ssh-load-test/cmd/reopen.go
2498 views
1
package cmd
2
3
import (
4
"io"
5
"log"
6
"time"
7
8
"github.com/spf13/cobra"
9
)
10
11
var concurrentNum int32
12
13
var reopenCmd = &cobra.Command{
14
Use: "reopen",
15
Short: "try dropping and reopening connections to see whether ws-proxy leaks memory on such connections",
16
Run: func(cmd *cobra.Command, args []string) {
17
for i := 0; i < int(concurrentNum); i++ {
18
go func(i int) {
19
for {
20
cli, err := connSSH()
21
if err != nil {
22
log.Println("[error]", i, "open ssh failed", err)
23
return
24
}
25
err = cli.Cmd("date").Run()
26
if err != nil && err != io.EOF {
27
log.Println("[error]", i, "exec cmd failed", err)
28
return
29
}
30
err = cli.Close()
31
if err != nil {
32
log.Println("[error]", i, "close ssh failed", err)
33
return
34
}
35
time.Sleep(1 * time.Second)
36
}
37
}(i)
38
time.Sleep(10 * time.Millisecond)
39
}
40
select {}
41
},
42
}
43
44
func init() {
45
rootCmd.AddCommand(reopenCmd)
46
rootCmd.PersistentFlags().Int32VarP(&concurrentNum, "concurrent", "c", 1, "Number of concurrent connection")
47
}
48
49