Live data from Hacker News

An unscientific benchmark of SQLite vs. the file system (btrfs)

github.com

21–30 of 68 posts

Re: An unscientific benchmark of SQLite vs. the file system (btrfs)

#21
post #20

Go is perhaps not the best tool to use for this as calling sqlite via Cgo will incur a penalty. Might be significant in a very hot loop.

Go’s the tool I’m using to build a side project, so I was really only curious about Go + SQLite vs Go + file system.

Re: An unscientific benchmark of SQLite vs. the file system (btrfs)

#22
post #20

Go is perhaps not the best tool to use for this as calling sqlite via Cgo will incur a penalty. Might be significant in a very hot loop.

Go’s the tool I’m using to build a side project, so I was really only curious about Go + SQLite vs Go + file system.

You might find these projects interesting:

- https://pkg.go.dev/modernc.org/ql

- https://pkg.go.dev/modernc.org/sqlite

It’s hard to find much information about them, but the first one seems to be a database similar to sqlite, and the latter seems to be some kind of automated translation of sqlite to Go. I’m not sure either of these will outperform sqlite on CGo, but both of them should eliminate the CGo overhead and might give you some more room.

P.S.: The latter is a bit unorthodox in that it contains separate code for each architecture supported by Go, most likely a reflection of the method of the automated translation.

Re: An unscientific benchmark of SQLite vs. the file system (btrfs)

#23
post #4

Earlier quoted context omitted.

If you only care about storing data and not doing any complex operations or query against it why are you using something like sqlite as well? It’s not a comparison as being in sqlite makes the ability to access this data significantly easier. This is comparing apples and dogs and i don’t see the merits.

In one application I use sqlite to store JPEG thumbnails. That's it; there's nothing else in there. It's super handy; I specifically needed to reduce the number of files that I open and close because that's slow on Windows/NTFS. SQLite made this trivial. I could have managed a binary pack format on my own but I didn't have to.

You could have easily done that with a single file with a tail header for look ups.

Re: An unscientific benchmark of SQLite vs. the file system (btrfs)

#25
post #22

Earlier quoted context omitted.

Go’s the tool I’m using to build a side project, so I was really only curious about Go + SQLite vs Go + file system.

You might find these projects interesting: - https://pkg.go.dev/modernc.org/ql - https://pkg.go.dev/modernc.org/sqlite It’s hard to find much information about them, but the first one seems to be a database similar to sqlite, and the latter seems to be some kind of automated translation of sqlite to Go. I’m not sure either of these will outperform sqlite on CGo, but both of them should eliminate the CGo overhead and…

I hadn’t heard of ql, but I tried the latter project, and it was much slower for inserts. Something like 500/second.

Re: An unscientific benchmark of SQLite vs. the file system (btrfs)

#26
post #24

How about a fast filesystem? This is by far the slowest.

That’s fair. It’s the file system I have easy access to. I should spin up a VPS and use ext4 or xfs. I may do that when I have some spare time. It looks like I may get double the perf by making that switch. SQLite also seems to get a bump on different file systems.

Edit: just ran it on EXT4 on Linode.

SQLite: 8.7s

EXT4: 18.3s

Re: An unscientific benchmark of SQLite vs. the file system (btrfs)

#27
post #18

A quick google shows there are few FUSE SQLite implementations. Then you can use grep, ls, etc

How would you defrag the sqlite file? Or would VACUUM or what have you automagically accomplish that?

Actually, having a sqlite filesystem is intriguing because you could in theory add any kind of metadata or filesystem feature you wanted to (such as a forward-error-correcting checksum field, auto-compressed/decompressed data, dedup, encryption, etc.) It would make it nearly trivial for anyone to experiment with new filesystems.

Re: An unscientific benchmark of SQLite vs. the file system (btrfs)

#28

Earlier quoted context omitted.

In one application I use sqlite to store JPEG thumbnails. That's it; there's nothing else in there. It's super handy; I specifically needed to reduce the number of files that I open and close because that's slow on Windows/NTFS. SQLite made this trivial. I could have managed a binary pack format on my own but I didn't have to.

You could have easily done that with a single file with a tail header for look ups.

Easier than SQLite? With less bugs and better tests?

SQLite advertises itself as an fopen replacement. Sounds like a perfect match for parent’s use case.

Re: An unscientific benchmark of SQLite vs. the file system (btrfs)

#29
post #4

Earlier quoted context omitted.

If you only care about storing data and not doing any complex operations or query against it why are you using something like sqlite as well? It’s not a comparison as being in sqlite makes the ability to access this data significantly easier. This is comparing apples and dogs and i don’t see the merits.

In one application I use sqlite to store JPEG thumbnails. That's it; there's nothing else in there. It's super handy; I specifically needed to reduce the number of files that I open and close because that's slow on Windows/NTFS. SQLite made this trivial. I could have managed a binary pack format on my own but I didn't have to.

Another alternative that I've seen used is a zip or tar with no compression if you are just appending files and reading but only rarely updating or deleting.

But sqlite is still better, it is more reliable, a bad write on that end of zip index destroys the whole zip archive and sqlite also gives you a lot more potential flexibility later on if you need to add metadata or something else. It is better in terms of inserts and deletes, although you will still need to vacuum.

Re: An unscientific benchmark of SQLite vs. the file system (btrfs)

#30

Earlier quoted context omitted.

In one application I use sqlite to store JPEG thumbnails. That's it; there's nothing else in there. It's super handy; I specifically needed to reduce the number of files that I open and close because that's slow on Windows/NTFS. SQLite made this trivial. I could have managed a binary pack format on my own but I didn't have to.

Another alternative that I've seen used is a zip or tar with no compression if you are just appending files and reading but only rarely updating or deleting. But sqlite is still better, it is more reliable, a bad write on that end of zip index destroys the whole zip archive and sqlite also gives you a lot more potential flexibility later on if you need to add metadata or something else. It is better in terms of inser…

A bad write on a zip file destroys the O(1) seek time, but it doesn't destroy the zip. That goes back to PKZip trying to work on floppies and over modems. You can still do an O(n) seek on a particular file, or expand and recompress the file to recover whatever isn't truncated.

For this situation it does matter, but it is recoverable.

Post reply on HN