Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Modern browsers have local storage, which is stored in webappstore.sqlite (for firefox) and localstorage.sqlite (for chrome).

There is a third-party script, (online messenger), which uses local storage and changes some value every second (chrome) or even more often (firefox, 2-3 time per second).

Local storage key which is changed so often:

_STRG_fm_current

script is webagent-04052011092843.js

I think, that sqlite engine in broswer do a fsync every time (or every second) when the values in local storage is changed. Using Filemon, I also detected work with .sqlite-journal files, but they are deleted when I try to find them in the folder with localstorage.

Is it possible to limit how often will sqlite do fsyncs of localstorage db's in firefox and chrome?

share|improve this question

1 Answer 1

up vote 2 down vote accepted

If you have a web app that is using local storage so heavily that it causes performance issues, I would contact the web app author and let them know, so perhaps they can fix it.

However, SQLite does have a mode since version 3.7.0 called write-ahead logging which uses fewer fsync operations. Since newer versions of Chrome and Firefox both use at least version 3.7.0 of SQLite, you may be able to set WAL mode on your local storage database, and it ought to persist when Chrome and Firefox start using it.

You will need the sqlite3 executable. Close Chrome first, then run the following commands:

sqlite3 path/to/localstorage.sqlite

sqlite> PRAGMA journal_mode=WAL;
sqlite> .quit

(When you run the PRAGMA command, you should get back the result "wal".)

The same commands would be used to set WAL mode for the Firefox database, substituting webappstore.sqlite for localstorage.sqlite.

To undo this setting, run the same commands, except use PRAGMA journal_mode=DELETE;.

Please note that I have not tried this myself; my guess is that it will work fine, but I urge you to backup the database file before trying it.


As an aside, the *.sqlite-journal files you are seeing in Filemon are part of how SQLite performs an atomic commit. By default, the journal file exists only for a very short time. When committing a change to a SQLite database, the following actions happen:

  1. The current data is written to the journal file.
  2. The new data is written to the database file.
  3. The journal file is deleted.

If the computer crashes in the middle of writing the database file, the journal file is used to recover the database back to before the change ever started.

share|improve this answer
    
Can I disable journal (not doing fsync at all) and disable atomic commits? Power loss is very rare event (2-3 per year even w/o UPS), and I need no ACID for my browser history. But shuffling data between several files leads to very high level of file fragmentation. How big should sqlite-journal be? –  osgx May 27 '12 at 22:17
1  
@osgx: You would need to get Chrome/Firefox to run PRAGMA journal_mode=OFF (unlike WAL, running it from the sqlite3 program will not set it for other programs). This would probably require you to recompile those browsers from source. The journal size depends on the size of the changes being made; for this application, the journals should be pretty small. –  Stephen Jennings May 27 '12 at 23:37

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.