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

高性能本地缓存 #943

Open
tianxiaoliang opened this issue Dec 7, 2020 · 4 comments
Open

高性能本地缓存 #943

tianxiaoliang opened this issue Dec 7, 2020 · 4 comments
Labels
enhancement New feature or request

Comments

@tianxiaoliang
Copy link
Member

tianxiaoliang commented Dec 7, 2020

当前的微服务local cache,当前的默认实现使用简单的map结构来存储所有微服务实例信息

// CacheIndex is a unified local instances cache manager
type CacheIndex interface {
	Get(service string, tags map[string]string) ([]*MicroServiceInstance, bool)
	//Set will overwrite all instances correspond to a service name
	Set(service string, instances []*MicroServiceInstance)
	FullCache() *cache.Cache
	Delete(service string)
}

需要一种新的数据结构能够快速的根据tags内的kv对进行检索
tag其实就是简单的查询条件,例如version=1.0,app=shop

@tianxiaoliang tianxiaoliang added the enhancement New feature or request label Dec 7, 2020
@tianxiaoliang tianxiaoliang changed the title 高性能缓存 高性能本地缓存 Dec 7, 2020
@ichiro999
Copy link
Collaborator

现有的cache有什么问题吗?效率低?

@tianxiaoliang
Copy link
Member Author

肯定的,On2的复杂度

//Get return instances cache by criteria
func (ic *IndexCache) Get(k string, tags map[string]string) ([]*MicroServiceInstance, bool) {

@daqingshu
Copy link
Contributor

todo: ref tinylfu/sampled lfu caffeine

@chenwei113524
Copy link
Contributor

用空间换时间,将Get的复杂度由On2降为On,但是Set的复杂度由On上升为On2
1、修改前BenchmarkIndexCacheGet
image
2、修改后BenchmarkIndexCacheGet
image

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

No branches or pull requests

4 participants