News for hackers. Stuff that matters.
Re:SQLite small blob storage: 35% Faster Than the Filesystem by tarasglek on Tuesday June 13, 2017 @11:02PM (#14550417)
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 able to predict reads better when they are within a single file. Writes are faster because they do one bulk COMMIT instead of many individual fsyncs.

Re:SQLite small blob storage: 35% Faster Than the Filesystem by imron on Tuesday June 13, 2017 @11:09PM (#14550440)
> 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 less disk space by sticking the files in SQLite instead.

Re:SQLite small blob storage: 35% Faster Than the Filesystem by nimchimpsky on Tuesday June 13, 2017 @11:47PM (#14550538)
> 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 by function_seven on Tuesday June 13, 2017 @11:57PM (#14550566)
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 by akira2501 on Wednesday June 14, 2017 @12:01AM (#14550580)
> You’d end up rewriting your own version of a database.

This is the hell we just crawled out of in one of our codebases.. it's not so much the access for a single process, but when you want to share the data in the file, that's when it seriously starts to get messy and breaking through otherwise clean abstraction layers and/or forcing recompile on compatibility breaking changes.

Re:SQLite small blob storage: 35% Faster Than the Filesystem by adventured on Wednesday June 14, 2017 @12:18AM (#14550614)
If you don't mind answering, out of sheer curiosity how was the data stored in the individual file/s?
Re:SQLite small blob storage: 35% Faster Than the Filesystem by akira2501 on Wednesday June 14, 2017 @01:47AM (#14550863)
Straight array of structs. The complication was that there were several of them, they were stored in bus-attached MRAM which was accessed directly (e.g. mmap of /dev/ram) by several independent processes.

The idea came from previous generations of the product which generally ran on microcontrollers coupled with custom FPGA designs, so, not entirely unwarranted.. but completely incorrect for a newer product with much greater computing power than their previous devices.

Re:SQLite small blob storage: 35% Faster Than the Filesystem by inetknght on Wednesday June 14, 2017 @12:38AM (#14550683)
> Writing your own methods to retrieve arbitrary chunks of data from a monolithic file would be a lot of work.

Oh goodness have we come a long way if interacting with a file is harder than interacting with a SQL database.

(it really depends on what language and/or library(ies) you use and for what purpose)

Re:SQLite small blob storage: 35% Faster Than the Filesystem by imron on Wednesday June 14, 2017 @01:49AM (#14550867)
> Oh goodness have we come a long way if interacting with a file is harder than interacting with a SQL database.

It's not interacting with a file, it's interacting with a file that contains other files of varying sizes that need to be accessed randomly with good performance.

Re:SQLite small blob storage: 35% Faster Than the Filesystem by diroussel on Wednesday June 14, 2017 @03:21AM (#14551183)
If you only want to read then both zip and tar are good for this purpose. It's commonly used and known to work well. There are many formats that are really just a renamed zip file. Like jar, and epub. File entries don't have to be compressed so you can mmap.

If you want to do random writes then more consideration is needed.

Re:SQLite small blob storage: 35% Faster Than the Filesystem by imron on Wednesday June 14, 2017 @03:57AM (#14551287)
> If you only want to read then both zip and tar are good for this purpose

And programmatically accessing them is significantly more complicated than using SQLite which involves dropping a single header in your project and about 10 lines of code.

> If you want to do random writes then more consideration is needed.

Which you almost certainly what you want to do for the sorts of use cases where SQLite is also under consideration.

Re:SQLite small blob storage: 35% Faster Than the Filesystem by dkersten on Wednesday June 14, 2017 @05:14AM (#14551509)
which involves dropping a single header in your project and about 10 lines of code.

10 lines of user code + the sqlite library. Using other formats like zip is hardly any more user code (+ some external library).

Re:SQLite small blob storage: 35% Faster Than the Filesystem by imron on Wednesday June 14, 2017 @05:30AM (#14551554)
The sqlite 'library' is a single header file and a single c file that you can just drop in your project and use.
Re:SQLite small blob storage: 35% Faster Than the Filesystem by dkersten on Wednesday June 14, 2017 @10:29AM (#14552960)
So are many libraries for other formats.

Btw I'm personally a big fan of SQLite, I just think the argument here is a bit of a straw man.

Re:SQLite small blob storage: 35% Faster Than the Filesystem by akx on Thursday June 15, 2017 @10:10AM (#14560539)
Afaik, tar files do not contain a central directory, so finding a certain file in a tar file requires skimming through the entire archive.
Re:SQLite small blob storage: 35% Faster Than the Filesystem by function_seven on Wednesday June 14, 2017 @01:01AM (#14550740)
As far as I know, querying a database has always been easier than querying a custom file format. It's the whole reason databases exist in the first place. And using one off the shelf is clearly easier than writing your own.
Re:SQLite small blob storage: 35% Faster Than the Filesystem by tetromino_ on Wednesday June 14, 2017 @01:18AM (#14550792)
Not easier, but vastly more flexible.

Sure, it's completely trivial to read a file containing an array of C structs of metadata and offsets into a blob of concatenated PNGs: just mmap the thing, and your main data structure is sitting right there in memory.

But problems start arising when you need to update the structure of that metadata. Add some more fields. Some more structured, multi-value fields, referring to multiple entities in your increasingly complex data structure. Entities which must be guaranteed to exist. And perform modifications concurrently, from multiple processes. And have the file not get corrupted when something kills a writer process in the middle of writing...

Databases are slow and overkill for the simple case, but they certainly make adding unexpected requested features much easier. And it can be expected that you will get unexpected feature requests.

Re:SQLite small blob storage: 35% Faster Than the Filesystem by dkersten on Wednesday June 14, 2017 @05:08AM (#14551492)
Nothing wrong with comparing apples and oranges. They have a lot more in common than people give them credit for (both are fruit, shape, flavour, nutrient content, where they grow, who eats them etc etc). You can even compare things that aren't similar at all and its not necessarily pointless.
Re:SQLite small blob storage: 35% Faster Than the Filesystem by codehusker on Tuesday June 13, 2017 @11:07PM (#14550434)
The third paragraph might offer the logical analysis you're looking for:

> The performance difference arises (we believe) because when working from an SQLite database, the open() and close() system calls are invoked only once, whereas open() and close() are invoked once for each blob when using blobs stored in individual files. It appears that the overhead of calling open() and close() is greater than the overhead of using the database. The size reduction arises from the fact that individual files are padded out to the next multiple of the filesystem block size, whereas the blobs are packed more tightly into an SQLite database.

Re:SQLite small blob storage: 35% Faster Than the Filesystem by ori_b on Tuesday June 13, 2017 @11:56PM (#14550565)
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 by justinclift on Wednesday June 14, 2017 @06:12AM (#14551680)
Cool, have you pointed them at it? :)
Re:SQLite small blob storage: 35% Faster Than the Filesystem by bigger_cheese on Wednesday June 14, 2017 @02:05AM (#14550914)
From this old stack overflow topic: https://stackoverflow.com/questions/6916011/how-do-i-get-win...

Conclusion seems to be that filesystems on windows are not well optimized for the usecase of reading and writing from many small files at once.

Which could explain poor windows performance in the benchmark (writing to 100,000 individual files).

Re:SQLite small blob storage: 35% Faster Than the Filesystem by AstralStorm on Wednesday June 14, 2017 @02:10AM (#14550928)
Which is why before making such broad statements they should check on the other platforms, which have much less broken file systems. (Check Ext4, ZFS, UFS2, HPFS+ and APFS at least.)

What they did is check an untuned Ext4, UBIFS, HPFS+ and NTFS vs a tuned database in a single thread scenario. Especially misleading in the mmap case where synchronization would just kill the performance dead.

Re:SQLite small blob storage: 35% Faster Than the Filesystem by majewsky on Wednesday June 14, 2017 @05:58AM (#14551638)
I find that comparison justified: How many people are even aware of the fact that filesystems can be tuned (except for, maybe, noatime and discard for SSDs)?
Re:SQLite small blob storage: 35% Faster Than the Filesystem by std_throwaway on Wednesday June 14, 2017 @12:30AM (#14550650)
Why stop there? One could use the raw device to get even greater performance!
Re:SQLite small blob storage: 35% Faster Than the Filesystem by nine_k on Wednesday June 14, 2017 @01:27AM (#14550821)
A database on a raw device is a thing. E.g. Oracle has this option for decades; MySQL, for some time, too.
Re:SQLite small blob storage: 35% Faster Than the Filesystem by aruggirello on Wednesday June 14, 2017 @05:10AM (#14551497)
Exactly my thought. A possibly fairer comparison could be SQLite blobs vs. some archive format (with and without compression).
Re:SQLite small blob storage: 35% Faster Than the Filesystem by visarga on Wednesday June 14, 2017 @12:19AM (#14550617)
No, no, if it is faster than the filesystem it must mean that it has a faster storage medium. Maybe it is writing to memory, or the aether. /s Now, seriously, how can the foot be faster than the shoe?
Re:SQLite small blob storage: 35% Faster Than the Filesystem by geon on Wednesday June 14, 2017 @05:02AM (#14551473)
A reading/writing a single file can be faster than multiple files. Also querying a db can be faster than querying the fs.