为什么有人需要内存数据库?

发布于 2024-09-04 01:06:49 字数 68 浏览 2 评论 0原文

我读到一些数据库可以在内存中使用,但无法想到为什么有人想要使用此功能。我总是使用数据库来保存数据和内存缓存以实现快速访问。

I read that a few databases can be used in-memory but can't think of reason why someone would want to use this feature. I always use a database to persist data and memory caches for fast access.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(11

谁把谁当真 2024-09-11 01:06:49

缓存也是一种数据库,就像文件系统一样。 “内存缓存”只是内存数据库的一种具体应用,有些内存数据库专门用作内存缓存。

内存数据库的其他用途已经包含在其他答案中,但让我也列举一下用途:

  1. 内存缓存。通常会使用专门用于该用途的数据库系统(可能称为“内存缓存”而不是“数据库”)。
  2. 测试数据库相关代码。在这种情况下,通常会使用某些通用数据库系统的“内存中”模式,但也可以使用专用的“内存中”数据库来替换其他“磁盘上”数据库以进行更快的测试。
  3. 复杂的数据操作。内存中的 SQL 数据库通常以这种方式使用。 SQL 是一个很好的数据操作工具,有时在计算最终结果时不需要将数据写入磁盘。
  4. 存储瞬态运行时状态。有些应用程序需要将其状态存储在某种数据库中,但不需要在应用程序重新启动时保留该状态。考虑某种流程管理器 - 它需要跟踪子流程的运行,但该数据仅在应用程序和子流程运行时才有效。

Cache is also a kind of database, like a file system is. 'Memory cache' is just a specific application of an in-memory database and some in-memory databases are specialized as memory caches.

Other uses of in-memory databases have already been included in other answers, but let me enumerate the uses too:

  1. Memory cache. Usually a database system specialized for that use (and probably known as 'a memory cache' rather than 'a database') will be used.
  2. Testing database-related code. In this case often an 'in-memory' mode of some generic database system will be used, but also a dedicated 'in-memory' database may be used to replace other 'on-disk' database for faster testing.
  3. Sophisticated data manipulation. In-memory SQL databases are often used this way. SQL is a great tool for data manipulation and sometimes there is no need to write the data on disk while computing the final result.
  4. Storing of transient runtime state. There are application that need to store their state in some kind of database but do not need to persist that over application restart. Think of some kind of process manager – it needs to keep track of sub-processes running, but that data is only valid as long as the application and the sub-processes run.
风尘浪孓 2024-09-11 01:06:49

一个常见的用例是运行单元/集成测试。

您并不真正关心每次测试运行之间的持久数据,并且您希望测试尽可能快地运行(以鼓励人们经常进行测试)。在进程中托管数据库可以让您非常快速地访问数据。

A common use case is to run unit/integration tests.

You don't really care about persisting data between each test run and you want tests to run as quickly as possible (to encourage people to do them often). Hosting a database in process gives you very quick access to the data.

方圜几里 2024-09-11 01:06:49

你的内存缓存有 SQL 支持吗?

您是否认为内存数据库是一个非常聪明的缓存?

这确实留下了如何填充内存数据库、如何管理更新以及如何在多个实例之间保持一致性的问题。

Does your memory cache have SQL support?

How about you consider the in-memory database as a really clever cache?

That does leave questions of how the in-memory database gets populated and how updated are managed and consistency is preserved across multiple instances.

谎言 2024-09-11 01:06:49

如果不使用索引等技巧,在 100000 个元素中搜索某些内容会很慢。这些技巧已经在数据库引擎中实现(无论是持久的还是内存中的)。

内存数据库可能提供比您通过自己编写的结构快速实现的搜索功能更有效的搜索功能。

Searching for something among 100000 elements is slow if you don't use tricks like indexes. Those tricks are already implemented in a database engine (be it persistent or in-memory).

A in-memory database might offer a more efficient search feature than what you might be able to implement yourself quickly over self-written structures.

情绪 2024-09-11 01:06:49

对于通用(读取端)查询,内存数据库比传统 RDBMS 大约快至少一个数量级。大多数都是磁盘支持的,提供与普通 RDBMS 完全相同的一致性 - 仅捕获整个数据集必须适合 RAM。

核心思想是磁盘支持的存储具有巨大的随机访问惩罚,这不适用于 DRAM。数据可以以随机访问优化的方式进行索引/组织,而使用传统的 RDBMS 数据缓存方案是不可行的。

In-memory databases are roughly at least an order of magnitude faster than traditional RDBMS for general purpose (read side) queries. Most are disk backed providing the very same consistency as a normal RDBMS - only catch the entire dataset must fit into RAM.

The core idea is disk backed storage has huge random access penalties which does not apply to DRAM. Data can be index/organized in a random access optimized way not feasible using traditional RDBMS data caching schemes.

洋洋洒洒 2024-09-11 01:06:49

需要实时响应的应用程序希望使用内存数据库,也许是控制响应时间至关重要的飞机、工厂的应用程序

Applications, which require real time responses would like to use an in memory database, perhaps application to control aircraft, plants where the response time is critical

空名 2024-09-11 01:06:49

内存数据库在游戏编程中也很有用。您可以将数据存储在内存数据库中,这比永久数据库快得多。

An in memory database is also useful in game programming. You can store data in an in memory database which is much faster than permanent databases.

半窗疏影 2024-09-11 01:06:49

它们用作高级数据结构来存储、查询和修改运行时数据。

They are used as an advanced data structure to store, query and modify runtime data.

寻找我们的幸福 2024-09-11 01:06:49

如果多个不同的应用程序要访问数据集,您可能需要一个数据库。数据库具有用于访问/修改数据的一致接口,而哈希表(或您使用的其他任何东西)则没有。

如果单个程序正在处理数据,那么无论您使用什么语言,都可以合理地使用数据结构。

You may need a database if several different applications are going to access the dataset. A database has a consistent interface for accessing / modifying data, which your hash table (or whatever else you use) won't have.

If a single program is dealing with the data, then it's reasonable to just use a data structure in whatever language you are using though.

春风十里 2024-09-11 01:06:49

内存数据库比执行数据库缓存更好。
在 READ 操作方面,数据库缓存的工作原理与内存数据库类似。

另一方面,当涉及到 WRITE 操作时,内存数据库比数据库缓存更快,后者的数据保存在磁盘上(这会导致 IO 开销)。

此外,使用数据库缓存,您可能会出现缓存未命中的情况,但在使用内存数据库时,您永远不会出现缓存未命中的情况。

In-memory database is better than performing database caching.
Database caching works similar to in-memory databases when it comes to READ operations.

On the other hand, when it comes to WRITE operations, in-memory databases are faster when compared to database caches, where the data is persisted onto disk (which leads to IO overhead).

Also, with database caching you can end with cache misses but you will never end up with cache misses when using in-memory databases.

别把无礼当个性 2024-09-11 01:06:49

考虑到它们的速度和 RAM 价格的下降,内存数据库很可能成为未来的主导技术。已经有一些开发了复杂的功能,例如 SQL 查询、二级索引和用于处理大于 RAM 的数据集的引擎。

Given their speed and the declining price of RAM, it’s likely that in-memory databases will become the dominant technology in the future. There are already some that have developed sophisticated features like SQL queries, secondary indexes, and engines for processing datasets larger than RAM.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文