ZoneTree is a persistent, high-performance, transactional, ACID-compliant ordered key-value database for NET. It can operate in memory or on local/cloud storage.
$ dotnet add package ZoneTreeZoneTree is a persistent, high-performance key-value database for .NET. It can operate in memory or on disk. (Optimized for SSDs)
ZoneTree is a fast and high-performance LSM Tree for .NET.
LSM Tree (Log-structured merge-tree) is the most popular data structure and it is being used by many popular databases internally.
2 Million int key and int value inserts in 7 seconds. (Config: 1M mutable segment size, 2M readonly segments merge-threshold)
20 Million int key and int value inserts in 73 seconds. (Config: 1M mutable segment size, 2M readonly segments merge-threshold)
20 Million int key and int value reads in 16 seconds. (Config: 1M mutable segment size, 2M readonly segments merge-threshold)
Doing database benchmark is tough. A proper and fair performance analysis requires a lot of work.
For now, we are confident that ZoneTree is fast enough to be used in production.
var dataPath = "data/mydatabase";
var walPath = "data/mydatabase/wal";
using var zoneTree = new ZoneTreeFactory<int, string>()
.SetComparer(new IntegerComparerAscending())
.SetDataDirectory(dataPath)
.SetWriteAheadLogDirectory(walPath)
.SetKeySerializer(new Int32Serializer())
.SetValueSerializer(new Utf8StringSerializer())
.OpenOrCreate();
// upsert a key-value pair.
zoneTree.Upsert(39, "Hello Zone Tree!");
// atomically update a record in database. (thread-safe)
zoneTree.TryAddOrUpdateAtomic(39, "a", (x) => x + "b");
Big LSM Trees require maintenance tasks. ZoneTree provides the IZoneTreeMaintenance interface to give you full power on maintenance tasks. It also comes with a default maintainer to let you focus on your business logic without wasting time with LSM details. You can start using the default maintainer like in the following sample code. Note: For small data you don't need a maintainer.
var dataPath = "data/mydatabase";
var walPath = "data/mydatabase/wal";
// 1. Create your ZoneTree
using var zoneTree = new ZoneTreeFactory<int, string>()
.SetComparer(new IntegerComparerAscending())
.SetDataDirectory(dataPath)
.SetWriteAheadLogDirectory(walPath)
.SetKeySerializer(new Int32Serializer())
.SetValueSerializer(new Utf8StringSerializer())
.OpenOrCreate();
using var maintainer = new BasicZoneTreeMaintainer<int, string>(zoneTree);
// 2. Read/Write data
zoneTree.Upsert(39, "Hello ZoneTree!");
// 3. Complete maintainer running tasks.
maintainer.CompleteRunningTasks().AsTask().Wait();I am going to write more detailed documentation as soon as possible.
I appreciate any contribution to the project. These are the things I do think we need at the moment: