简体   繁体   English

内存数据缓存中的.Net应用程序性能

[英]In Memory Data Cache for Performance in .Net Applications

We have an application (rules engine) that has a lot of tables in memory to perform certain business rules. 我们有一个应用程序(规则引擎),该应用程序在内存中有很多表可以执行某些业务规则。 This engine is also used for writing back to the database when needed. 该引擎还用于在需要时写回数据库。

The DB structure is denormalized, and we have 5 transactional tables, that also sometimes need to be queried for reporting. 数据库结构是非规范化的,我们有5个事务表,有时也需要查询这些表以进行报告。

The issue here is, we want to cache the data inside the app, so it loads on App startup, and then only changes if the DB changed. 这里的问题是,我们希望将数据缓存在应用程序内部,以便在应用程序启动时加载,然后仅在数据库更改时才更改。

Any recommendations? 有什么建议吗?

We are leaning towards creating a DB service, that will handle all Inserts, Updates and Deletes, and queue them to decrease load on the DB server (the transactional tables have loads of indexes also). 我们倾向于创建一个数据库服务,该服务将处理所有插入,更新和删除,并将它们排队以减少DB服务器上的负载(事务表也具有索引负载)。 Also, we are thinking of enabling the DB service to sit on top and serve all reports / other apps that need direct DB access. 另外,我们正在考虑使数据库服务位于最上方,并为所有需要直接数据库访问的报表/其他应用程序提供服务。

The aim here ofcourse is to decrease DB hits for Select queries per request, and prioritize transactions. 当然,这样做的目的是减少每个请求的“选择”查询的数据库命中率,并优先处理事务。 Also to ensure people accessing apps dont bring the DB server down. 还要确保访问应用程序的人员不会关闭数据库服务器。

Rules Engine is a C# desktop app, reporting and other apps are web based. Rules Engine是C#桌面应用程序,报表和其他应用程序基于Web。

What would be the best way to go about this? 最好的方法是什么? I did also think of removing all indexes from my transactional table, and having a trigger insert into a new table which would be a copy, but indexed for report retrieval. 我也确实考虑过从事务表中删除所有索引,并将触发器插入到新表中,该表将是副本,但为报表检索而建立了索引。

I've done something similar with an obscenely complex rules engine. 我已经使用一个复杂的复杂规则引擎做了类似的事情。 Ultimately, I set it up so that the data was serialized centrally (with a process to release new changes, causing a new copy to be serialized and the blob stored somewhere accessible). 最终,我进行了设置,以便对数据进行集中式序列化(通过释放新更改的过程来进行,从而导致对新副本进行序列化并将blob存储在可访问的位置)。 During load, each app-server would check whether they have the up to date version of the blob, and if not fetch it (and store it locally). 在加载期间,每个应用服务器都会检查它们是否具有Blob的最新版本,如果没有,则将其获取(并将其存储在本地)。

Then all it has to do is deserialize the data into memory. 然后,它要做的就是将数据反序列化到内存中。 No db hit, except for occasionally grabbing the new blob. 没有数据库命中,除了偶尔抓住新的斑点。 It also means the app-server can work while the db server is offline (as long as it has a cached copy of the blob). 这也意味着应用程序服务器可以在db服务器处于脱机状态时工作(只要它具有blob的缓存副本)。 It also polled periodically for new updates while running, of course - but only to the "is there a new blob" code (it still didn't need to hit the main tables). 当然,它还会在运行时定期轮询是否有新的更新-但只轮询“是否有新的Blob”代码(它仍然不需要点击主表)。

You should perhaps look at distributed caching solutions (from both performance and scalability point of view). 您也许应该看一下分布式缓存解决方案(从性能和可伸缩性的角度来看)。 In short, I am taking about scalable DB Services backed by distributed cache (so that multiple DB services get served by same cache). 简而言之,我正在考虑由分布式缓存支持的可伸缩数据库服务(以便多个数据库服务由同一缓存提供)。

Here's the article that discusses distributed caching including various approaches for database synchronization. 本文讨论了分布式缓存,其中包括用于数据库同步的各种方法。 And here is the blog post that list few options in .NET for distributed caching. 这是博客文章,列出了.NET中用于分布式缓存的一些选项。

You may be interested in this article It uses xml to store a readonly copy of the database (in memory). 您可能对本文感兴趣,它使用xml来存储数据库的只读副本(在内存中)。 And XPath to query. 和XPath进行查询。 Nowadays you'd prefer to query with linq, of course. 当然,如今您更希望使用linq进行查询。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM