Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
gitpod-io
GitHub Repository: gitpod-io/gitpod
Path: blob/main/dev/ssh-load-test/cmd/lotconn.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 connNum int32
12
13
var lotconnCmd = &cobra.Command{
14
Use: "lotconn",
15
Short: "many connections to learn the cost of single connection in terms of memory and CPU",
16
Run: func(cmd *cobra.Command, args []string) {
17
// for num -> start connection
18
for i := 0; i < int(connNum); i++ {
19
go func(i int) {
20
cli, err := connSSH()
21
if err != nil {
22
log.Println("[error]", i, "connSSH failed", err)
23
return
24
}
25
for {
26
_, err := cli.Cmd("date").Output()
27
if err != nil && err != io.EOF {
28
log.Println("[error]", i, err)
29
time.Sleep(1 * time.Second)
30
continue
31
}
32
// log.Println("[debug]", string(out))
33
time.Sleep(1 * time.Second)
34
}
35
}(i)
36
time.Sleep(10 * time.Millisecond)
37
}
38
select {}
39
},
40
}
41
42
func init() {
43
rootCmd.AddCommand(lotconnCmd)
44
rootCmd.PersistentFlags().Int32VarP(&connNum, "num", "n", 1, "Number of connection")
45
}
46
47