Rocks DB: One of tool to achieve lowest latency
Before we begin, if you are looking out to use RocksDB in your project then you are at right place, here in this article we are trying to cover one must know features of RocksDB. Article is quick summary of rocksdb. Article doesn't deep dive into intricate details, just setting an expectations here.
Let's begin now...
Client facing applications demands lightning speed real time latency, accessing data over the network can slowdown the response time at least by network roundtrip and IO. Applications cares to not lose fraction millisecond has to do something about network consuming latency as it's dominating factor.
In a client-server architecture where the database is hosted on an SSD, nearly half of the time is consumed by network latency, making it a significant bottleneck. The relative impact of this latency can vary based on hardware and network configurations. One potential solution to mitigate this issue is to implement a faster network.
Another solution to problem is to completely remove the network from architecture and move the storage near to application.
Will this model fits perfect in all applications? Well answer is No! you have to take concise decision based on your application use case.
What RocksDB is not?
Write Request Path
Read Request Path
Can we create tables in RocksDB like in other relational databases?
RocksDB has column family handler which is logical partition of key-value pairs. You can create multiple column family handlers and insert/read key-value pairs. To conclude the answer, Yes, in a way column family handler serve the same purpose as tables.
For intricate details - refer
What happens if the machine crashes while the application is running?
You will lose the database. You need to have your own ways to backup the database to durable storage. One way could be to backup database on some interval to durable storage and on crash restore database back on application startup. Application needs to be resilient enough to handle missing data scenarios and start from the last consistent state.
To know more details about backup - refer
How to retrieve data from RocksDB?
Here are several ways to retrieve data from RocksDB
Does RocksDB support Indexing?
RocksDB does not natively support indexing, it is flexible enough to allow developers to build and manage their own indexing mechanisms tailored to their application's requirements. Sample custom indexing demonstrated as below.
Index key/value payloads are light weight compared to real dataset key/value pairs.
领英推荐
Key: prefix,k1,v1 Value: v1
Key: prefix,k1,v2 Value: v2
Key: prefix,k1,v3 Value: v3
// Index
Key: index_prefix,v1 Value: prefix,k1,v1
Key: index_prefix,v2 Value: prefix,k1,v2
Key: index_prefix,v3 Value: prefix,k1,v3
What is the key ordering in RocksDB?
Organizes keys in lexicographical (or byte-wise) order by default. This ordering is based on the binary representation of the keys. Here’s a more detailed breakdown:
Byte-wise Lexicographical Order: Keys are compared byte by byte. This means that a shorter key might come before a longer key if the shorter key is a prefix of the longer one. For example, the key "abc" would come before the key "abcd".
Numerical Sorting: When keys are numeric, they are still compared based on their byte representation. Therefore, the string "10" will come before the string "2" because in lexicographical order, "1" is less than "2", and the first byte determines the order.
Custom Comparators: While the default is lexicographical order, RocksDB allows you to define custom comparators if you need a different sorting order for your keys. This can be useful for implementing specific application logic.
Does RocksDB support Transaction?
Yes, it does support transactions.
For more details - refer
Does RocksDB experience performance degradation in any scenario?
Yes, it does get's slower in some scenarios, this is coming from practical experience using rocksdb in real world project.
How can you manage the increasing database size in RocksDB?
This really depends on use-case, for us we were simply pruning the database which was keeping database size in check. We were moving rocksdb data to secondary storage for query purpose, any client query was served from secondary storage, this allowed us to prune the primary storage i.e. RocksDB and keep only active dataset.
How can you handle scenarios involving frequent deletions?
Again answer largely vary on use-case. We were triggering compaction immediately after deleting set of keys which was helping to retain the performance at large extend.
Compaction in RocksDB is a process that reorganizes data on disk to optimize storage utilization and improve read and write performance.
As data is written to RocksDB, old data versions and deleted data accumulate on disk. Compaction helps reclaim this space by removing obsolete data and consolidating live data.
How to avoid memory leaks?
Close the iterators and meta resources associated with iterators
What is Compaction in RocksDB?
Compaction in RocksDB is a process that reorganizes data on disk to optimize storage utilization and improve read and write performance. Here are the primary functions and benefits of compaction in RocksDB:
Where to look RocksDB performance benchmarking
Who all using RocksDB in Industry?
Reference
Arcesium | Walmart | Morgan Stanley | Yodlee
5 个月https://www.youtube.com/watch?v=7C3it10L-Jg