Comments (1)
目前zk在做服务注册发现的时候操作
RegistryDataCache
是在childEvent
中调用的。在这种情况下,无论是生产者还是消费者,其增删改事件都是在一个
watcher
线程顺序消费的,因此RegistryDataCache
的实现可以不是线程安全的,且不存在线程安全问题。但是registry那边的实现,是在Controller(tomcat线程池)中跟新cache
/** * 获取服务列表 * * @return */ @GetMapping("all") public List<ServiceModel> queryServiceList() { doRefreshCache(); List<ServiceModel> data = new ArrayList<>(); Map<String, RpcService> rpcServices = registryDataCache.fetchService(); for (Map.Entry<String, RpcService> rpcServiceEntry : rpcServices.entrySet()) { final String serviceName = rpcServiceEntry.getKey(); ServiceModel model = fetchServiceModel(serviceName); data.add(model); } return data; }此时由于
RegistryDataCache
实现地非线程安全,就可能会出现问题。解决方案是让
RegistryDataCache
实现变得线程安全,比如使用ConcurrentHashMap#compute
更新缓存map,或者添加轻量级锁比如stampedlock等。比如:
@Override public void addProviders(String serviceName, List<RpcProvider> providerList) { RpcService rpcService = services.get(serviceName); if (rpcService == null) { LOGGER.warn("receive provider registry data add, but service name is not exist now,{}", serviceName); return; } providers.compute(rpcService, (key, origin) -> { //This might be thread-safe if (origin == null) { return providerList; } List<RpcProvider> aggregate = new ArrayList<>(origin); aggregate.addAll(providerList); return aggregate; }); LOGGER.info("receive provider registry data add, data is {}", providerList); }
@chpengzh 感谢关注。这里其实确实会有线程安全问题:
- 对于 doRefreshCache 操作只会在 注册中心是 SOFARegitry 时才会对缓存操作起作用,对于 Zookeeper 则不会。
- 在 SOFARegitry 作为注册中心的情况,每次进入页面,都会对当前缓存进行清空,然后再拉取注册中心session数据,在多线程场景下,会引发线程安全问题。
关于这个点,还需要评估下是否在使用 SOFARegitry 情况下继续沿用 cache 机制,如果 SOFARegitry 本身数据了很大,对 Dashboard 来说缓存会造成一定的负担。后面会和 SOFARegitry 同学沟通优化方案
from sofa-dashboard.
Related Issues (20)
- 优化 SOFADashboard 获取动态模块插件方式
- 插件查询之后无法获取应用实例问题
- Probably memory leak risk HOT 2
- ZookeeperRegistryDataCacheImpl may be not threadSafe HOT 3
- The maven dependency dependency in the quick start is written as denpendency HOT 3
- there are problems executing `mvn install` commands HOT 2
- Front-end API and back-end controller do not match HOT 3
- Backend lacks dependencies, can't be packaged, help HOT 1
- TypeError: Cannot read property 'detail' of undefined HOT 2
- Hope to add dashboard support for k8s HOT 1
- we
- ark biz 安装后,前端不能正确显示状态 HOT 3
- 无法将类 com.alipay.sofa.dashboard.client.model.common.HostAndPort中的构造器 HostAndPort应用到给定类型;
- Quick Start Issues HOT 1
- 开源之夏-SOFADashboard 整体功能细分 HOT 5
- 为什么controller中,方法基本都是用@RequestMapping 不指定用@GetMapping或者@PostMapping等指定类型
- 服务面板中目前zookeeper当注册中心时 能获取到RPC服务列表,那如果是sofa-register 当注册中心 如何配置sofa-dashboard。 HOT 1
- npm install failed
- Update SOFABoot to 3.10.0
- 启动运行问题咨询 HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from sofa-dashboard.