Skip to content

Commit

Permalink
fix: network connectivity speed
Browse files Browse the repository at this point in the history
Signed-off-by: renxiangyu <[email protected]>
  • Loading branch information
renxiangyu committed Jan 9, 2024
1 parent 88a3efe commit e9da94d
Showing 1 changed file with 66 additions and 30 deletions.
96 changes: 66 additions & 30 deletions pkg/kosmosctl/floater/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"os"
"strconv"
"sync"

"github.com/olekukonko/tablewriter"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -45,6 +46,10 @@ type CommandCheckOptions struct {

SrcFloater *Floater
DstFloater *Floater

routinesMaxNum int
goroutinePool chan struct{}
waitGroup sync.WaitGroup
}

type PrintCheckData struct {
Expand Down Expand Up @@ -92,6 +97,10 @@ func NewCmdCheck() *cobra.Command {
flags.StringVar(&o.Port, "port", "8889", "Port used by floater.")
flags.IntVarP(&o.PodWaitTime, "pod-wait-time", "w", 30, "Time for wait pod(floater) launch.")
flags.StringVar(&o.Protocol, "protocol", string(TCP), "Protocol for the network problem.")
flags.IntVarP(&o.routinesMaxNum, "routines-max-number", "", 5, "Number of goroutines to use.")

o.goroutinePool = make(chan struct{}, o.routinesMaxNum)
o.waitGroup = sync.WaitGroup{}

return cmd
}
Expand Down Expand Up @@ -203,58 +212,85 @@ func (o *CommandCheckOptions) RunRange(iPodInfos []*FloatInfo, jPodInfos []*Floa
for _, iPodInfo := range iPodInfos {
for _, jPodInfo := range jPodInfos {
for _, ip := range jPodInfo.PodIPs {
var targetIP string
var err error
var cmdResult *command.Result
if o.DstFloater != nil {
targetIP, err = netmap.NetMap(ip, o.DstFloater.CIDRsMap)
} else {
targetIP = ip
}
if err != nil {
cmdResult = command.ParseError(err)
} else {
// ToDo RunRange && RunNative func support multiple commands, and the code needs to be optimized
cmdObj := &command.Ping{
TargetIP: targetIP,
}
cmdResult = o.SrcFloater.CommandExec(iPodInfo, cmdObj)
}
resultData = append(resultData, &PrintCheckData{
*cmdResult,
iPodInfo.NodeName, jPodInfo.NodeName, targetIP,
})
o.goroutinePool <- struct{}{}
o.waitGroup.Add(1)
routineIPodInfo := iPodInfo
routineJPodInfo := jPodInfo
routineIp := ip
go o.checkRange(routineIPodInfo, routineJPodInfo, routineIp, resultData)
}
}
}
}

o.waitGroup.Wait()
return resultData
}

func (o *CommandCheckOptions) checkRange(routineIPodInfo, routineJPodInfo *FloatInfo, routineIp string, resultData []*PrintCheckData) {
var targetIP string
var err error
var cmdResult *command.Result
if o.DstFloater != nil {
targetIP, err = netmap.NetMap(routineIp, o.DstFloater.CIDRsMap)
} else {
targetIP = routineIp
}
if err != nil {
cmdResult = command.ParseError(err)
} else {
// ToDo RunRange && RunNative func support multiple commands, and the code needs to be optimized
cmdObj := &command.Ping{
TargetIP: targetIP,
}
cmdResult = o.SrcFloater.CommandExec(routineIPodInfo, cmdObj)
}
resultData = append(resultData, &PrintCheckData{
*cmdResult,
routineIPodInfo.NodeName, routineJPodInfo.NodeName, targetIP,
})
defer func() {
<-o.goroutinePool
o.waitGroup.Done()
}()
}

Check failure on line 257 in pkg/kosmosctl/floater/check.go

View workflow job for this annotation

GitHub Actions / lint

ineffectual assignment to resultData (ineffassign)
func (o *CommandCheckOptions) RunNative(iNodeInfos []*FloatInfo, jNodeInfos []*FloatInfo) []*PrintCheckData {
var resultData []*PrintCheckData

if len(iNodeInfos) > 0 && len(jNodeInfos) > 0 {
for _, iNodeInfo := range iNodeInfos {
for _, jNodeInfo := range jNodeInfos {
for _, ip := range jNodeInfo.NodeIPs {
// ToDo RunRange && RunNative func support multiple commands, and the code needs to be optimized
cmdObj := &command.Ping{
TargetIP: ip,
}
cmdResult := o.SrcFloater.CommandExec(iNodeInfo, cmdObj)
resultData = append(resultData, &PrintCheckData{
*cmdResult,
iNodeInfo.NodeName, jNodeInfo.NodeName, ip,
})
o.goroutinePool <- struct{}{}
o.waitGroup.Add(1)
routineINodeInfo := iNodeInfo
routineJNodeInfo := jNodeInfo
routineIp := ip
go o.checkNative(routineINodeInfo, routineJNodeInfo, routineIp, resultData)
}
}
}
}

o.waitGroup.Wait()
return resultData
}
func (o *CommandCheckOptions) checkNative(routineINodeInfo, routineJNodeInfo *FloatInfo, routineIp string, resultData []*PrintCheckData) {
// ToDo RunRange && RunNative func support multiple commands, and the code needs to be optimized
cmdObj := &command.Ping{
TargetIP: routineIp,
}
cmdResult := o.SrcFloater.CommandExec(routineINodeInfo, cmdObj)
resultData = append(resultData, &PrintCheckData{
*cmdResult,
routineINodeInfo.NodeName, routineJNodeInfo.NodeName, routineIp,
})
defer func() {
<-o.goroutinePool
o.waitGroup.Done()
}()
}

Check failure on line 294 in pkg/kosmosctl/floater/check.go

View workflow job for this annotation

GitHub Actions / lint

ineffectual assignment to resultData (ineffassign)
func (o *CommandCheckOptions) PrintResult(resultData []*PrintCheckData) {
table := tablewriter.NewWriter(os.Stdout)
Expand Down

0 comments on commit e9da94d

Please sign in to comment.