go-kratos / aegis Goto Github PK
View Code? Open in Web Editor NEWService Reliability Algorithm
License: MIT License
Service Reliability Algorithm
License: MIT License
fatal error: checkptr: pointer arithmetic result points to invalid allocation
goroutine 27808 [running]:
runtime.throw({0x6a7beb7?, 0x18cd719?})
GOROOT/src/runtime/panic.go:1047 +0x5d fp=0xc0037a2e28 sp=0xc0037a2df8 pc=0x1893bfd
runtime.checkptrArithmetic(0xc007c31980?, {0x0, 0x0, 0xc0037a2eb0?})
GOROOT/src/runtime/checkptr.go:69 +0xaa fp=0xc0037a2e58 sp=0xc0037a2e28 pc=0x185e52a
github.com/spaolacci/murmur3.Sum32WithSeed({0xc007c31980, 0x40, 0x40}, 0x0)
external/com_github_spaolacci_murmur3/murmur32.go:129 +0x90 fp=0xc0037a2ec0 sp=0xc0037a2e58 pc=0x53f2290
github.com/spaolacci/murmur3.Sum32(...)
external/com_github_spaolacci_murmur3/murmur32.go:111
github.com/pingcap/tidb/util/topk.(*HeavyKeeper).Add(0xc00070b320, {0xc007c318c0, 0x40}, 0x1)
func (r *RollingPolicy) apply(f func(offset int, val float64), val float64)
这里如果timespan超过了r.size,会导致r.lastAppendTime设置的时间不对。 下面是修改过的代码
func (r *RollingPolicy) apply(f func(offset int, val float64), val float64) {
r.mu.Lock()
defer r.mu.Unlock()
// calculate current offset
rawtimespan := r.timespan()
if rawtimespan > 0 {
start := (r.offset + 1) % r.size
end := (r.offset + timespan) % r.size
timespan := rawtimespan
if rawtimespan > r.size {
timespan = r.size
}
// reset the expired buckets
r.window.ResetBuckets(start, timespan)
r.offset = end
r.lastAppendTime = r.lastAppendTime.Add(time.Duration(rawtimespan * int(r.bucketDuration)))
}
f(r.offset, val)
}
package ratelimit
// Limiter is a rate limiter.
type Limiter interface {
Allow() (DoneFunc, error)
}
如果不使用默认的 bbr 实现,想要额外拓展一些更细粒度的限流,不传请求信息进去什么都搞不了,这个接口基本没有拓展性。
类似这样:
// Limiter is a rate limiter.
type Limiter interface {
Allow(ctx context.Context, req interface{}) (DoneFunc, error)
}
type Bucket struct {
Points []float64 // 这里为什么要用切片类型呢?
Count int64
next *Bucket
}
Points 如果定义为数值类型会有什么坏处吗?看源码里也只使用Points[0],这样的话为什么不直接用数值类型呢?
Line 219 in 56c0fb5
If you want to count the avg of single window with all points, you should use this:
avg := total / float64(len(bucket.Points))
请教一下作者,基于各种 BBR 算法的解读,例如:
想要探测 minRt 就要有排空阶段,排空就是要限制并发数,但在这里的 bbr 实现 里并没有看到相关逻辑。
type Warden interface {
// 开始保护一段代码逻辑或者一次RPC Invoke
Ward(ctx context.Context, opts ...Options) (Done, error)
}
// 结束的时候传入error、bytes send、bytes recevied等信息
type Done func(err error, opts ...DoneOptions)
type Option func(*options)
type DoneOption func(*doneOptions)
环境:阿X云Serverless Kubernetes(ASK)集群,底层使用基于Kata的安全沙箱容器。
问题:测试发现默认会使用 cgroup 方式来采集 CPU Limit,Kata 好像是类似于虚拟机的,没用 cgroup,无法采集。
然后调整代码直接用 psutil 来采集信息也对不上,比如限制 cpu 0.5核,实际会给两核,每核只能用0.25。psutil 采集的也是两核,导致限流失效。
猜测:不确定是 Kata 无法采集还是阿X云底层实现不同导致的,对这些不怎么了解。
临时方案:限制是通过 k8s downwardapi 把具体资源限制注入到容器中,然后修改了相关代码,把 CPU Limit 直接设置给 limiter,而不是自动获取
有必要添加这么一个 options 来手动设置 cpu limit 嘛?
Line 235 in 56c0fb5
Background:
I plan to use the API average RT (response time) or P95 RT as the adaptive current limiting startup threshold. But the current code design makes it difficult for me to implement this function.
My thoughts:
By defining the startup threshold interface, and supporting passing in limiter during initialization.
e.x.
type StartupThreshold interface {
Reach()
}
func (l *BBR) shouldDrop() bool {
now := time.Duration(time.Now().UnixNano())
//
if ! l.StartupThreshold.Reach() {
// do sth when not reach threshold
}
// do sth when reach threshold
// drop ...
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.