🫕配置并发设计
# 说明
这里的配置是DashBoard中的模板在发布配置后会自动为应用生成一个基于JSON
的模板配置,通过Longpolling
同步到框架SDK中
(ConcurrentHashMap
)。
# 思考
那么大家有想过,在程序运行过程中,存在于内存缓存中的配置信息在被高并发的大量请求访问,这时候如果发布模板配置将内存中的配置进行更新 会产生什么影响? 答案是明确的: 会产生并发安全问题。 那么Cube使用的手段是什么呢?
- 并发安全类
- 读写分离
# 框架是怎么解决的
框架内部维护这一套读写分离的缓存对象,长链接通过监听管理端的配置变更更新的只是WRITE副本中的内容。 在更新完成之后在通过属性 赋值的方式赋值给READ配置中,这样将大大提高更新并发吞吐量。提升系统在配置变更时的访问性能。
如下配置存储对象:
public class CubeConfigStore {
/**
* key floorCode
* value Floor
*/
public static ConcurrentMap<String, Floor> CUBE_FLOORCODE_FLOOR = new ConcurrentHashMap<>();
/**
* key templateId
* value floorCode
*/
public static ConcurrentMap<String, Template> CUBE_TEMPLATE_FLOOR_READ = new ConcurrentHashMap<>();
/**
* The constant ISV_REMOTE_CONFIG_SET.
*/
public static ConcurrentMap<String, Set<RemoteConfig>> CUBE_REMOTE_CONFIG_SET = new ConcurrentHashMap<>();
/**
* The constant FLOOR_ABILITY.
*/
public static ConcurrentMap<String, List<DomainService.Ability>> FLOOR_ABILITY_READ = new ConcurrentHashMap<>();
/**
* The constant FLOOR_DOMAINS.
*/
public static ConcurrentMap<String, List<DomainService>> FLOOR_DOMAINS_READ = new ConcurrentHashMap<>();
/**
* The constant FLOOR_COMPONENTS.
*/
public static ConcurrentMap<String, List<Component>> FLOOR_COMPONENTS_READ = new ConcurrentHashMap<>();
/**
* The constant FLOOR_REMOTE_CONFIG.
*/
public static ConcurrentMap<String, Set<RemoteConfig>> FLOOR_REMOTE_CONFIG_READ = new ConcurrentHashMap<>();
/**
* The constant ISV_TEMPLATE_FLOOR_WRITE.
*/
public static ConcurrentMap<String, Template> CUBE_TEMPLATE_FLOOR_WRITE = new ConcurrentHashMap<>();
/**
* The constant FLOOR_ABILITY.
*/
public static ConcurrentMap<String, List<DomainService.Ability>> FLOOR_ABILITY_WRITE = new ConcurrentHashMap<>();
/**
* The constant FLOOR_DOMAINS.
*/
public static ConcurrentMap<String, List<DomainService>> FLOOR_DOMAINS_WRITE = new ConcurrentHashMap<>();
/**
* The constant FLOOR_COMPONENTS.
*/
public static ConcurrentMap<String, List<Component>> FLOOR_COMPONENTS_WRITE = new ConcurrentHashMap<>();
/**
* The constant FLOOR_REMOTE_CONFIG.
*/
public static ConcurrentMap<String, Set<RemoteConfig>> FLOOR_REMOTE_CONFIG_WRITE = new ConcurrentHashMap<>();
/**
* Clear.
*/
public static void clear() {
CUBE_FLOORCODE_FLOOR.clear();
CUBE_TEMPLATE_FLOOR_READ.clear();
CUBE_REMOTE_CONFIG_SET.clear();
}
}
帮助我们改善此文档 (opens new window)