317 points · by cwinter · 8y ago · 129 comments
So if not memory-bandwidth, what is the constraining factor? Or specifically, what's the limiting factor that causes the observed benchmark speeds for LocustDB?
My guess would be that a well designed in-memory database should be limited by memory-bandwidth, but that real-world memory-bandwidth shouldn't be thought of as a single number. Instead, it depends on the size and pattern of requests, the latency of different cache hierarchies, and (crucially but often forgotten) on the number of requests in flight.
Is there a better terminology that distinguishes these two uses of memory-bandwidth?
Of course you are right that this is not the whole picture, it is possible to be bottlenecked on neither memory bandwidth nor CPU throughput.
With respect to memory, two additional considerations are read amplification and latency.
Read amplification: Read amplification basically means that you are reading data but not actually using it. Suppose we have a table stored in row format with four columns C1, C2, C3, C4 which store 8 byte integers. Row format means that the values for the columns are interleaved, so the memory layout would look like this, where cn refers to some value for column Cn:
0x0000 c1 c2 c3 c4 c1 c2 c3 c4
0x0040 c1 c2 c3 c4 c1 c2 c3 c4
...
One property of conventional memory is that we can only read memory in blocks of 64bytes (the size of a cache line).
So if we have a loop that sums of all of the values in C1, we will actually also load all of the values for columns C2, C3, C4.
This means we have a read amplification of factor 4, and our usable bandwidth will be a quarter of the theoretical maximum.Latency: Suppose we also don't have any read amplification and make use of all values for each loaded cache line. Then after we finish processing a cache line, and load the next cache line, we might have to wait a long time (100s of cycles) before the new cache line actually arrives! So then we would actually be stalled because of memory latency during some parts of program execution.
One of the big advantages of using columnar layout (which stores all values for a column sequentially) is that it all but eliminates read amplification. Similarly, by accessing data sequentially we make it possible for the CPU to predict what data will be accessed in the future, and have it loaded into the cache before we even request it.
Of course there's a number of reasons why things might not work out quite so perfectly in practice, and those may why performance in this benchmark starts to degrade before the (usable) memory bandwidth reaches the theoretical maximum memory bandwidth. But as you can see it still possible to get very close, so it's safe to assume that queries which read much less data than the maximum bandwidth are constrained on CPU.
The constraining factor in this case is CPU throughput.
When you looked at it with VTune, did you find clear evidence of this? That is, were you consistently executing 4 instructions per cycle, or were you maxed out at 100 percent utilization for a particular execution port? While it's possible to be at these limits (say if you were hashing each input) in most cases I think it's rare to get to that point when reading from RAM.
Similarly, by accessing data sequentially we make it possible for the CPU to predict what data will be accessed in the future, and have it loaded into the cache before we even request it.
One important caveat to this (at least on Intel) is that the hardware prefetcher does not cross 4KB page boundaries. So if you are doing an 8B read every cycle, and if you are able to do your other processing in the other 3 µops available that cycle, it's taking you ~500 cycles to process each page. And then you hit a ~200 cycle penalty when you finish each page, which means you are taking a ~25% performance hit because of memory latency, and probably have a CPI closer to 3 rather than 4! So if you (or your compiler) haven't already done so, you might see a useful performance boost by adding in explicit prefetch statements (one per cacheline) for the next page ahead.
Anyway, thanks for your response. I like your approach, and I wish you luck in making it even faster!
Your other points make sense. And those would surface as constraints in a similar fashion as a CPU throughput limitation would. I just expect those well before a CPU constraint.
I confess I have not researched CPU speeds in quite a while. Nor RAM speeds. Just surprised to see that the CPU's throughput would ever really be the bottleneck.
Sort of. Random main memory access speeds aren't there, but L1 is; as long as your memory accesses are sequential, proper coding can stream sequential main memory into L1 and keep the CPU working.
But it's effectively a lost art - the vast majority of programs spend a significant part of their time stalling on memory access.
If you take any basic computer architecture class you'd know that this is not the case. Unless there are breakthroughs within the past 5 years i have not read about. DRAM is at least 10x slower than CPU. Unless your prefetcher is so accurate it can feed the i-cache/d-cache without any stalls on the CPU side.
theoretical peak bandwidth
effective/observed bandwidth
I'm looking for a different denominator, which is also theoretical. Maybe call it the "theoretically achievable bandwidth", which takes into account all the details of the requests. If the "observed bandwidth" equals the "theoretically achievable bandwidth", your only path to improvement is to change your data layout or increase the parallelism of your requests. If the "observed bandwidth" is less than this theoretical, there should still be room for implementation optimizations.
Falling short of the "theoretical peak bandwidth" (even by a lot) doesn't tell you which of these is the case.
All of these "fast" databases have a fatal flaw - it takes forever to load the data in the first place. In this case loading takes >1000x longer than the query so loading is all that matters.
Your complaint only makes sense if you only intend to perform one single query against a dataset.
The response time is quite fantastic (less than a minute), but there are drawbacks: - GC takes in the order of minutes to complete - loading the data takes 90 min from spinning rust
So yeah, it's possible, but your bottleneck becomes the storage driver.
Source: I work at SAP's internal cloud team. For our internal customers running SAP HANA, we offer baremetal machines with up to 6 TiB RAM.
Heavy fixed processing costs up front with the benefit of light variable processing moving forward.
It's far from the correct title. A good part of the optimisation of all modern analysis DBs is in-memory... this is no different and as such he's compared his work against 2 of the major other systems in the space.
I see a lot of critics here... I think the guy should be congratulated for his work - which if you've read through all pages, appears to be done single handed!
There's a lot more to data analysis than loading data off disk.
They even admit that they couldn't be bothered to modify their ingestion scripts to not partition their data.
> One note about the results for kdb+: The ingestion scripts I used for kdb+ partition/index the data on the year and passenger_count columns. This may give it a somewhat unfair advantage over ClickHouse and LocustDB on all queries that group or filter on these columns (queries 2, 3, 4, 5 and 7). I was going to figure out how to remove that partitioning and report those results as well, but didn’t manage before my self-imposed deadline.
>The pickup_ntaname column is stored as varchars by ClickHouse and kdb+, and as dictionary encoded single byte values by LocustDB.
But it would be trivial to convert to enum/sym type in kdb+. It's silly to query and group by strings.
But even then, hardware/networking performance and tuning can throw a wrench in the most seasoned/knowledgeable approaches. Users can further bring otherwise solid setups to a grinding halt with unanticipated use-cases.
The only hope when you hit these inevitable road-blocks is that you're working for someone that appreciates the difficulty of the problem.
Looking over the queries, he made some... interesting changes that have him benchmarking oranges to apples.
So yeah, maybe the guy has no idea what to do with kdb - but ultimately having a fast, free and open-source database & query language beats a fast and expensive piece of commercial software.
Having read both this post and the documentation for TrailDB, I don’t think they are comparable past very simple use cases. This post seems to be covering a complete database system with a query parser, planner, and (previously?) a storage engine. TrailDB is more like a storage engine you can push certain kinds of filters down into, but performs neither query parsing nor planning for you.
I also wouldn't be surprised if someone has done a sqlite backend for it.
How to Analyze Billions of Records per Second on a Supercomputer
Present:
How to Analyze Billions of Records per Second on a Single Desktop PC
Future:
How to Analyze 5 Records per Second on Thousands of Machines Distributed Across the Globe Over the Blockchain.
If you're processing an amount of data that comfortably fits in memory on a single machine, then obviously Hadoop is going to perform poorly in comparison. The costs of scheduling a job onto N mappers/reducers, transferring code to each node, waiting for the slowest mapper/reducer to finish, transferring data from mappers -> reducers, replicating output on HDFS, etc. are well-understood. It's true that many people try to use Hadoop when they'd be better served with simpler solutions, but that does not justify the amount of shade that the author throws at it.
In that article, the author runs a regular expression that looks lines that start with "Result" in the pgn files. Then they do a tiny bit of processing with awk.
In the original article[0] the author completely parses the pgn files. Then they extract the result from the parsed file.
I wouldn't be surprised if the difference came completely from that.
I would love to see someone run benchmark the exact same program and see how much of a difference there really is between Hadoop and Bash.
[0] https://web.archive.org/web/20140119221101/http://tomhayden3...
366,000 RPS on a laptop: https://adamdrake.com/big-data-small-machine.html
There is an axiom that software gets bigger, for no particularly good reason, for at least 40 years.
This can be witnessed in how the size of /bin/true on Unix went from 0 bytes to whatever size it is today [1]. I can't find it now, but there was an article with a bar chart showing a gradual progression through time.
Of course, on-disk size doesn't translate directly to performance, but the trivial example demonstrates mechanisms by which bloat/cruft can accumulate so gradually that no outcry is ever caused.
It also refutes the sibling/downthread comment the "cruft" is (necessarily) someone else's use case.
[1] e.g. 13k MacOS native, 52k GNU coreutils from MacPorts
Sounds like a computer variant of Parkinson's law: "Work expands to fill the time available for its completion."
Why does the Word window not appear within milliseconds of me clicking on the application icon?
And that's with non-optimized code!
I now hear actual data scientists complain that startups trying to hire them think they have "big data" problems when all they have are "data" problems.