如何使用C#vb.net控制内存DB消耗中的SQLite [英] How to control SQLite in memory DB consumption using C# vb.net

查看:96
本文介绍了如何使用C#vb.net控制内存DB消耗中的SQLite的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有100 GB的数据.我想在VB.Net中使用SQLite将其加载到内存中.我有32 GB的RAM.我希望SQLite占用24 GB的RAM,而其他8 GB仍可用于其他OS任务.当它达到24 GB RAM限制时,它应该开始自动将数据刷新到某些磁盘文件中.

首先:我使用了内存数据库.

First: I used in-memory DB.

Dim cn As SQLiteConnection = New SQLiteConnection("Data Source=:memory:")

但是它消耗31.8 GB的RAM,然后OS(Windows 7)进入并控制并开始使用虚拟内存(将数据保存到磁盘).但这确实确实减慢了计算机的速度.简而言之,当何时使用内存方法加载大量数据时,SQLite会消耗掉所有内存并停止计算机.

But it consumes 31.8 GB RAM, and then OS (Windows 7) jump in and takes the control and start using virtual memory (which saves data to disk). But it really really slows down the Computer. In short when to load huge data (by using in-memory method), SQLite eats up all ram and halts the computer.

第二:我使用临时数据库加载了数据.

Second: I loaded the data using temporary DB.

Dim cn As SQLiteConnection = New SQLiteConnection("FullUri=file:")

但是,当SQLite消耗了将近2GB的RAM时,它将通过将数据刷新到文件"C:\ Users \ Administrator \ AppData \ Local \ Temp \ etilqs_d4Fsx23dc"来释放它并开始加载下一个数据.简而言之,当通过临时DB方法加载大量数据时,它使用的RAM更少,磁盘更多.

But when SQLite consumed near 2GB RAM it frees it by flushing data to file "C:\Users\Administrator\AppData\Local\Temp\etilqs_d4Fsx23dc" and start loading next data. In short when to load huge data (by using temporary DB method), it uses very less RAM and More Disk.

第一种情况会消耗所有内存,第二种情况会消耗很少的RAM.我需要中间的方式来控制自己,等等.SQLite为24 GB RAM,操作系统为8 GB,当达到24 GB RAM限制时,它将开始自动将数据刷新到磁盘文件中.

First scenario eats all ram and second consumes very less RAM. I need middle way that should be in my own control etc. 24 GB RAM for SQLite and 8 GB for OS, when it hits the 24 GB RAM limit, It should start flushing data to disk file automatically.

推荐答案

要控制SQLite用于磁盘数据库的内存量,请使用

To control the amount of memory that SQLite uses for an on-disk database, use PRAGMA cache_size. However, any unused memory will be used by the OS for the file cache, so SQLite's cache should not be set too large.

要加快对磁盘的写入速度(但要使其与内存数据库一样不可靠),请使用

To speed up writes to disk (but make them as unreliable as with an in-memory database), use PRAGMA journal_mode = OFF.

这篇关于如何使用C#vb.net控制内存DB消耗中的SQLite的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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