News for hackers. Stuff that matters.
Re:Are You Sure You Want to Use MMAP in Your Database Manage... by gavinray on Sunday July 02, 2023 @04:44PM (#36565504)
Out of curiosity, how many databases have you written?

This is co-authored by Pavlo, Viktor Leiss, with feedback from Neumann. I'm sorry, but if someone on the internet claims to know better than those 3, you're going to need some monumental evidence of your credibility.

Additionally, what you link here:

  > ... (See the slide at 21:25 into the video). Modern DBMSs spend 96% of their time managing buffers and locks, and only 4% doing actual useful work for the caller.
Is discussing "Main Memory" databases. These databases do no I/O outside of potential initial reads, because all of the data fits in-memory!

These databases represent a small portion of contemporary DBMS usage when compared to traditional RDBMS.

All you have to do is look at the bandwidth and reads/sec from the paper when using O_DIRECT "pread()"s versus mmap'ed IO.

Re:Are You Sure You Want to Use MMAP in Your Database Manage... by LAC-Tech on Sunday July 02, 2023 @04:58PM (#36565661)
This is a classic appeal to authority. Let's play the argument, not the man.

(My understanding is that the GP wrote LMDB, works on openLDAP, and was a maintainer for BerkelyDB for a number of years. But even if he'd only written 'hello, world!' I'm much more interested in the specific arguments).

Re:Are You Sure You Want to Use MMAP in Your Database Manage... by hyc_symas on Sunday July 02, 2023 @05:40PM (#36566074)
Correct, and thank you. I wrote LMDB, wrote a lot of OpenLDAP, and worked on BerkeleyDB for many years. And actually Andy Pavlo invited me to CMU to give a lecture on LMDB a few years back. https://www.youtube.com/watch?v=tEa5sAh-kVk

Andy and I have had this debate going for a long time already.

Re:Are You Sure You Want to Use MMAP in Your Database Manage... by gavinray on Sunday July 02, 2023 @05:52PM (#36566179)
Well, I eat my shorts.

Isn't LMBD closer to an embedded key-value store than an RDBMS, though? Also there's a section in the paper that mentions it's single-writer.

Re:Are You Sure You Want to Use MMAP in Your Database Manage... by hyc_symas on Sunday July 02, 2023 @05:55PM (#36566203)
Yes, LMDB is an embedded key/value store but it can be used as the backing store of any other DB model you care for. E.g. as a backend to MySQL, or SQLite, or OpenLDAP, or whatever.
Re:Are You Sure You Want to Use MMAP in Your Database Manage... by gavinray on Sunday July 02, 2023 @05:43PM (#36566107)
The argument is that:

- Queries can trigger blocking page faults when accessing (transparently) evicted pages, causing unexpected I/O stalls

- mmap() complicates transactionality and error-handling

- Page table contention, single-threaded page eviction, and TLB shootdowns become bottlenecks

Re:Are You Sure You Want to Use MMAP in Your Database Manage... by hyc_symas on Sunday July 02, 2023 @05:53PM (#36566186)
1 - for reading any uncached data, the I/O stalls are unavoidable. Whatever client requested that data is going to have to wait regardless.

2 - complexity? this is simply false. LMDB's ACID txns using MVCC are much simpler than any "traditional" approach.

3 - contention is a red herring since this approach is already single-writer, as is common for most embedded k/v stores these days. You lose more perf by trying to make the write path multi-threaded, in lock contention and cache thrashing.

Re:Are You Sure You Want to Use MMAP in Your Database Manage... by pclmulqdq on Sunday July 02, 2023 @08:13PM (#36567192)
It's kind of disingenuous to talk about how great your concurrency system is when you only allow a single writer. RCU (which I imagine your system is isomorphic to) is pretty simple compared to what many DB engines use to do ACID transactions that involve both reads and writes.
Re:Are You Sure You Want to Use MMAP in Your Database Manage... by hyc_symas on Sunday July 02, 2023 @08:59PM (#36567483)
You don't need more than single-writer concurrency if your write txns are fast enough.

Our experience with OpenLDAP was that multi-writer concurrency cost too much overhead. Even though you may be writing primary records to independent regions of the DB, if you're indexing any of that data (which all real DBs do, for query perf) you wind up getting a lot of contention in the indices. That leads to row locking conflicts, txn rollbacks, and retries. With a single writer txn model, you never get conflicts, never need rollbacks.

Re:Are You Sure You Want to Use MMAP in Your Database Manage... by pclmulqdq on Sunday July 02, 2023 @09:05PM (#36567513)
That's probably because your OpenLDAP benchmarks used a tiny database. If you have multi-terabyte databases, you will start to see huge gains from a multi-writer setup because you will be regularly be loading pages from disk, rather than keeping almost all of your btree/LSM tree in RAM.
Re:Are You Sure You Want to Use MMAP in Your Database Manage... by hyc_symas on Sunday July 02, 2023 @09:09PM (#36567540)
Yeah, no. Not with a DB 50x larger than RAM, anyway.

http://www.lmdb.tech/bench/hyperdex/

RAM is relatively cheap too, there's no real reason to be running multi-TB databases at greater than a 50x ratio.

Re:Are You Sure You Want to Use MMAP in Your Database Manage... by pclmulqdq on Sunday July 02, 2023 @09:28PM (#36567643)
Sorry, but "50x larger than RAM" is a pretty small DB - that's an 800 GB database on a machine with 16 GB of RAM. I usually have seen machines with 500-1000x ratios of flash to RAM. "RAM is relatively cheap" is also false when you're storing truly huge amounts of data, which is how the systems you compare yourself to (LevelDB, etc) are usually deployed. Note that RAM is now the single greatest cost when buying servers.

> Now that the total database is 50 times larger than RAM, around half of the key lookups will require a disk I/O.

That is an insanely high cache hit rate, which should have probably set off your "unrepresentative benchmark" detector. I am also a little surprised at the lack of a random writes benchmark. I get that this is marketing material, though.

Re:Are You Sure You Want to Use MMAP in Your Database Manage... by hyc_symas on Sunday July 02, 2023 @09:39PM (#36567700)
> I am also a little surprised at the lack of a random writes benchmark.

Eh? This was 20% random writes, 80% random reads. LMDB is for read-heavy workloads.

> That is an insanely high cache hit rate, which should have probably set off your "unrepresentative benchmark" detector.

No, that is normal for a B+tree; the root page and most of the branch pages will always be in cache. This is why you can get excellent efficiency and performance from a DB without tuning to a specific workload.

Re:Are You Sure You Want to Use MMAP in Your Database Manage... by pclmulqdq on Sunday July 02, 2023 @09:52PM (#36567774)
> Eh? This was 20% random writes, 80% random reads. LMDB is for read-heavy workloads.

The page says "updates," not "writes." Updates are a constrained form of write where you are writing to an existing key. Updates, importantly, do not affect your index structure, while writes do.

> No, that is normal for a B+tree; the root page and most of the branch pages will always be in cache. This is why you can get excellent efficiency and performance from a DB without tuning to a specific workload.

It is normal for a small B+tree relative to the memory size available on the machine. The "small" was the unrepresentative part of the benchmark, not the "B+tree."

Re:Are You Sure You Want to Use MMAP in Your Database Manage... by hyc_symas on Sunday July 02, 2023 @10:13PM (#36567892)
> The page says "updates," not "writes." Updates are a constrained form of write where you are writing to an existing key. Updates, importantly, do not affect your index structure, while writes do.

OK, I see your point. It would only have made things even worse for LevelDB here to do an Add/Delete workload because its garbage compaction passes would have had to do a lot more work.

> It is normal for a small B+tree relative to the memory size available on the machine. The "small" was the unrepresentative part of the benchmark, not the "B+tree."

This was 100 million records, and a 5-level deep tree. To get to 6 levels deep it would be about 10 billion records. Most of the branch pages would still fit in RAM; most queries would require at most 1 more I/O than the 5-level case. The cost is still better than any other approach.

Re:Are You Sure You Want to Use MMAP in Your Database Manage... by jandrewrogers on Sunday July 02, 2023 @10:49PM (#36568154)
> You don't need more than single-writer concurrency if your write txns are fast enough.

This only works on systems with sufficiently slow storage. If your server has a bunch of NVMe, which is a pretty normal database config these days, you will be hard-pressed to get anywhere close to the theoretical throughput of the storage with a single writer. That requires 10+ GB/s sustained. It is a piece of cake with multiple writers and a good architecture.

Writes through indexing can be sustained at this rate (assuming appropriate data structures), most of the technical challenge is driving the network at the necessary rate in my experience.

Re:Are You Sure You Want to Use MMAP in Your Database Manage... by hyc_symas on Monday July 03, 2023 @04:34AM (#36570312)
That's all just false. Just because you're single-writer at the application level doesn't mean the OS isn't queueing enough writes to saturate storage at the device level. We've benchmarked plenty of high speed NVMe devices, like Intel Optane SSDs, etc. showing this. http://www.lmdb.tech/bench/optanessd/
Re:Are You Sure You Want to Use MMAP in Your Database Manage... by heisjustsosmart on Wednesday July 05, 2023 @01:39PM (#36603955)
this guy is a fool. Ignore him. Or see his website.
Re:Are You Sure You Want to Use MMAP in Your Database Manage... by jeffffff on Sunday July 02, 2023 @09:25PM (#36567625)
take a look at http://nms.csail.mit.edu/~stavros/pubs/OLTP_sigmod08.pdf - the overhead of coordinating multiple writers often makes multi-writer databases slower than single-writer databases. remember, everything has to be serialized when it goes to the write ahead log, so as long as you can do the database updates as fast as you can write to the log then concurrent writers are of no benefit.
Re:Are You Sure You Want to Use MMAP in Your Database Manage... by pclmulqdq on Sunday July 02, 2023 @09:50PM (#36567763)
This is another cool example of a toy database that is again very small:

> The database size for one warehouse is approximately 100 MB (we experiment with five warehouses for a total size of 500MB).

It is not surprising that when your database basically fits in RAM, serializing on one writer is worth doing, because it just plainly reduces contention. You basically gain nothing in a DB engine from multi-writer transactions when this is the case. A large part of a write (the vast majority of write latency) in many systems with a large database comes from reading the index up to the point where you plan to write. If that tree is in RAM, there is no work here, and you instead incur overhead on consistency of that tree by having multiple writers.

I'm not suggesting that these results are useless. They are useful for people whose databases are small because they are meaningfully better than RocksDB/LevelDB which implicitly assume that your database is a *lot* bigger than RAM.

Re:Are You Sure You Want to Use MMAP in Your Database Manage... by hyc_symas on Sunday July 02, 2023 @09:56PM (#36567796)
> RocksDB/LevelDB which implicitly assume that your database is a lot bigger than RAM.

Where are you getting that assumption from? LevelDB was built to be used in Google Chrome, not for multi-TB DBs. RocksDB was optimized specifically for in-memory workloads.

Re:Are You Sure You Want to Use MMAP in Your Database Manage... by pclmulqdq on Sunday July 02, 2023 @10:02PM (#36567830)
I worked with the Bigtable folks at Google. LevelDB's design is ripped straight from BigTable, which was designed with that assumption in mind. I'm also pretty sure it was not designed specifically for Google Chrome's use case - it was written to be a general key-value storage engine based on BigTable, and Google Chrome was the first customer.

RocksDB is Facebook's offshoot of LevelDB, basically keeping the core architecture of the storage engine (but multithreading it), and is used internally at Facebook as the backing store for many of their database systems. I have never heard from anyone that RocksDB was optimized for in-memory workloads at all, and I think most benchmarks can conclusively say the opposite: both of those DB engines are pretty bad for workloads that fit in memory.

Re:Are You Sure You Want to Use MMAP in Your Database Manage... by hyc_symas on Sunday July 02, 2023 @10:18PM (#36567922)
I think we've gone off on a tangent. At any rate, both LevelDB and RocksDB are still single-writer so whatever point seems to have been lost along the way.
Re:Are You Sure You Want to Use MMAP in Your Database Manage... by earthnail on Monday July 03, 2023 @04:05AM (#36570134)
I've used RocksDB for an in-memory K/V store of ~600GB in size and it worked really well. Not saying it's the best choice out there but it did the job very well for us. And in particular because our dataset was always growing and we needed the option to fallback to disk if needed, RocksDB worked very well.

Was a PITA to optimise though; tons of options and little insight into which ones work.

Re:Are You Sure You Want to Use MMAP in Your Database Manage... by ayende on Monday July 03, 2023 @03:19AM (#36569826)
I am using the same rough model, and I'm using that on a 1.5 TB db running on Raspberry PI very successfully.

Pretty much all storage libraries written in the past couple of decades are using single writer. Note that single writer doesn't mean single transaction. Merging transactions is easy and highly profitable, after all.

Re:Are You Sure You Want to Use MMAP in Your Database Manage... by AdamProut on Sunday July 02, 2023 @11:51PM (#36568550)
Yeah for workloads with any long running write transactions a single writer design is a pretty big limitation. Say some long running data load (or a big bulk deletion) running along with some faster high throughput key value writes - the big data load would block all the faster key-value writes when it runs.

No "mainstream" database I'm aware of has a global single writer design.

Re:Are You Sure You Want to Use MMAP in Your Database Manage... by RaisingSpear on Monday July 03, 2023 @08:15AM (#36571822)
> for reading any uncached data, the I/O stalls are unavoidable.

Excuse me for a silly question, but whilst an I/O stall may be unavoidable, wouldn't a thread stall be avoidable if you're not using mmap?

Assuming that you're not swapping, you'll generally know if you've loaded something into memory or not, whilst mmap doesn't help you know if the relevant page is cached. If the data isn't in memory, you can send the I/O request to a thread to retrieve it, and the initiating thread can then move onto the next connection. I suspect this isn't doable under mmap based access?

Re:Are You Sure You Want to Use MMAP in Your Database Manage... by jemfinch on Sunday July 02, 2023 @06:10PM (#36566322)
"Taking full control of your I/O and buffer management is great if (a) your developers are all smart and experienced enough to be kernel programmers" is already an appeal to authority in itself.

We shouldn't apply a higher bar to the counterargument than we applied to the argument in the first place.

Re:Are You Sure You Want to Use MMAP in Your Database Manage... by jandrewrogers on Sunday July 02, 2023 @06:20PM (#36566403)
I think the real argument is more nuanced. Where you see mmap() fail badly on Linux, even for read-only workloads, is under a few specific conditions: very large storage volumes, highly concurrent access, non-trivial access patterns (e.g. high-dimensionality access methods). Most people do not operate data models under these conditions, but if you do then you can achieve large integer factor gains in throughput by not using mmap().

Interestingly, most of the reason for these problems has to do with theoretical limitations of cache replacement algorithms as drivers of I/O scheduling. There are alternative approaches to scheduling I/O that work much better in these cases but mmap() can’t express them, so in those cases bypassing mmap() offers large gains.

Re:Are You Sure You Want to Use MMAP in Your Database Manage... by pclmulqdq on Sunday July 02, 2023 @08:03PM (#36567136)
GP wrote a key-value store called LMDB that is constrained to a single writer, and often used for small databases that fit entirely in memory but need to persist to disk. There's a whole different world for more scalable databases.
Re:Are You Sure You Want to Use MMAP in Your Database Manage... by hyc_symas on Sunday July 02, 2023 @09:18PM (#36567590)
"fit entirely in memory" is not a requirement. LMDB is not a main-memory database, it is an on-disk database that uses memory mapping.
Re:Are You Sure You Want to Use MMAP in Your Database Manage... by LAC-Tech on Sunday July 02, 2023 @08:33PM (#36567332)
Can you explain "high-dimensionality access methods" to me? (Or if it's too big for an HN comment, maybe recommend a paper).
Re:Are You Sure You Want to Use MMAP in Your Database Manage... by heisjustsosmart on Wednesday July 05, 2023 @01:26PM (#36603716)
This guy talks a lot of crap. See his website for examples, and don't waste your time with him

<<<There is one significant drawback that should not be understated. Algorithm design using topology manipulation can be enormously challenging to reason about. You are often taking a conceptually simple algorithm, like a nested loop or hash join, and replacing it with a much more efficient algorithm involving the non-trivial manipulation of complex high-dimensionality constraint spaces that effect the same result. Routinely reasoning about complex object relationships in greater than three dimensions, and constructing correct parallel algorithms that exploit them, becomes easier but never easy.>>>

http://www.jandrewrogers.com/2015/10/08/spacecurve/

Re:Are You Sure You Want to Use MMAP in Your Database Manage... by ilyt on Sunday July 02, 2023 @09:33PM (#36567663)
I'd imagine same kind of worst case access would also be a problem doing IO the "classical" way
Re:Are You Sure You Want to Use MMAP in Your Database Manage... by ilyt on Sunday July 02, 2023 @09:30PM (#36567649)
Out of curiosity, do you have anything actually useful to add or are just throwing appeals to authority because you don't ?
Re:Are You Sure You Want to Use MMAP in Your Database Manage... by Mikhail_Edoshin on Monday July 03, 2023 @05:10PM (#36578883)
Even thought the data resides mostly in-memory they still have to write transactions to disk to preserve them, don't they?