Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@DuodenumL
Copy link
Contributor

优化了一下Engine Cache Check的逻辑,即使GetEngine报错了也要记录到缓存里,否则在endpoint三层不通的时候,每次ping都要花很长时间,导致一些api例如GetWorkload耗时巨大。

}()

keysToCheck.Range(func(key, _ interface{}) bool {
pool.Go(ctx, func() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sync.Map. Range 里用 goroutine 好像会导致并发不安全, 本来有互斥锁, 但是 goroutine 逃逸了这个锁.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

改了,不知道为啥这里没标outdated

@DuodenumL DuodenumL force-pushed the feature/engine-cache branch from aa94e3e to 7e17f11 Compare January 19, 2022 09:38
}

// ImageBuildFromExist .
func (f *Engine) ImageBuildFromExist(ctx context.Context, ID string, refs []string, user string) (string, error) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmmmm 有点过分了

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里是为了让error进入缓存,比如创建Engine的时候错误是connection refused,那么就让这个fake engine每次调用都返回connection refused

}
if err := validateEngine(ctx, client, config.ConnectionTimeout); err != nil {
log.Errorf(ctx, "[EngineCacheChecker] engine %v is unavailable, will be replaced with a fake engine, err: %v", cacheKey, err)
engineCache.Set(cacheKey, &fake.Engine{DefaultErr: err})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里更新 cache 用了两步操作, 先 delete 再 set, 可以合并成一步吗, 合并成一步是不是就并发安全了


// EngineCacheChecker checks if the engine in cache is available
func EngineCacheChecker(ctx context.Context, timeout time.Duration) {
func EngineCacheChecker(ctx context.Context, config types.Config) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里已经应该建模了吧, 不要再操作一个全局变量了, 创建一个结构体, 包含 cache, 然后这个函数作为其中一个方法.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

改好了

@DuodenumL DuodenumL force-pushed the feature/engine-cache branch 3 times, most recently from 44dd656 to b60db40 Compare January 19, 2022 10:31
}()

// getEngine get engine
func getEngine(ctx context.Context, config types.Config, nodename, endpoint, ca, cert, key string) (client engine.API, err error) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个名字应该是 newEngine

Copy link
Member

@jschwinger233 jschwinger233 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

好像还行 自己要跑一跑试一下

@DuodenumL DuodenumL force-pushed the feature/engine-cache branch from b60db40 to 472f41c Compare January 19, 2022 10:50
@DuodenumL
Copy link
Contributor Author

DuodenumL commented Jan 19, 2022

好像还行 自己要跑一跑试一下

跑了一下,截至目前没发现问题

@DuodenumL DuodenumL closed this Jan 19, 2022
@DuodenumL DuodenumL reopened this Jan 19, 2022
@jschwinger233 jschwinger233 merged commit d145b4c into projecteru2:v22.01.05 Jan 19, 2022
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

Successfully merging this pull request may close these issues.

3 participants