简体   繁体   English

SQLite 与 Python 并发?

[英]SQLite Concurrency with Python?

Suppose that I have a huge SQLite file (say, 500[MB]).假设我有一个巨大的 SQLite 文件(比如 500[MB])。 Can 10 different python instances access this file at the same time and update different records of it?. 10个不同python实例可以同时访问这个文件并更新它的不同记录吗? Note, the emphasis here is on different records .注意,这里的重点是不同的记录

For example, suppose that the SQLite file has say 1M rows:例如,假设 SQLite 文件有1M行:

instance 1 will deal with (and update) rows 0 - 100000实例 1 将处理(并更新)行 0 - 100000

instance 2 will will deal with (and update) rows 100001 - 200000实例 2 将处理(并更新)行 100001 - 200000

......................... …………………………………………………………………………………………………………

instance 10 will deal with (and update) rows 900001 - 1000000实例 10 将处理(并更新)行 900001 - 1000000


Meaning, each python instance will only be updating a unique subset of the file.这意味着,每个python实例只会更新文件的唯一子集。 Will this work, or will I have serious integrity issues?这会奏效吗,还是我会有严重的诚信问题?

Updated, thanks to André Caron.更新,感谢 André Caron。

You can do that, but only read operations supports concurrency in SQLite, since entire database is locked on any write operation.可以这样做,在 SQLite 中只有读操作支持并发,因为整个数据库都被锁定在任何写操作上。 SQLite engine will return SQLITE_BUSY status in this situation (if it exceeds default timeout for access). SQLite 引擎在这种情况下会返回 SQLITE_BUSY 状态(如果超过默认访问超时)。 Also consider that this heavily depends on how good file locking is implemented for given OS and file system.还要考虑到这在很大程度上取决于对给定的操作系统和文件系统实现的文件锁定有多好。 In general I wouldn't recommend to use proposed solution, especially considering that DB file is quite large, but you can try.一般来说,我不建议使用建议的解决方案,特别是考虑到数据库文件非常大,但您可以尝试。

It will be better to use server process based database (MySQL, PostgreSQL, etc.) to implement desired app behaviour.最好使用基于服务器进程的数据库(MySQL、PostgreSQL 等)来实现所需的应用程序行为。

Somewhat.有些。 Only one instance can write at any single time, which means concurrent writes will block (refer to the SQLite FAQ ).任何时候只有一个实例可以写入,这意味着并发写入将被阻塞(请参阅SQLite 常见问题解答)。 You won't get integrity issues, but I'm not sure you'll really benefit from concurrency, although that depends on how much you write versus how much you read.你不会遇到完整性问题,但我不确定你是否真的会从并发中受益,尽管这取决于你写了多少和你读了多少。

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

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