Live data from Hacker News

SQLite small blob storage: 35% Faster Than the Filesystem

sqlite.org

11–20 of 208 posts

Re: SQLite small blob storage: 35% Faster Than the Filesystem

#13
post #11

If I asserted: "It's faster to put 10,000 rows of csv data in single file instead of 10,000 individual files" even the most junior programmer would likely say "Well, duh, it's 1 file instead of 10,000". Yet this benchmark is at the top of HN for some reason.

Your intuition far surpasses mine.

I for one am interested in the result and the reason.

Re: SQLite small blob storage: 35% Faster Than the Filesystem

#14
post #11

If I asserted: "It's faster to put 10,000 rows of csv data in single file instead of 10,000 individual files" even the most junior programmer would likely say "Well, duh, it's 1 file instead of 10,000". Yet this benchmark is at the top of HN for some reason.

Are the rows in the test indexed with a "filename" as a primary key? Bound to query a single file faster than a CSV parsing in that case.

Re: SQLite small blob storage: 35% Faster Than the Filesystem

#15
post #8

This is weird benchmarketing. They are comparing reading/writing 100,000 individual files vs writing 100,000 entries into a single file(sqlite database). For comparison one could concatenate the same data into a single big file even faster than into sqlite. They then do not offer logical analysis as to why things are faster. My understanding is that reads are probably faster due to operating system readahead being ab…

> For comparison one could concatenate the same data into a single big file even faster than into sqlite. One could, but then one would have great difficulty retrieving the individual files back when needed. The point is not about what has the greatest raw speed, the point is that that for applications that read lots of small files from the filesystem, they'll possibly get better performance and almost certainly use…

> have great difficulty retrieving

Not that great, and the point is its comparing apples to oranges, pointless.

Re: SQLite small blob storage: 35% Faster Than the Filesystem

#16
post #11

If I asserted: "It's faster to put 10,000 rows of csv data in single file instead of 10,000 individual files" even the most junior programmer would likely say "Well, duh, it's 1 file instead of 10,000". Yet this benchmark is at the top of HN for some reason.

So you never think that using database to store file will be slower than using file to store file?

"Duh, I always knew that" is easy to say when you don't have to provide proof.

Also, are you sure that CSV will be faster as well? Do you have a benchmark for it?

Re: SQLite small blob storage: 35% Faster Than the Filesystem

#17
post #11

If I asserted: "It's faster to put 10,000 rows of csv data in single file instead of 10,000 individual files" even the most junior programmer would likely say "Well, duh, it's 1 file instead of 10,000". Yet this benchmark is at the top of HN for some reason.

Your intuition far surpasses mine. I for one am interested in the result and the reason.

Opening a file means locating it physically on the disk by following references (usually at least one per directory level). This is a costly operation.

Compare to the typical case of adding another row by appending to an already allocated disk block. No seek operation needed.

Re: SQLite small blob storage: 35% Faster Than the Filesystem

#18

This is weird benchmarketing. They are comparing reading/writing 100,000 individual files vs writing 100,000 entries into a single file(sqlite database). For comparison one could concatenate the same data into a single big file even faster than into sqlite. They then do not offer logical analysis as to why things are faster. My understanding is that reads are probably faster due to operating system readahead being ab…

A big part of it is because they're repeatedly walking the same path while reading and writing it. I got a 20% performance improvement on FreeBSD+ZFS with this change, which merely opens an fd, and uses that to stat and write, cutting the number of path traversals in half:

https://eigenstate.org/paste/d41e3b69d258e3b52f7cee7a9921f02...

Re: SQLite small blob storage: 35% Faster Than the Filesystem

#19
post #8

Earlier quoted context omitted.

> For comparison one could concatenate the same data into a single big file even faster than into sqlite. One could, but then one would have great difficulty retrieving the individual files back when needed. The point is not about what has the greatest raw speed, the point is that that for applications that read lots of small files from the filesystem, they'll possibly get better performance and almost certainly use…

> have great difficulty retrieving Not that great, and the point is its comparing apples to oranges, pointless.

Writing your own methods to retrieve arbitrary chunks of data from a monolithic file would be a lot of work. Using map tiles as the example, how do you easily retrieve just the tiles in a specific region? Ok, how about all tiles that have the “hasLand” attribute set? Or the “containsCoastline” attribute?

You’d end up rewriting your own version of a database.

Re: SQLite small blob storage: 35% Faster Than the Filesystem

#20
post #16
post #11

If I asserted: "It's faster to put 10,000 rows of csv data in single file instead of 10,000 individual files" even the most junior programmer would likely say "Well, duh, it's 1 file instead of 10,000". Yet this benchmark is at the top of HN for some reason.

So you never think that using database to store file will be slower than using file to store file? "Duh, I always knew that" is easy to say when you don't have to provide proof. Also, are you sure that CSV will be faster as well? Do you have a benchmark for it?

"Measure before optimizing" has limited application. There are many things that need not be measured. Appending to a file is definitely not slower than doing memory management inside the file to allocate a new chunk, seeking to that position and then writing out the chunk. Period. (And the serialization overhead is negligible compared to the disk I/O).
Post reply on HN