sentinel-golang icon indicating copy to clipboard operation
sentinel-golang copied to clipboard

what does the reset() of MetricBucket do? seems no references

Open titanxxh opened this issue 3 years ago • 2 comments

https://github.com/alibaba/sentinel-golang/blob/c362aaeafd1e500c9812d4961bcea81b25008b45/core/stat/base/metric_bucket.go#L68

another question: the minrt updating function is not thread safe.

func (mb *MetricBucket) AddRt(rt int64) {
	mb.addCount(base.MetricEventRt, rt)
	if rt < atomic.LoadInt64(&mb.minRt) { // here is not thread safe.
		// Might not be accurate here.
		atomic.StoreInt64(&mb.minRt, rt)
	}
}

titanxxh avatar Apr 28 '21 03:04 titanxxh

what does the reset() of MetricBucket do? seems no references

This was designed for refreshing the deprecated bucket (i.e. ResetBucketTo of BucketGenerator) but not used (maybe forgotten). Would you like to submit a PR to improve it?

sczyh30 avatar Apr 28 '21 12:04 sczyh30

i can do this in my spare time

Howie59 avatar Apr 29 '21 03:04 Howie59

@sczyh30 I think you mean that the existing reset() function is not being used and a new MetricBucket is recreated in the ResetBucketTo() function. Therefore, you want to optimize your code to call reset() to avoid this unnecessary operation. Is that so?

Alipebt avatar Mar 22 '23 08:03 Alipebt

@sczyh30 I think you mean that the existing reset() function is not being used and a new MetricBucket is recreated in the ResetBucketTo() function. Therefore, you want to optimize your code to call reset() to avoid this unnecessary operation. Is that so?

Yeah, that's it.

sczyh30 avatar Mar 23 '23 01:03 sczyh30