Comments (6)
`
*/
func (r *RuleEntity) Execute(dc *context.DataContext) (interface{}, error, bool) {
// r.Vars = make(map[string]reflect.Value)
// defer r.clearMap()
v, e, b := r.RuleContent.Execute(dc, make(map[string]reflect.Value))
if v == reflect.ValueOf(nil) {
return nil, e, b
}
return v.Interface(), e, b
}
func (r *RuleEntity) clearMap() {
// r.Vars = make(map[string]reflect.Value)
}
`
我改成这样的方式,就没有再重现这个问题了,你们可以自己执行一下压测试试。
from gengine.
感谢你的测试!
并发读写了同一个map,而不加锁,所以会出现问题。
在“最佳实践文”文档里有多次提到,gengine能保证规则更新等针对引擎自身的操作 线程安全;但对于用户要并发访问非线程安全的数据结构(如普通map),gengine是无法保证其线程安全的。
推荐做法有几种(这其实是所有编程语言的通用做法):
1.不要共享变量
2.使用并发安全的数据结构
3.使用无状态函数
最佳实践文档:
https://github.com/bilibili/gengine/wiki/%E6%9C%80%E4%BD%B3%E5%AE%9E%E8%B7%B5
from gengine.
不是哦,不是用户的并发访问,用的是引擎池的ExecuteSelectedRulesWithControlAndStopTag方法,完全是一个无状态的接口,也不涉及到map的访问。
我压测的时候,是全部执行的同一个规则。
from gengine.
非常感谢你的回复!你的说法是对的。
在之前的老版本,因为每个实例独自使用自己的rule_entity, 所以将 r.Vars放在结构体中是不会有并发安全的问题;
后来为了提高规则编译性能,降低内存使用率,所以无状态的rule_entity是pool内多实例共享的,如果这个时候还将Vars放在结构体层次,就会导致并发安全问题。
期待你提个MR:删除RuleEntity中的Vars,然后按照你上面的写法,注释或删除掉你注释的代码行,并删除func (r *RuleEntity) clearMap()函数。
再次感谢你的反馈。
from gengine.
两天没等到大佬您,我只好自己提交修复了
from gengine.
@rencalo770 你好,大佬, 对于规则池的最佳实践,在高并发方面有些疑问,麻烦解答一下;
1: 此框架能否用于高并发的业务场景,我想引入此规则引擎到实时推荐中,QPS在3万左右。
2: 在规则池的最佳实践中,规则池的大小是否需要根据QPS 来设置呢, 如果QPS =3万, 那规则池的大小是否应该设置大于3万。
3: 贵公司是否在 有将此框架用于实时推荐的业务场景,能够共享一下经验,主要还是担心数据并发安全问题。
以上, 期待您的尽快回复, 谢谢!
from gengine.
Related Issues (20)
- 还有人在维护么,看最近一次提交是21年8月份 HOT 3
- ruleBuilder 构建后 传入进方法的map 添加的key value 添加不进去
- 能不能分享一下实际项目使用了gengine,参考一下 HOT 4
- 什么叫规则执行出错? 一致没查到是什么场景
- 流程图、应用场景举例
- isNil() 问题
- wiki中文文档链接失效
- rule执行go的function时,支持返回多个值吗? HOT 3
- 规则可以外部获取吗?
- 是否考虑更新依赖到“github.com/antlr/antlr4/runtime/Go/antlr/v4”模块 HOT 1
- Concurrent map NEEDED FOR GENGINE\
- 生产环境中runBuilder.BuildRuleFromString 初始化时,构建的规则量级较大耗时比较高,这种情况下有处理建议么? HOT 4
- 如何做到先初始化完全局规则,后根据业务场景动态对请求data进行校验? HOT 1
- 规则引擎并发安全问题咨询 HOT 1
- 有处理规则数量级特别大的场景吗? 规则全注册到内存中消耗太大 HOT 2
- 错误问题,关闭 HOT 1
- nConcurrentMSort 模式下 b 参数影响了规则正常执行
- RuleBuilder 是否支持动态变更 dataContext?
- 引擎池只能修改规则吗?可以新增规则 吗
- 有qq群可以交流问题吗,想要接入,有挺多问题想咨询的,之前的群搜不到了
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 gengine.