简体   繁体   English

在 Memory 数据库中

[英]In Memory Database

I'm using SqlServer to drive a WPF application, I'm currently using NHibernate and pre-read all the data so it's cached for performance reasons.我正在使用 SqlServer 来驱动 WPF 应用程序,我目前正在使用 NHibernate 并预读取所有数据,因此出于性能原因将其缓存。 That works for a single client app, but I was wondering if there's an in memory database that I could use so I can share the information across multiple apps on the same machine.这适用于单个客户端应用程序,但我想知道 memory 数据库中是否有我可以使用的数据库,以便我可以在同一台机器上的多个应用程序之间共享信息。 Ideally this would sit below my NHibernate stack, so my code wouldn't have to change.理想情况下,这将位于我的 NHibernate 堆栈下方,因此我的代码不必更改。 Effectively I'm looking to move my DB from it's traditional format on the server to be an in memory DB on the client.实际上,我希望将我的数据库从服务器上的传统格式移动到客户端上的 memory 数据库中。

Note I only need select functionality.注意我只需要 select 功能。

I would be incredibly surprised if you even need to load all your information in memory.如果您甚至需要将所有信息加载到 memory 中,我会感到非常惊讶。 I say this because, just as one example, I'm working on a Web app at the moment that (for various reasons) loads thousands of records on many pages.我这么说是因为,举个例子,我目前正在开发一款 Web 应用程序,该应用程序(由于各种原因)在许多页面上加载了数千条记录。 This is PHP + MySQL.这是 PHP + MySQL。 And even so it can do it and render a page in well under 100ms.即便如此,它也可以在 100 毫秒内完成并渲染页面。

Before you go down this route make sure that you have to.在您沿着这条路线走 go 之前,请确保您必须这样做。 First make your database as performant as possible.首先使您的数据库尽可能高性能。 Now obviously this includes things like having appropriate indexes and tuning your database but even though are putting the horse before the cart.现在显然这包括诸如拥有适当的索引和调整数据库之类的事情,但即使是本末倒置。

First and foremost you need to make sure you have a good relational data model: one that lends itself to performant queries.首先,你需要确保你有一个良好的关系数据 model:一个适合于高性能查询的数据。 This is as much art as it is science.这既是艺术,也是科学。

Also, you may like NHibernate but ORMs are not always the best choice .此外,您可能喜欢 NHibernate 但ORM 并不总是最佳选择 There are some corner cases, for example, that hand-coded SQL will be vastly superior in.例如,在某些极端情况下,手工编码的 SQL 会非常出色。

Now assuming you have a good data model and assuming you've then optimized your indexes and database parameters and then you've properly configured NHibernate, then and only then should you consider storing data in memory if and only if performance is still an issue .现在假设您有一个良好的数据 model 并假设您已经优化了索引和数据库参数,然后您已经正确配置了 NHibernate,那么只有这样您才应该考虑将数据存储在 ZCD69B4957F06CD818D82.917BF3D6198 中,并且仅当性能仍然存在时

To put this in perspective, the only times I've needed to do this are on systems that need to perform millions of transactions per day.从这个角度来看,我需要这样做的唯一时间是在需要每天执行数百万笔交易的系统上。

One reason to avoid in-memory caching is because it adds a lot of complexity.避免内存缓存的一个原因是它增加了很多复杂性。 You have to deal with issues like cache expiry, independent updates to the underlying data store, whether you use synchronous or asynchronous updates, how you give the client a consistent (if not up-to-date) view of your data, how you deal with failover and replication and so on.您必须处理诸如缓存到期、对底层数据存储的独立更新、使用同步还是异步更新、如何为客户端提供一致(如果不是最新)数据视图、如何处理等问题具有故障转移和复制等功能。 There is a huge complexity cost to be paid.需要付出巨大的复杂性成本。

Assuming you've done all the above and you still need it, it sounds to me like what you need is a cache or grid solution.假设您已完成上述所有操作并且仍然需要它,那么在我看来,您需要的是缓存或网格解决方案。 Here is an overview of Java grid/cluster solutions but many of them (eg Coherence, memcached) apply to.Net as well.这是Java 网格/集群解决方案的概述,但其中许多(例如 Coherence、memcached)也适用于.Net。 Another choice for.Net is Velocity . .Net 的另一个选择是Velocity

It needs to be pointed out and stressed that something like NHibernate is only consistent so long as nothing externally updates the database and that there is exactly one NHibernate-enabled process (barring clustered solutions).需要指出并强调的是,像 NHibernate 这样的东西只有在没有任何外部更新数据库并且只有一个启用 NHibernate 的进程(除非集群解决方案)的情况下是一致的。 If two desktop apps on two different PCs are both updating the same database with NHibernate the caching simply won't work because the persistence units simply won't be aware of the changes the other is making.如果两台不同 PC 上的两个桌面应用程序都使用 NHibernate 更新同一个数据库,则缓存将无法正常工作,因为持久性单元根本不会知道另一个正在进行的更改。

You can use HANA, express edition.您可以使用HANA,快递版。 You can download it for free , it's in-memory, columnar and allows for further analytics capabilities such as text analytics, geospatial or predictive.您可以免费下载它,它是内存中的、柱状的,并允许进一步的分析功能,例如文本分析、地理空间或预测。 You can also access with ODBC, JDBC, node.js hdb library, REST APIs among others.您还可以使用 ODBC、JDBC、node.js hdb 库、Z50780F47F65800D47D60BC4 等访问

http://www.db4o.com/ can be your friend! http://www.db4o.com/可以成为你的朋友!

Velocity is an out of process object caching server designed by Microsoft to do pretty much what you want although it's only in CTP form at the moment. Velocity是一个进程外的 object 缓存服务器,由 Microsoft 设计,几乎可以满足您的需求,尽管目前它只是 CTP 形式。

I believe there are also wrappers for memcached, which can also be used to cache objects.我相信memcached也有包装器,也可以用来缓存对象。

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

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