Skip to content

Commit

Permalink
fix loss ratio calculation bug
Browse files Browse the repository at this point in the history
  • Loading branch information
wxiaoguang committed Oct 29, 2022
1 parent 659051f commit ccb076e
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 29 deletions.
27 changes: 12 additions & 15 deletions .github/workflows/release_build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,22 @@ on:
- "*"

jobs:
build:
name: GoReleaser build
build-release:
runs-on: ubuntu-latest

steps:
- name: Check out code into the Go module directory
uses: actions/checkout@v2
with:
fetch-depth: 0 # See: https://goreleaser.com/ci/actions/

- name: Set up Go 1.14
uses: actions/setup-go@v2
-
name: Checkout
uses: actions/checkout@v3
with:
go-version: 1.14
id: go

- name: Run GoReleaser
uses: goreleaser/goreleaser-action@master
fetch-depth: 0
-
name: Set up Go
uses: actions/setup-go@v3
-
name: Run GoReleaser
uses: goreleaser/goreleaser-action@v3
with:
distribution: goreleaser
version: latest
args: release --rm-dist
workdir: ./cmd/echoping
Expand Down
28 changes: 14 additions & 14 deletions internal/echoping/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,24 +18,24 @@ var ClientPingTimeout = 3 * time.Second
var ClientPingInterval = 20 * time.Millisecond

type clientPingRequestRecord struct {
sentTime time.Time
sentTime time.Time
sentBytes int64
recvTime time.Time
recvTime time.Time
recvBytes int64
}

type clientConnSession struct {
key string
key string
remoteAddr string
sessionId string
sessionId string

pingRequestRecords map[string]*clientPingRequestRecord
mu sync.Mutex
mu sync.Mutex
}

type Client struct {
connSessions map[string]*clientConnSession
mu sync.Mutex
mu sync.Mutex

onceClientTimer sync.Once
}
Expand Down Expand Up @@ -91,7 +91,7 @@ func (client *Client) startClientTimer() {
statsRequestCount := loss + pingRoundTripCount

pps := float64(statsRequestCount) / statsDurationSeconds
lossRatio := float64(loss/statsRequestCount)
lossRatio := float64(loss) / float64(statsRequestCount)

rttAvgMs := math.NaN()
rttStddevMs := math.NaN()
Expand Down Expand Up @@ -128,7 +128,7 @@ func (client *Client) startClientTimer() {
sort.SliceStable(pingRoundTripDurations, func(i, j int) bool {
return pingRoundTripDurations[i] < pingRoundTripDurations[j]
})
p90idx := pingRoundTripCount*9/10
p90idx := pingRoundTripCount * 9 / 10
rttP90Ms = pingRoundTripDurations[p90idx].Seconds() * 1000
}
}
Expand Down Expand Up @@ -329,14 +329,14 @@ func (client *Client) ConnectEchoPingUdp(addr string) {
wg.Add(2)

go func() {
loop:
loop:
for !exitLoop {
pingTime := time.Now()
data := client.preparePingRequest(pingTime, cs, msgMap)
if _, err := conn.WriteToUDP(data, udpRemoteAddr); err != nil {
log.Printf("client udp conn %s write error: %s", addr, err)
break loop
}
if _, err := conn.WriteToUDP(data, udpRemoteAddr); err != nil {
log.Printf("client udp conn %s write error: %s", addr, err)
break loop
}
elapsed := time.Now().Sub(pingTime)
sleepDuration := ClientPingInterval - elapsed
if sleepDuration > 0 {
Expand All @@ -350,7 +350,7 @@ func (client *Client) ConnectEchoPingUdp(addr string) {
buf := make([]byte, 65536)
var n int
var err error
loop:
loop:
for !exitLoop {
_ = conn.SetReadDeadline(time.Now().Add(time.Second))
if n, _, err = conn.ReadFromUDP(buf); err != nil {
Expand Down

0 comments on commit ccb076e

Please sign in to comment.