您将学到什么:
- Where in-memory databases are used (spoiler: everywhere!).
- Suitability of in-memory databases for microcontrollers.
- Risks and mitigation of data loss.
- 内存数据库与数据库缓存不同。
Steven Graves, president ofMcObject,揭露了有关内存数据库技术的一些神话和错误信息。
1.内存数据库将不适合微控制器。
内存数据库可以并且确实适合在各种应用领域(例如工业自动化和运输)中的微控制器。beplay体育手机登录内存中数据库系统可以非常紧凑(低于500k代码大小),如下面的《神话3》中提到的,请使用可用的内存。嵌入式系统中的微控制器通常无法管理很多数据(因此不需要很多内存),但是数据仍然不同且相关,因此它受益于数据库技术。
For reference, the桌子below shows some publicly available code-size estimates for a few different in-memory database systems. Keep in mind that code size depends on the target CPU, compiler, and compiler optimizations employed.
2。内存数据库不会扩展。
There are two dimensions to scalability: horizontal and vertical. Vertical scalability means getting a bigger server to handle a growing database. While RAM is certainly more expensive than other storage media, it’s not uncommon to see servers with terabytes of memory. Ipso facto, in-memory databases can scale vertically into the terabytes.
Horizontal scalability means the ability to shard/partition a database and spread it over multiple servers while still treating the federation as a single logical database. This applies equally to in-memory databases.
3.内存数据库可能会丢失您的数据(并非持久)。
在没有任何缓解因素的情况下,当该过程终止或重新启动系统时,内存数据库确实会“消失”。但是,这可以通过几种方式解决:
- 在关闭之前快照数据库(并在下一个启动之后重新加载它)。
- Combine #1 with transaction logging to persistent media to protect against an abnormal termination.
- 使用NVDIMM(RAM与Flash,SuperCapacitor和固件相结合,将RAM倒入电源损耗时闪烁,并在RESTART时复制回RAM)。
- 使用持续记忆A La Intel的Optane。
4.内存数据库与将数据库放在RAM驱动器中相同。
错误的。真正的内存数据库被优化为这样。持久数据库被优化为这样。这些优化是截然相反的。优化了内存数据库以最大程度地减少CPU周期(毕竟,您使用内存数据库,因为您需要最大的速度),并最大程度地减少存储任何给定数据量的数据所需的空间。相反,持久数据库将使用额外的CPU周期(例如,通过维护缓存)和空间(通过将索引数据存储在索引结构中)来最小化I/O,因为I/O是最慢的操作。
5. In-memory databases are the same as caching 100% of a conventional database.
Also false. Caching 100% of a conventional database will improve read (query) performance but will do nothing to improve insert/update/delete performance. And, maintaining a cache means having extra logic that a persistent database needs for a least-recently-used (LRU) index—an index to know if a requested page is in cache, or not (a DBMS doesn’t “know” that you’re caching the entire database; it needs to carry out this logic regardless), marking pages as “dirty” and so on.
6.内存数据库仅适用于极少数和特定的用例。
内存数据库几乎用于您可以想象的所有工作负载。常见应用包括消费电子产品,工业自动化,网络/电信基础设施设备,金融技术,自动驾驶汽车(地面/海上/空beplay体育手机登录气),航空电子产品等。
7. In-memory databases are more susceptible to corruption.
内存数据库并不比任何其他类型的数据库更容易受到损坏,也许更少。持久媒体上的数据库可以被流氓或恶毒过程“涂抹”,从而破坏它们。与文件系统提供的文件相比,操作系统为内存提供了更多的保护。
8.内存数据库如果已满,将崩溃。
A well-written in-memory database will handle an out-of-memory condition as gracefully as a well-written persistent database handles a disk becoming full. Ideally, an in-memory database doesn’t allocate memory dynamically; rather, memory is allocated up-front and memory required for the in-memory database is doled out from that initial memory pool as needed.
这种方法消除了比用户/系统限制允许的内存更多的可能性。它还消除了内存泄漏影响系统内存数据库在系统中运行的系统的其他部分的可能性。
9.内存数据库可以消耗所有系统内存。
写得很好的数据库不应动态分配存储空间(通用物质可能是另一个故事)。对于内存数据库的存储空间(内存)应在启动时一次分配。如果填充填充,则内存数据库系统应报告该事实,并允许应用程序确定下一步(修剪一些数据,分配其他内存,优美的关闭等)。
10. In-memory databases are very fast, therefore suitable for real-time systems.
Real-time systems break down into two classes: soft real-time and hard real-time. In-memory databases can be suitable for soft real-time systems. Hard real-time systems require more than just speed—they require determinism. That, in turn, requires a time-cognizant database system, i.e., one that’s aware of, and can manage, real-time constraints (deadlines). It also has become fashionable to advertise in-memory databases as “real-time,” which has become synonymous with “real fast” but has no relationship to soft or hard real-time systems.
11. It doesn’t make sense to have an in-memory client/server database.
Refer to Myth #1. An in-memory database that’s sharded/partitioned practically requires a client/server architecture. Therefore, client application(s) can be isolated from the physical topology of the distributed system, including any changes to it (e.g., to scale it horizontally).