or
or
By clicking below, you agree to our terms of service.
New to HackMD? Sign up
Syntax | Example | Reference | |
---|---|---|---|
# Header | Header | 基本排版 | |
- Unordered List |
|
||
1. Ordered List |
|
||
- [ ] Todo List |
|
||
> Blockquote | Blockquote |
||
**Bold font** | Bold font | ||
*Italics font* | Italics font | ||
~~Strikethrough~~ | |||
19^th^ | 19th | ||
H~2~O | H2O | ||
++Inserted text++ | Inserted text | ||
==Marked text== | Marked text | ||
[link text](https:// "title") | Link | ||
 | Image | ||
`Code` | Code |
在筆記中貼入程式碼 | |
```javascript var i = 0; ``` |
|
||
:smile: | ![]() |
Emoji list | |
{%youtube youtube_id %} | Externals | ||
$L^aT_eX$ | LaTeX | ||
:::info This is a alert area. ::: |
This is a alert area. |
On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?
Please give us some advice and help us improve HackMD.
Do you want to remove this version name and description?
Syncing
xxxxxxxxxx
NOMT Design Decisions
Hash-Table: Triangular Probing
We have chosen to use triangular probing as our preferred hash-table algorithm instead of 3-ary cuckoo or Robinhood.
We wanted the following properties in our algorithm:
With meta-data bits in memory, Triangular probing fulfills all 3. It degrades gracefully beyond a .9 load factor, with fewer than 2 average probes per existing key query, and fewer than 1 average probes per absent key query even at that load factor with 4 or more meta-bits.
Note that triangular probing requires that the number of buckets is a power of two. A proof that it visits all the buckets is provided here: https://fgiesen.wordpress.com/2015/02/22/triangular-numbers-mod-2n/
An insert or delete operation only ever requires a single page write, which is optimal.
Manual DB Sizing
We have chosen to have the database operator manually choose a database size on node initialization. This database can only be re-sized either by creating a new node or with a special command while the node is not running. We do not perform in-flight resizing.
The reasoning for this choice:
Because our hash-table degrades in performance slowly, there is a long period of time during which a node operator can re-size their database. It will likely take months or years for a properly sized database to grow to 80% or 90% occupancy, providing the operator with a long window to upgrade.
Crash Consistency: Use SQLite's Assumptions
We have chosen to use the assumptions which SQLite makes, as regarding crash consistency. These assumptions strike a healthy balance between crash consistency and performance, while not being theoretically perfect. We expect our database to run in a replicated environment, where rare corruptions due to power loss are acceptable.
Quotes from the document on atomic commit (https://www.sqlite.org/atomiccommit.html)
Quotes from the document on Powersafe Overwrite (https://www.sqlite.org/psow.html)
(several of these properties are mostly corroborated by https://www.usenix.org/system/files/conference/osdi14/osdi14-paper-pillai.pdf)
Override RocksDB WAL with our own
We have chosen to override the RocksDB WAL for the purposes of consistency with our hash-table. We will create a separate WAL which contains updates to the flat key-value pairs as well as the diffs to pages in the hash-table. RocksDB provides a hook for listening to the operation sequence numbers committed to SST files, which we can use to prune the WALs as data is successfully flushed to disk by RocksDB.
IO system
After considering several options we have decided to go with io_uring as the primary IO interface.
It's worth talking about the alternatives that we considered and why we turned them down.
The traditional way to interact with IO is via the read/write syscalls and their modern counterparts. NOMT is built to achieve great speedups by taking advantage of parallelism of SSDs. To leverage that the app using sync read/write syscalls would need to use many threads. This turns out comes with a lot of overhead: context switching, syscall overheads, locking. While this may not be a bottleneck for NOMT, but the resources wasted on the overhead may be spent better spent elsewhere in the node.
A similar approach is to use mmap. At first it may seem very attractive because it solves some of the overheads that come with sync syscalls and it also provides a simple interface to work with. However, this simplicity is superficial. While it's easy to create a prototype with it it's rather hard to make the implementation robust. This is because of lack of control over when the pages get evicted, when the pages get flushed and it is not trivial to do error handling.
OTOH, mmap's performance is not as great as it's perceived. There are several reasons: TLB shootdown, eviction happening in a single thread and page table contention.[1]
Another way is linux-aio (also known as io_submit). This one provides an asynchronous interface to disk IO. However, it suffers from some downsides[2]:
In addition to that, io_uring offers a bunch of advanced features that could offer performance benefits.
SPDK is the king when it comes to performance. However, it's more limiting and harder to use. For example, it can only be used with NVMe devices directly without any FS. At the same time, io_uring can get close to SPDK[3]. Therefore, the risks do not seem to outweigh the potential benefits. Although it would be interesting to see what improvements it could provide as future work.
io_uring also has somedraw backs. Most of them stems from the fact that it's relatively new (5 years in trunk compared to 22 years of aio).
Yet, it seems already that it's getting some tangible adoption. To name a few examples:
Mostly though it's the new developments and it seems that the more established projects[4] have limited success of adopting io_uring even though the performance numbers show significant improvements.
Compatibility also doesn't seem to be a big problem. If using Debian as a conservative choice of a Linux distribution, then the current LTS version comes with the 6.1 kernel. This covers most of the available APIs.
The security of io_uring leaves much to be desired.
Google disables io_uring in ChromeOS and Android. At the same time they admit that:
However, and NOMT is a trusted component and this is not a significant concern for us.
Anecdotically, io_uring is disabled in Docker due to seccomp profiles. While this may be a problem for running a node in the a managed container service, this should not pose a problem for the operator controlled docker deployment.
To cater for the use-cases where io_uring is not supported and/or the utmost performance is not required (e.g. developers working on macOS), we are going to provide a fallback on the best effort basis (e.g. posix_aio or likely read/write syscalls coupled with a worker pool).
Split Update / Commit Functions
We have chosen to split the update and commit functions in order to enable users to support short-term forks. We will design this API to be flexible for differing users' needs.
While NOMT is a single-state database, users will likely need to handle short-term forks in some capacity. Even with "instant" finality, there may be blocks which are proposed, discarded, reordered, etc and so on.
The general approach is that we will have the
update
function return a set of page-diffs and accept as a parameter a set of page-diffs to build upon.The
commit
function will actually commit the changes to the disk, and will accept a set of page-diffs and key-value changes to commit. It will be the responsibility of the user to make sure these are consistent.Are You Sure You Want to Use MMAP in Your
Database Management System? ↩︎
Jens Axboe: Efficient IO with io_uring ↩︎
https://research.vu.nl/ws/portalfiles/portal/217956662/Understanding_Modern_Storage_APIs_A_systematic_study_of_libaio_SPDK_and_io_uring.pdf ↩︎
PostgreSQL, RocksDB. ↩︎