业务逻辑/规则 - 在数据库或内存中处理
由于我过于傲慢,我正在开发一个程序,该程序可以比我们当前使用的当前系统更好地处理一些数据。我的问题是,何时实现业务规则(即,如果这条数据与发送到该队列的模式相匹配),最佳实践是:
在程序启动时简单地将所有规则从数据库加载到内存中
积极:非常快
负面:该程序将分配规则,因此可能会占用大量内存
将所有规则放入数据库并允许在数据库中完成匹配 正面
:不使用大量内存
负面:大量数据库调用
内存中有一个标志,可以调用数据库中的特定规则。
积极:没有大量内存
消极:仍然有很多数据库调用
有任何想法
because of my over abundance of hubris, I am working on a program that would process some of the data better than the current system we are currently using. My question is when the implementing business rules (i.e. if this piece of data matches this pattern send to this que) is it best practice to:
simply load all the rules into memory from a DB when the program starts
positive: very fast
negative: this program would have allot of rules so could be a memory hog
have all the rules into a database and allow the matching to be done in the database
positive: not using a ton of memory
negative: lots of database calls
have a flag in memory that would call to a specific rule in the database.
positive: not a ton of memory
negative: still a lot of database calls
Any thoughts
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您忘记了两个极端的混合体——更智能的缓存(比内存中的一切都聪明)。
不使用规则(或一些最流行的规则)初始化缓存。
应用程序从缓存中请求规则。
如果缓存中存在,则返回。
如果没有,则从数据库加载,存储在缓存中,然后返回给用户。
You forgot about the hybrid of your two extremes -- a smarter cache (smarter than everything in memory).
Initialize the cache with no rules (or a few of the most popular).
The app requests a rule from the cache.
If it exists in the cache, return it.
If not, load it from the database, store it in cache, and return it to the user.
与所有与性能相关的事情一样,您需要尝试各种选项并衡量它们的性能。很难提前判断哪一种最适合您。
最新趋势之一是内存数据库。在数据库中进行 BI 和分析,该数据库将整个所需的数据集保存在内存中。我们谈论的是千兆字节的 RAM。
您可以考虑这个选项,因为它不再是异国情调。现在 RAM 很便宜。也许它对你有用。你需要尝试一下。
As with everything performance-related, you need to try options and measure their performance. It is very hard to tell in advance which one will work best for you.
One of the latest trends is in-memory databases. Doing BI and analytics in the database which holds the entire needed dataset in memory. We're talking about gigabytes of RAM.
You could consider this option knowing it is not exotic any more. RAM is cheap these days. Maybe it will work for you. You need to try it out.