Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQLite insert performance

Tags:

sqlite

I need to write single lines to a file placed on a file server. I am considering utilizing SQLite to ensure that the writing of the line was successful and not just partially completed. However, as insert performance is really essential. My question is, what is the exact process (as it read this, write that, read this and so on) that SQLite goes through when it inserts a row to a table. The table does not have any indexes, nor primary keys, constraints or anything.

like image 274
David Avatar asked Dec 05 '10 12:12

David


People also ask

How can I improve my insert performance?

To optimize insert speed, combine many small operations into a single large operation. Ideally, you make a single connection, send the data for many new rows at once, and delay all index updates and consistency checking until the very end.

How many writes per second SQLite?

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.

How performant is SQLite?

SQLite works great as the database engine for most low to medium traffic websites (which is to say, most websites). The amount of web traffic that SQLite can handle depends on how heavily the website uses its database. Generally speaking, any site that gets fewer than 100K hits/day should work fine with SQLite.


2 Answers

This is the most common bottleneck in my experience:

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

Except for that, SQLite is really fast. :)

like image 85
BastiBen Avatar answered Nov 11 '22 20:11

BastiBen


You should use transactions and thus try to avoid fsync()-ing on every INSERT. Take a look here for some benchmarks.

Also, be sure to properly set the two important pragmas:

  • synchronous (NORMAL)
  • journal_mode (WAL)
like image 44
the_void Avatar answered Nov 11 '22 19:11

the_void