简体   繁体   English

Python内存数据库溢出

[英]Python in-memory database overflow

I couldn't find an answer online, so here it goes. 我无法在线找到答案,所以就到这里了。 I'm developing a SAAS that creates a temporary in-memory SQLITE3 database on the cloud for each user. 我正在开发一个SAAS,可以在云中为每个用户创建一个临时的内存SQLITE3数据库。 The databases will not be stored, hence they are in-memory: 数据库将不会被存储,因此它们在内存中:

import sqlite3
conn = sqlite3.connect(':memory:')

My question is regarding scalability. 我的问题是关于可伸缩性。 Worst case scenario there are thousands of users each creating GB sized databases all at the same time. 最坏的情况是成千上万的用户同时创建GB大小的数据库。 What is the default behavior of SQLITE3 when it runs out of memory? SQLITE3内存不足时的默认行为是什么? Will it write additional databases to disk? 它将其他数据库写入磁盘吗? Will it just crash? 它会崩溃吗?

I realize this is also a function of how the SAAS SERVER is configured, but my question lies only with the memory issue. 我意识到这也是SAAS SERVER配置方式的功能,但是我的问题仅在于内存问题。

This documentation page reads: 文档页面显示:

The sole difference [between a temporary and an in-memory database] is that a ":memory:" database must remain in memory at all times whereas parts of a temporary database might be flushed to disk if database becomes large or if SQLite comes under memory pressure. [临时数据库和内存数据库之间的唯一区别是,“:memory:”数据库必须始终保留在内存中,而如果数据库变大或SQLite出现故障,则可能会将部分临时数据库刷新到磁盘记忆压力。

This means that if SQLite runs out of memory then you'll probably hit your operating system's error codes. 这意味着,如果SQLite内存不足,则您可能会遇到操作系统的错误代码。

The database may be swapped to disk by the OS even if the ram is consumed, though. 即使使用了内存,操作系统也可能会将数据库交换到磁盘。

I'd advise to use a temporary database instead as described on the same documentation page if you're that worried, so if you run out of ram, SQLite will be able to flush them to disk. 如果您担心的话,建议您改用同一文档页面上所述的临时数据库,因此,如果用完了ram,SQLite将能够将它们刷新到磁盘上。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM