INSERT is really slow - I can only do few dozen INSERTs per second

http://www.sqlite.org/faq.html#q19

Actually, SQLite will easily do 50,000 or more INSERT statements per second on an average desktop computer. But it will only do a few dozen transactions per second. Transaction speed is limited by the rotational speed of your disk drive. A transaction normally requires two complete rotations of the disk platter, which on a 7200RPM disk drive limits you to about 60 transactions per second.

Transaction speed is limited by disk drive speed because (by default) SQLite actually waits until the data really is safely stored on the disk surface before the transaction is complete. That way, if you suddenly lose power or if your OS crashes, your data is still safe. For details, read about atomic commit in SQLite..

By default, each INSERT statement is its own transaction. But if you surround multiple INSERT statements with BEGIN...COMMIT then all the inserts are grouped into a single transaction. The time needed to commit the transaction is amortized over all the enclosed insert statements and so the time per insert statement is greatly reduced.

Another option is to run PRAGMA synchronous=OFF. This command will cause SQLite to not wait on data to reach the disk surface, which will make write operations appear to be much faster. But if you lose power in the middle of a transaction, your database file might go corrupt.

http://blogs.msdn.com/b/andy_wigley/archive/2013/11/21/how-to-massively-improve-sqlite-performance-using-sqlwinrt.aspx

http://blog.quibb.org/2010/08/fast-bulk-inserts-into-sqlite/

http://www.codeproject.com/Articles/853842/Csharp-Avoiding-Performance-Issues-with-Inserts-in

http://stackoverflow.com/questions/1711631/improve-insert-per-second-performance-of-sqlite

threadsafe / sqlite in multithread

https://www.sqlite.org/threadsafe.html

I read everywhere that creating transactions is the solution to slow SQLite writes, but it can be long and painful to rewrite your code and wrap all your SQLite writes in transactions.

I found a much simpler, safe and very efficient method: I enable a (disabled by default) SQLite 3.7.0 optimisation : the Write-Ahead-Log (WAL). The documentation says it works in all unix (i.e. Linux and OSX) and Windows systems.

How ? Just run the following commands after initializing your SQLite connection:

PRAGMA journal_mode = WAL
PRAGMA synchronous = NORMAL

My code now runs ~600% faster : my test suite now runs in 38 seconds instead of 4 minutes :)

to improve sqlite performance的更多相关文章

  1. Five Invaluable Techniques to Improve Regex Performance

    Regular expressions are powerful, but with great power comes great responsibility. Because of the wa ...

  2. Ten ways to improve the performance of large tables in MySQL--转载

    原文地址:http://www.tocker.ca/2013/10/24/improving-the-performance-of-large-tables-in-mysql.html Today I ...

  3. build a real-time analytics dashboard to visualize the number of orders getting shipped every minute to improve the performance of their logistics for an e-commerce portal

    https://cloudxlab.com/blog/real-time-analytics-dashboard-with-apache-spark-kafka/

  4. [XAF] How to improve the application's performance

    [自己的解决方案]数据量大时,可显著提升用户使用体验! 1.Root ListView 参考官方的E1554 点击导航菜单后首先跳出查询条件设置窗体进行设置 可设置查询方案或查询方案的查询条件,排序字 ...

  5. (转) Ensemble Methods for Deep Learning Neural Networks to Reduce Variance and Improve Performance

    Ensemble Methods for Deep Learning Neural Networks to Reduce Variance and Improve Performance 2018-1 ...

  6. [转]How to Improve Entity Framework Add Performance?

    本文转自:http://entityframework.net/improve-ef-add-performance When you overuse the Add() method for mul ...

  7. How To Improve Deep Learning Performance

    如何提高深度学习性能 20 Tips, Tricks and Techniques That You Can Use ToFight Overfitting and Get Better Genera ...

  8. WPF Freezable–How to improve your application's performances

    在给ImageBrush绑定动态图片是会报以下错误. Error    4    The provided DependencyObject is not a context for this Fre ...

  9. How to Configure Nginx for Optimized Performance

    Features Pricing Add-ons Resources | Log in Sign up   Guides & Tutorials Web Server Guides Nginx ...

随机推荐

  1. 第一章:了解SQL_数据库基础

    什么是数据库(database): 数据库(database)是保存有组织的数据的容器(通常是一个文件或一组文件).数据库是一种以某种有组织的方式存储的数据集合.   表(table): 表(tabl ...

  2. POST请求的forHTTPHeaderField

    POST请求的forHTTPHeaderField 也许你的iOS项目中使用了AFNetworking2.0,或者是ASIHTTPRequest,对于http中POST请求的操作,你用了他们提供的现成 ...

  3. [翻译] NSImage+HHTint - Tints grayscale images using CoreImage

    NSImage+HHTint - Tints grayscale images using CoreImage https://github.com/gloubibou/NSImage-HHTint ...

  4. Imagex用法

    imagex用来合并/导出wim映像实例 查看wim中包含的所有单个wim实例信息,注意其中的index是唯一的,用来区分不同的wim,导出的时候也通过该index导出相应的wimimagex /in ...

  5. python操作Exchange邮箱实例(-)

    需求很简单,就是实现按公司域名及服务器模拟exchange发送邮件,主要是协助自动化测试.主要功能:收件人/抄送/正文html/附件 本实例基于:python2.7.11 exchangelib1.1 ...

  6. 电脑技巧——DOS和windows的区别?

    本质:都是微软公司的操作系统,某种从程度上说windows是dos的后续操作系统版本.只是windows相比dos有质的飞跃.dos只支持命令操作,windows则有了良好的图形操作界面,window ...

  7. __iter__的有无

    迭代器和生成器 1.迭代器 我们之前⼀直在⽤可迭代对象进⾏迭代操作. 那么到底什么是可迭代对象.⾸先我们先回顾⼀下⽬前我们所熟知的可迭代对象有哪些: str, list, tuple, dict, s ...

  8. JS和css实现检测移动设备方向的变化并判断横竖屏幕

    这篇文章主要介绍了JS和css实现检测移动设备方向的变化并判断横竖屏幕,本文分别给出实现代码,需要的朋友可以参考下 方法一:用触发手机的横屏和竖屏之间的切换的事件  [自测可用, chrome , 手 ...

  9. django CBV模式下如何去掉csrf验证

    方式一:from django.views.decorators.csrf import csrf_exemptfrom django.utils.decorators import method_d ...

  10. Python学习之路 (二)爬虫(一)

    Python基础 基础教程参考廖雪峰的官方网站https://www.liaoxuefeng.com/ 一."大数据时代",数据获取的方式 1. 企业生产的用户数据:大型互联网公司 ...