键值数据库 [英] Key-Value Database

查看:157
本文介绍了键值数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要存储短字符串(50个以上的字符),并快速查找它们。起初我想为此使用SQLite。我使用一个索引的TEXT列创建了一个表。使用各种低级技巧,我可以在10秒钟内填充数据库中的一百万个字符串。



问题是,如果PC重新启动,再增加一个10.000行花费了30秒,这与10秒内的1M行无关。原因是SQLite在添加新行之前必须从磁盘读取现有索引的很大一部分。另一个问题是数据库的大小增加了一倍,因为所有的字符串由于b-tree机制而被存储了两次(一次在常规表中,一次在索引表中)。



<有没有简单的选择?例如,使用基于散列的查找?我知道各种NoSQL解决方案,但他们专注于分布式和分布式存储,而我只需要一个简单的嵌入式'平面文件'数据库?

解决方案

将最新值保存到磁盘有多关键?

您可以使用内存集合,如Dictionary或List,并通过序列化它到一个定期的异步调用中的本地文件。

然后,当你的应用程序启动时,你可以反序列化它回到记忆中。



这将是一种更为快速响应的方式,可以帮助您完成后续工作,因为您不必随时通过读/写操作继续刻录磁盘。


I need to store short strings (50+ characters), and quickly look them up. At first I wanted to use SQLite for this. I created a single table with a single indexed TEXT column. Using all kinds of low-level tricks I could fill the database with 1 million strings in 10 seconds.

The problem was that if the PC was rebooted, adding an additional 10.000 rows took 30 seconds, which is nowhere in line with 1M rows in 10s. The reason for this is that SQLite has to read a very large part of the existing index from disk, before it can add the new rows. Another problem is that the database doubles in size, because all strings are stored twice (once in the regular table, once in the index table) because of the b-tree mechanism.

Is there a simple alternative? Which uses hash-based lookups for example? I know about the various NoSQL solutions, but they are focussed at decentral and distributed storage, while I just need a simple embedded 'flat-file' database?

解决方案

How critical is it to persist the latest values to disk?

You can use an in-memory collection such as Dictionary or List and persist it to disk by serializing it to a local file in an ansynchronous call at regular intervals.

Then when your application starts you can deserialize it back into memory.

This would be a far more responsive way to accomplish what you are after as you dont have to keep hammering the disk all the time with read/write efforts.

这篇关于键值数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆