Skip to content

how is the rate calculated? #14

@Asuraqi

Description

@Asuraqi

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions