Skip to content

Commit

Permalink
(q191201771#58) [refactor] demo/benchrtmpconnect 关闭日志,超时时长改为30秒,优化建连时…
Browse files Browse the repository at this point in the history
…长小于1毫秒的展示
  • Loading branch information
q191201771 committed Jun 20, 2021
1 parent 7b4c984 commit b1c9f58
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions app/demo/benchrtmpconnect/benchrtmpconnect.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
func main() {
_ = nazalog.Init(func(option *nazalog.Option) {
option.AssertBehavior = nazalog.AssertFatal
option.Level = nazalog.LevelLogNothing
})
defer nazalog.Sync()

Expand All @@ -51,11 +52,22 @@ func main() {
totalB := time.Now()
for _, url := range urls {
go func(u string) {
pullSession := rtmp.NewPullSession()
pullSession := rtmp.NewPullSession(func(option *rtmp.PullSessionOption) {
option.PullTimeoutMs = 30000
option.ReadAvTimeoutMs = 30000
option.HandshakeComplexFlag = false
})
b := time.Now()
err := pullSession.Pull(u, func(msg base.RtmpMsg) {
})
cost := time.Now().Sub(b).Milliseconds()
e := time.Now()
cost := e.Sub(b).Milliseconds()
// 耗时不够1毫秒,我们将值取整到1毫秒,并打印更精确的实际耗时
if cost == 0 {
_, _ = fmt.Fprintf(os.Stderr, "round to 1 ms but actual is %s\n", e.Sub(b).String())
cost = 1
}

mu.Lock()
if err == nil {
succCosts = append(succCosts, cost)
Expand All @@ -67,7 +79,12 @@ func main() {
}(url)
}
wg.Wait()
totalCost := time.Now().Sub(totalB).Milliseconds()
totalE := time.Now()
totalCost := totalE.Sub(totalB).Milliseconds()
if totalCost == 0 {
_, _ = fmt.Fprintf(os.Stderr, "round to 1 ms but actual is %s\n", totalE.Sub(totalB).String())
totalCost = 1
}
min, max, avg := analyse(succCosts)
_, _ = fmt.Fprintf(os.Stderr, "task(num): total=%d, succ=%d, fail=%d\n", len(urls), len(succCosts), len(failCosts))
_, _ = fmt.Fprintf(os.Stderr, " cost(ms): total=%d, avg=%d, min=%d, max=%d\n", totalCost, avg, min, max)
Expand Down

0 comments on commit b1c9f58

Please sign in to comment.