System.Data.Sqlite:缓存大小=...连接字符串参数似乎不起作用

发布于 2024-11-08 04:54:16 字数 1084 浏览 0 评论 0原文

我正在比较磁盘和内存数据库的速度。我正在尝试使用以下连接字符串将大约 8mb 的数据插入到 sqlite3 数据库中:

<configuration>
    <connectionStrings>
      <add name="Server" connectionString="Data Source=db.db3;Version=3;" providerName="System.Data.SQLite" />
   </connectionStrings>
</configuration>

它会在大约 4 秒内插入我的数据。

当我将连接字符串更改为以下字符串时:

<configuration>
    <connectionStrings>
      <add name="Server" connectionString="Data Source=:memory:;Version=3;" providerName="System.Data.SQLite" />
   </connectionStrings>
</configuration>

我在大约 0.5 秒内插入了数据。

但是,当我按照以下方式更改设置时(注意Cache Size=16777216),

<configuration>
    <connectionStrings>
      <add name="Server" connectionString="Data Source=db.db3;Version=3;Cache Size=16777216;" providerName="System.Data.SQLite" />
   </connectionStrings>
</configuration>

结果又是 4 秒,并且结果与缓存量无关。根据我的理解,缓存大小是数据量的两倍应该会使我的数据在内存中稳定下来。当没有更多缓存剩余时,应该发生磁盘迁移...

如何使 sqlite 响应更快?

I'm comparing speeds of disk and in-memory databases. I'm trying to insert approximately 8mb of data to a sqlite3 db with the following connection string:

<configuration>
    <connectionStrings>
      <add name="Server" connectionString="Data Source=db.db3;Version=3;" providerName="System.Data.SQLite" />
   </connectionStrings>
</configuration>

It gets my data inserted in around 4 seconds.

When I change my connection string to the following one:

<configuration>
    <connectionStrings>
      <add name="Server" connectionString="Data Source=:memory:;Version=3;" providerName="System.Data.SQLite" />
   </connectionStrings>
</configuration>

I get my data inserted in around 0.5 seconds.

But when I change the settings the following way (note Cache Size=16777216)

<configuration>
    <connectionStrings>
      <add name="Server" connectionString="Data Source=db.db3;Version=3;Cache Size=16777216;" providerName="System.Data.SQLite" />
   </connectionStrings>
</configuration>

This results 4 seconds again, and result is independent of the amount of cache. In my understanding having the cache size twice as large as the amount of data should make my data settle in memory. And disk migrations should occur when no more cache left...

How can I make sqlite more responsive?

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

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

发布评论

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

评论(2

池予 2024-11-15 04:54:16

它比较慢,因为:内存意味着数据库在内存中,磁盘总是会比较慢。您可以通过将插入包装在事务中来加快速度,因为它只会在事务结束时刷新到磁盘一次。翻转交易日志也会有所帮助,但会使其更容易因崩溃和断电而出现问题。

缓存不太可能加快任何速度,因为您不会多次使用同一数据页。

It's slower because :memory means the database in memory, disk will always be slower. You may be able to speed things up a bit by wrapping the inserts in a transaction as it will only flush to disk once at the end of the transaction. Turning of the transaction journal will help as well but will make it more prone to issues due to crashes and power loss.

It's unlikely the cache will speed anything up because you aren't using the same page of data more than once.

生生漫 2024-11-15 04:54:16

根据 SQL Lite 文档,缓存大小的设置仅是建议。 “是否遵守此建议由应用程序定义的页面缓存自行决定”

According to the SQL Lite Documentation the setting of cache size is a suggestion only. "Whether or not this suggestion is honored is at the discretion of the Application Defined Page Cache"

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