News for hackers. Stuff that matters.
Re:SQLite small blob storage: 35% Faster Than the Filesystem by patio11 on Wednesday June 14, 2017 @07:11AM (#14551896)
My experience (for an application which had a working set of under 1 GB of files in the 50kb to N MB range, and approximately 50 GB persisted at any given time) was that preserving access to the toolchain which operates trivially with files was worth the additional performance overhead of working with the files and, separately, occasionally having to retool things to e.g. not have 10e7 files in a single folder, which is something that Linux has some opinions (none of them good) about.

Trivial example: it's easy to delete any file most recently accessed more than N months ago [+] with a trivial line in cron (the exact line escapes me -- it involves find), but doing that with a database requires that you roll your own access tracking logic. Incremental backups of a directory structure are easy (rsync or tarsnap); incremental backups of a database appeared to me to be highly non-trivial.

[+] Since we could re-generate PDFs or gifs from our source of truth at will (with 5~10 seconds of added latency), we deleted anything not accessed in N months to limit our hard disk usage.

Re:SQLite small blob storage: 35% Faster Than the Filesystem by troutaway123 on Wednesday June 14, 2017 @10:11AM (#14552827)
¿Porque no los dos?

Store the files in a database but expose them via FUSE.

Re:SQLite small blob storage: 35% Faster Than the Filesystem by pjc50 on Wednesday June 14, 2017 @10:34AM (#14553001)
That gives you the time cost of a filesystem plus the time cost of a database plus an extra round-trip in and out of kernel space.
Re:SQLite small blob storage: 35% Faster Than the Filesystem by troutaway123 on Wednesday June 14, 2017 @11:01AM (#14553221)
> preserving access to the toolchain which operates trivially with files was worth the additional performance overhead of working with the files

Sounds like they're OK with that.

In any case, couldn't you avoid the kernel trips with some dylib foolery (assuming the toolchain is dynamically linked)?

Re:SQLite small blob storage: 35% Faster Than the Filesystem by firethief on Wednesday June 14, 2017 @01:39PM (#14554423)
So: store the files in a database, expose them via FUSE, bypass FUSE and access the database?
Re:SQLite small blob storage: 35% Faster Than the Filesystem by troutaway123 on Saturday June 17, 2017 @01:15PM (#14576714)
Yep ;D
Re:SQLite small blob storage: 35% Faster Than the Filesystem by octetta on Wednesday June 14, 2017 @02:56PM (#14555096)
...or v9fs... but the overhead might make the whole exercise pointless.
Re:SQLite small blob storage: 35% Faster Than the Filesystem by Twirrim on Wednesday June 14, 2017 @11:42AM (#14553541)
> e.g. not have 10e7 files in a single folder, which is something that Linux has some opinions (none of them good) about.

I keep running in to this as a common anti-pattern in software, even with software developers that should know better (having fallen afoul of it before).

I ran in to it with some semi-bespoke software once, used by a remarkable number of state departments across the country. It was one of many, many things wrong with that godawful thing. Worse, not only were they dumping files in a single directory, almost any time they went to do something with the directory they'd request a directory listing too. Like many of the bizarre things the app did, it never actually used the information it acquired that way.

Re:SQLite small blob storage: 35% Faster Than the Filesystem by cm2187 on Wednesday June 14, 2017 @12:33PM (#14553861)
I never understood why it mattered that files would be in a single directory or split over multiple directories. At the end of the day it is the same file system with the same number of files. The directories are just a logical structure. Why would there be a difference?
Re:SQLite small blob storage: 35% Faster Than the Filesystem by jamie_ca on Wednesday June 14, 2017 @01:22PM (#14554281)
Spinning disks.

If you want raw file access, your ideal filesystem is a giant key-value store that keys on the full path to the file. This choice means doing a directory listing will involve a lot of random access reads across the disk, and in the days before SSDs this would be a performance killer.

So instead, a directory would have a little section of disk to write its file entries to. These would be fairly small, because most directories are small, and if there were more files added than there was room, another block would be allocated. Doing a file listing would be reasonably quick as you're just iterating over a block and following the link to the next block, but random file access would get slower the more files are added.

It's probably a solvable problem in filesystem design, but because current filesystems fall down hard on the million-files-in-a-directory use case, nobody actually does that, so there's no drive to make a filesystem performant in that case.

Re:SQLite small blob storage: 35% Faster Than the Filesystem by the8472 on Wednesday June 14, 2017 @01:39PM (#14554427)
ext4 uses btrees for the directory index, so accessing files by name is just as fast as manually splitting it into a prefix-based directory tree.

Searching by filename on the other hand can be much faster with a prefix tree because directories only allow linear scans, not range-based ones.

Re:SQLite small blob storage: 35% Faster Than the Filesystem by ngrilly on Wednesday June 14, 2017 @04:05PM (#14555661)
I'm missing something. What difference do you see between "accessing files by name" and "searching by filename"?
Re:SQLite small blob storage: 35% Faster Than the Filesystem by the8472 on Wednesday June 14, 2017 @04:46PM (#14555993)

    f = open("/path/to/file");
    // do something with file
vs.

    d = opendir("path/to")
    while((dent = readdir(d)) != NULL) {
       if(!dent.name.startsWith("file"))
          continue;
       // do something with first matched entry
    }

The former is O(log n) on ext4, O(n) on older filesystems that use flat lists.

The latter is always O(n)

Re:SQLite small blob storage: 35% Faster Than the Filesystem by ngrilly on Wednesday June 14, 2017 @05:01PM (#14556092)
Understood. Thanks ;-)
Re:SQLite small blob storage: 35% Faster Than the Filesystem by cm2187 on Wednesday June 14, 2017 @03:12PM (#14555233)
Ok but listing 100 directories with 10,000 files each should take the same time than listing one directory with 1,000,000 files (what you are describing is a filesystem with more files vs less files, not with more subdirectories than less subdirectories).
Re:SQLite small blob storage: 35% Faster Than the Filesystem by hulahoof on Wednesday June 14, 2017 @06:03PM (#14556471)
The benefit is with accessing single files and not requiring a 1,000,000 directory listing lookup
Re:SQLite small blob storage: 35% Faster Than the Filesystem by HeavyStorm on Wednesday June 14, 2017 @02:21PM (#14554782)
Well, my Linux-fu isn't very up-to-date, but my guess (which actually goes for any file system) is that a directory is a bit more than just a logical organization. It's an actual "thing" in your hard drive which keeps track of everything beneath it. And so it grows in size when more files are there, which slow down access.
Re:SQLite small blob storage: 35% Faster Than the Filesystem by Walf on Wednesday June 14, 2017 @08:33AM (#14552225)
Just don't let anyone mount with noatime, for performance. I found that little gem on a drive where paring down to used content would have been very helpful.
Re:SQLite small blob storage: 35% Faster Than the Filesystem by cat199 on Wednesday June 14, 2017 @10:09AM (#14552805)
Or, consider your use case for this at least.

Some user-level backups for example, will make the atime useless.

Re:SQLite small blob storage: 35% Faster Than the Filesystem by stuaxo on Friday June 16, 2017 @06:57AM (#14567910)
Even with way fewer files than that you can't use wildcards in bash because it will expands to longer than the commandline allows.

This makes any work in the shell painful.

Re:SQLite small blob storage: 35% Faster Than the Filesystem by ccommsxx on Wednesday June 14, 2017 @01:42PM (#14554452)
50GB of files in the 50KB-inf range can be at most 10e5 files, not 10e7. (10e7 would be 5TB of 50KB files)