Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how is the rate calculated? #14

Open
Asuraqi opened this issue Dec 9, 2020 · 1 comment
Open

how is the rate calculated? #14

Asuraqi opened this issue Dec 9, 2020 · 1 comment

Comments

@Asuraqi
Copy link

Asuraqi commented Dec 9, 2020

I deduced from the meterexample that the value of rate is the cumulative value of the mark/total time, but I found that if the time of each round is too small, the value of rate is 0.
Below is my code and result:
mt:=meter.NewMeter()

testStreamNum := 1000  
var wg sync.WaitGroup

send := func(wg *sync.WaitGroup) {
	defer wg.Done()
	resp, err := p1.Send(p2.PeerID(), msg)
	assert.Nil(t, err)
	assert.EqualValues(t, ack,resp)
}
for i := 0; i < testStreamNum; i++ {
	wg.Add(1)
	go send(&wg)
	mt.Mark(uint64(len(msg)))      //uint64(len(msg)=11
}
rate:=mt.Snapshot().Rate
wg.Wait()

time.Sleep(2*time.Second)

total:=mt.Snapshot().Total
fmt.Printf("%d(%d/s)\n",total,roundTens(rate))

result:
11000(0/s)
--- PASS: TestP2P_MultiStreamSend (2.07s)

@Stebalien
Copy link
Member

The rate is an EWMA (exponentially weighted moving average) over 1 second intervals.

but I found that if the time of each round is too small, the value of rate is 0.

The rate will be 0 if you've waited less than a second as the background loop won't have computed the rate yet. It may be possible to compute some form of instantaneous rate, but it's not clear exactly what this should be.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants