Is it more CPU-efficient to read/write config file or read/write sqlite database?

Chris Angelico rosuav at gmail.com
Tue Dec 17 22:35:51 EST 2013


On Wed, Dec 18, 2013 at 1:37 PM, Cameron Simpson <cs at zip.com.au> wrote:
>> I'd say this is the right thing for a DB to do.  If it comes back
>> from a commit() call, it better be on that disk, barring a failure
>> of the physical hardware.  If it comes back from a commit() and data
>> gets lost because of a power-failure, something is wrong.
>
> Depends on your view. People seem to treat dbs as some special form
> of data storage. I don't; to me they're no different to storing
> data in any other file. Do you do an fsync() every time you close
> a file you've written? Of course not, it is a gratuitous performance
> loss.  IMO, I've handed the data to the filesystem layer; its
> integrity is now the OS's problem.

An SQL database *is* a different form of storage. It's storing tabular
data, not a stream of bytes in a file. You're supposed to be able to
treat it as an efficient way to locate a particular tuple based on a
set of rules, not a different way to format a file on the disk. If you
want file semantics, use a file. Otherwise, what do you expect
commit() to do?

Also: the filesystem layer doesn't guarantee integrity. If you don't
fsync() or fdatasync() or some other equivalent [1], it's not on the
disk yet, so you can't trust it.

ChrisA

[1] See eg the PostgreSQL info on the subject:
http://www.postgresql.org/docs/9.3/static/runtime-config-wal.html#GUC-WAL-SYNC-METHOD



More information about the Python-list mailing list