Skip to content

Commit

Permalink
Rename WAL modes => Sync, SyncCompressed, AsyncCompressed, None
Browse files Browse the repository at this point in the history
  • Loading branch information
koculu committed Aug 23, 2022
1 parent f76c8d9 commit 682648e
Show file tree
Hide file tree
Showing 26 changed files with 128 additions and 131 deletions.
32 changes: 16 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ ZoneTree is a lightweight, transactional and high-performance LSM Tree for .NET.

It is several times faster than Facebook's RocksDB and hundreds of times faster than SQLite. It is faster than any other alternative that I have tested so far.
100 Million integer key-value pair inserts in 20 seconds. You may get longer durations based on the durability level.
For example, with Lazy WAL mode, you can insert 100M integer key-value pairs in 28 seconds. Background merge operation that might take a bit longer is excluded from the insert duration because your inserted data is immediately queryable.
For example, with async-compressed WAL mode, you can insert 100M integer key-value pairs in 28 seconds. Background merge operation that might take a bit longer is excluded from the insert duration because your inserted data is immediately queryable.
Loading 100M integer key-value pair database is in 812 ms. The iteration on 100M key-value pairs takes 24 seconds.
There are so many tuning options wait you to discover.

Expand All @@ -29,17 +29,17 @@ Benchmark for all modes: [benchmark](https://raw.githubusercontent.com/koculu/Zo

| Insert Benchmarks | 1M | 2M | 3M | 10M |
| ------------------------------------------------|---------|----------|------------|------------|
| int-int ZoneTree lazy WAL | 343 ms | 506 ms | 624 ms | 2328 ms |
| int-int ZoneTree compressed-immediate WAL | 885 ms | 1821 ms | 2737 ms | 9250 ms |
| int-int ZoneTree immediate WAL | 2791 ms | 5552 ms | 8269 ms | 27883 ms |
| int-int ZoneTree async-compressed WAL | 343 ms | 506 ms | 624 ms | 2328 ms |
| int-int ZoneTree sync-compressed WAL | 885 ms | 1821 ms | 2737 ms | 9250 ms |
| int-int ZoneTree sync WAL | 2791 ms | 5552 ms | 8269 ms | 27883 ms |
||
| str-str ZoneTree lazy WAL | 796 ms | 1555 ms | 2308 ms | 8712 ms |
| str-str ZoneTree compressed-immediate WAL | 1594 ms | 3187 ms | 4866 ms | 17451 ms |
| str-str ZoneTree immediate WAL | 3617 ms | 7083 ms | 10481 ms | 36714 ms |
| str-str ZoneTree async-compressed WAL | 796 ms | 1555 ms | 2308 ms | 8712 ms |
| str-str ZoneTree sync-compressed WAL | 1594 ms | 3187 ms | 4866 ms | 17451 ms |
| str-str ZoneTree sync WAL | 3617 ms | 7083 ms | 10481 ms | 36714 ms |
||
| RocksDb immediate WAL | NOT SUPPORTED |
| int-int RocksDb compressed-immediate WAL | 8059 ms | 16188 ms | 23599 ms | 61947 ms |
| str-str RocksDb compressed-immediate WAL | 8215 ms | 16146 ms | 23760 ms | 72491 ms |
| RocksDb sync WAL | NOT SUPPORTED |
| int-int RocksDb sync-compressed WAL | 8059 ms | 16188 ms | 23599 ms | 61947 ms |
| str-str RocksDb sync-compressed WAL | 8215 ms | 16146 ms | 23760 ms | 72491 ms |
||

Benchmark Configuration:
Expand All @@ -57,17 +57,17 @@ Tested up to 200M records in desktop computers till now.

### ZoneTree offers 4 WAL modes to let you make a flexible tradeoff.

* The Immediate mode provides maximum durability but slower write speed.
In case of a crash/power cut, the immediate mode ensures that the inserted data is not lost. RocksDb does not have immediate WAL mode. It has a WAL mode similar to the CompressedImmediate mode. ( reference: [rocksdb.org](http://rocksdb.org/blog/2017/08/25/flushwal.html) )
* The sync mode provides maximum durability but slower write speed.
In case of a crash/power cut, the sync mode ensures that the inserted data is not lost. RocksDb does not have sync WAL mode. It has a WAL mode similar to the sync-compressed mode. ( reference: [rocksdb.org](http://rocksdb.org/blog/2017/08/25/flushwal.html) )

* The CompressedImmediate mode provides faster write speed but less durability.
* The sync-compressed mode provides faster write speed but less durability.
Compression requires chunks to be filled before appending them into the WAL file.
It is possible to enable a periodic job to persist decompressed tail records into a separate location in a specified interval.
See IWriteAheadLogProvider options for more details.

* The Lazy mode provides faster write speed but less durability.
* The async-compressed mode provides faster write speed but less durability.
Log entries are queued to be written in a separate thread.
Lazy mode uses compression in WAL files and provides immediate tail record persistence.
async-compressed mode uses compression in WAL files and provides immediate tail record persistence.

* None WAL mode disables WAL completely to get maximum performance. Data still can be saved to disk by tree maintainer automatically or manually.

Expand Down Expand Up @@ -274,7 +274,7 @@ The following sample shows traditional way of doing transactions with ZoneTree.
| Supports optimistic transactions. |
| Supports Atomicity, Consistency, Isolation, Durability. |
| Supports Read Committed Isolation. |
| Immediate and Lazy modes for write ahead log. |
| 4 different modes for write ahead log. |
| Audit support with incremental transaction log backup. |
| Live backup. |
| Configurable amount of data that can stay in memory. |
Expand Down
6 changes: 3 additions & 3 deletions src/Playground/Benchmark/BenchmarkGroups.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ public static class BenchmarkGroups

static readonly WriteAheadLogMode[] TestWALModes = new[] {
WriteAheadLogMode.None,
WriteAheadLogMode.Lazy,
WriteAheadLogMode.CompressedImmediate,
WriteAheadLogMode.Immediate
WriteAheadLogMode.AsyncCompressed,
WriteAheadLogMode.SyncCompressed,
WriteAheadLogMode.Sync
};

static void Run(int count, WriteAheadLogMode? mode, Action<WriteAheadLogMode, int> job)
Expand Down
12 changes: 6 additions & 6 deletions src/Playground/Benchmark/ZoneTreeBenchmarks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,21 +31,21 @@ public void Setup()
}

[Benchmark]
public void Insert_1M_Lazy() => BenchmarkGroups.Insert1(1_000_000, WriteAheadLogMode.Lazy);
public void Insert_1M_Lazy() => BenchmarkGroups.Insert1(1_000_000, WriteAheadLogMode.AsyncCompressed);

[Benchmark]
public void Insert_3M1_Lazy() => BenchmarkGroups.Insert1(3_000_000, WriteAheadLogMode.Lazy);
public void Insert_3M1_Lazy() => BenchmarkGroups.Insert1(3_000_000, WriteAheadLogMode.AsyncCompressed);

[Benchmark]
public void Insert_1M_Immediate() => BenchmarkGroups.Insert1(1_000_000, WriteAheadLogMode.Immediate);
public void Insert_1M_Immediate() => BenchmarkGroups.Insert1(1_000_000, WriteAheadLogMode.Sync);

[Benchmark]
public void Insert_3M_Immediate() => BenchmarkGroups.Insert1(3_000_000, WriteAheadLogMode.Immediate);
public void Insert_3M_Immediate() => BenchmarkGroups.Insert1(3_000_000, WriteAheadLogMode.Sync);

[Benchmark]
public void Insert_1M_CompressedImmediate() => BenchmarkGroups.Insert1(1_000_000, WriteAheadLogMode.CompressedImmediate);
public void Insert_1M_CompressedImmediate() => BenchmarkGroups.Insert1(1_000_000, WriteAheadLogMode.SyncCompressed);

[Benchmark]
public void Insert_3M_CompressedImmediate() => BenchmarkGroups.Insert1(3_000_000, WriteAheadLogMode.CompressedImmediate);
public void Insert_3M_CompressedImmediate() => BenchmarkGroups.Insert1(3_000_000, WriteAheadLogMode.SyncCompressed);

}
10 changes: 5 additions & 5 deletions src/Playground/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@
TestConfig.DiskSegmentMode = DiskSegmentMode.SingleDiskSegment;
ConsoleLogger.DefaultLogLevel = LogLevel.Info;
//BenchmarkRunner.Run<ParallelMassiveInsertTests>();
//BenchmarkGroups.Iterate3(3_000_000, WriteAheadLogMode.CompressedImmediate)
//BenchmarkGroups.Iterate3(3_000_000, WriteAheadLogMode.SyncCompressed)
//RecoverFile.Recover2();
/*
while(true)
BenchmarkGroups.InsertIterate3(3_000_000, WriteAheadLogMode.CompressedImmediate);
BenchmarkGroups.InsertIterate3(3_000_000, WriteAheadLogMode.SyncCompressed);
*/

//Test1.TestTreeIteratorBehavior();
Expand Down Expand Up @@ -52,8 +52,8 @@
var m = 1_000_000;
var a = 10000;
BenchmarkGroups.Insert1(c);
ZoneTree1.InsertSingleAndMerge(WriteAheadLogMode.Lazy, c, m, a);
ZoneTree1.InsertSingleAndMerge(WriteAheadLogMode.CompressedImmediate, c, m, a);
ZoneTree1.InsertSingleAndMerge(WriteAheadLogMode.Immediate, c, m, a);
ZoneTree1.InsertSingleAndMerge(WriteAheadLogMode.AsyncCompressed, c, m, a);
ZoneTree1.InsertSingleAndMerge(WriteAheadLogMode.SyncCompressed, c, m, a);
ZoneTree1.InsertSingleAndMerge(WriteAheadLogMode.Sync, c, m, a);
BenchmarkGroups.Iterate1(c);
*/
6 changes: 3 additions & 3 deletions src/Playground/RecoverFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class RecoverFile
{
public static void Recover1()
{
var path = @"..\..\data\Lazy-50M-str-str";
var path = @"..\..\data\AsyncCompressed-50M-str-str";
var fileStreamProvider = new LocalFileStreamProvider();
var logger = new ConsoleLogger();
var deviceManager = new RandomAccessDeviceManager(logger, fileStreamProvider, path);
Expand All @@ -23,7 +23,7 @@ public static void Recover1()
Logger = logger,
WriteAheadLogProvider = new BasicWriteAheadLogProvider(new ConsoleLogger(), fileStreamProvider, path)
{
WriteAheadLogMode = WriteAheadLogMode.Lazy
WriteAheadLogMode = WriteAheadLogMode.AsyncCompressed
},
RandomAccessDeviceManager = deviceManager,
EnableDiskSegmentCompression = true,
Expand All @@ -40,7 +40,7 @@ public static void Recover1()

public static void Recover2()
{
var path = @"..\..\data\CompressedImmediate-3M-transactional-int-int";
var path = @"..\..\data\SyncCompressed-3M-transactional-int-int";
var logger = new ConsoleLogger();
var fileStreamProvider = new LocalFileStreamProvider();
var deviceManager = new RandomAccessDeviceManager(logger, fileStreamProvider, path);
Expand Down
4 changes: 2 additions & 2 deletions src/Playground/Test1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public static void SeveralParallelTransactions()
.SetWriteAheadLogDirectory(dataPath)
.ConfigureWriteAheadLogProvider(x =>
{
x.WriteAheadLogMode = WriteAheadLogMode.Immediate;
x.WriteAheadLogMode = WriteAheadLogMode.Sync;
x.EnableIncrementalBackup = true;
})
.OpenOrCreateTransactional();
Expand Down Expand Up @@ -85,7 +85,7 @@ public static void TestReverseIterator(
.ConfigureWriteAheadLogProvider(x =>
{
x.CompressionBlockSize = 1024 * 1024 * 20;
x.WriteAheadLogMode = WriteAheadLogMode.Lazy;
x.WriteAheadLogMode = WriteAheadLogMode.AsyncCompressed;
})
.Configure(x =>
{
Expand Down
24 changes: 12 additions & 12 deletions src/ZoneTree.UnitTests/AtomicUpdateTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ namespace Tenray.ZoneTree.UnitTests;

public class AtomicUpdateTests
{
[TestCase(WriteAheadLogMode.Immediate)]
[TestCase(WriteAheadLogMode.Lazy)]
[TestCase(WriteAheadLogMode.CompressedImmediate)]
[TestCase(WriteAheadLogMode.Sync)]
[TestCase(WriteAheadLogMode.AsyncCompressed)]
[TestCase(WriteAheadLogMode.SyncCompressed)]
public void IntIntAtomicIncrement(WriteAheadLogMode walMode)
{
var dataPath = "data/IntIntAtomicIncrement." + walMode;
Expand Down Expand Up @@ -76,9 +76,9 @@ public void IntIntAtomicIncrement(WriteAheadLogMode walMode)
data.Maintenance.DestroyTree();
}

[TestCase(WriteAheadLogMode.Immediate)]
[TestCase(WriteAheadLogMode.Lazy)]
[TestCase(WriteAheadLogMode.CompressedImmediate)]
[TestCase(WriteAheadLogMode.Sync)]
[TestCase(WriteAheadLogMode.AsyncCompressed)]
[TestCase(WriteAheadLogMode.SyncCompressed)]
public void IntIntAtomicIncrementForBTree(WriteAheadLogMode walMode)
{
var dataPath = "data/IntIntAtomicIncrementForBTree." + walMode;
Expand Down Expand Up @@ -140,9 +140,9 @@ public void IntIntAtomicIncrementForBTree(WriteAheadLogMode walMode)
data.Maintenance.DestroyTree();
}

[TestCase(WriteAheadLogMode.Immediate)]
[TestCase(WriteAheadLogMode.Lazy)]
[TestCase(WriteAheadLogMode.CompressedImmediate)]
[TestCase(WriteAheadLogMode.Sync)]
[TestCase(WriteAheadLogMode.AsyncCompressed)]
[TestCase(WriteAheadLogMode.SyncCompressed)]
public void IntIntMutableSegmentOnlyAtomicIncrement(WriteAheadLogMode walMode)
{
var dataPath = "data/IntIntMutableSegmentOnlyAtomicIncrement." + walMode;
Expand Down Expand Up @@ -204,9 +204,9 @@ public void IntIntMutableSegmentOnlyAtomicIncrement(WriteAheadLogMode walMode)
data.Maintenance.DestroyTree();
}

[TestCase(WriteAheadLogMode.Immediate)]
[TestCase(WriteAheadLogMode.Lazy)]
[TestCase(WriteAheadLogMode.CompressedImmediate)]
[TestCase(WriteAheadLogMode.Sync)]
[TestCase(WriteAheadLogMode.AsyncCompressed)]
[TestCase(WriteAheadLogMode.SyncCompressed)]
public void IntIntMutableSegmentSeveralUpserts(WriteAheadLogMode walMode)
{
var dataPath = "data/IntIntMutableSegmentSeveralUpserts." + walMode;
Expand Down
6 changes: 3 additions & 3 deletions src/ZoneTree.UnitTests/ExceptionlessTransactionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,9 @@ public async Task TransactionWithFluentAPI(int compactionThreshold)
// to prevent sleep intervals sum up on replacement.
if (compactionThreshold == 0)
{
x.WriteAheadLogMode = WAL.WriteAheadLogMode.Immediate;
x.LazyModeOptions.EmptyQueuePollInterval = 0;
x.CompressedImmediateModeOptions.TailWriterJobInterval = 0;
x.WriteAheadLogMode = WAL.WriteAheadLogMode.Sync;
x.AsyncCompressedModeOptions.EmptyQueuePollInterval = 0;
x.SyncCompressedModeOptions.TailWriterJobInterval = 0;
}
})
.OpenOrCreateTransactional();
Expand Down
2 changes: 1 addition & 1 deletion src/ZoneTree.UnitTests/FixedSizeKeyAndValueTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ private void ReloadIntIntTreeTestHelper(string dataPath, bool destroy)
.SetDataDirectory(dataPath)
.SetWriteAheadLogDirectory(dataPath)
.ConfigureWriteAheadLogProvider(x =>
x.WriteAheadLogMode = WriteAheadLogMode.Immediate)
x.WriteAheadLogMode = WriteAheadLogMode.Sync)
.SetIsValueDeletedDelegate((in int x) => x == -1)
.SetMarkValueDeletedDelegate((ref int x) => x = -1)
.OpenOrCreate();
Expand Down
8 changes: 4 additions & 4 deletions src/ZoneTree.UnitTests/OptimisticTransactionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ public void FirstTransaction(int compactionThreshold)
zoneTree.Maintenance.DestroyTree();
}

[TestCase(WriteAheadLogMode.Immediate)]
[TestCase(WriteAheadLogMode.Lazy)]
[TestCase(WriteAheadLogMode.Sync)]
[TestCase(WriteAheadLogMode.AsyncCompressed)]
public void SeveralParallelTransactions(WriteAheadLogMode walMode)
{
var dataPath = "data/SeveralParallelTransactions." + walMode;
Expand All @@ -81,8 +81,8 @@ public void SeveralParallelTransactions(WriteAheadLogMode walMode)
zoneTree.Maintenance.DestroyTree();
}

[TestCase(WriteAheadLogMode.Immediate)]
[TestCase(WriteAheadLogMode.Lazy)]
[TestCase(WriteAheadLogMode.Sync)]
[TestCase(WriteAheadLogMode.AsyncCompressed)]
public void SeveralParallelUpserts(WriteAheadLogMode walMode)
{
var dataPath = "data/SeveralParallelUpserts." + walMode;
Expand Down
2 changes: 1 addition & 1 deletion src/ZoneTree.UnitTests/WriteAheadLogTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public void WalBasicTest()
if (File.Exists(filePath))
File.Delete(filePath);
var serializer = new UnicodeStringSerializer();
var wal = new FileSystemWriteAheadLog<string, string>(
var wal = new SyncFileSystemWriteAheadLog<string, string>(
new ConsoleLogger(),
new LocalFileStreamProvider(),
serializer, serializer, filePath);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@
using System.Text;
using Tenray.ZoneTree.AbstractFileStream;
using Tenray.ZoneTree.Core;
using Tenray.ZoneTree.Exceptions;
using Tenray.ZoneTree.Exceptions.WAL;
using Tenray.ZoneTree.Serializers;

namespace Tenray.ZoneTree.WAL;

public sealed class LazyFileSystemWriteAheadLog<TKey, TValue> : IWriteAheadLog<TKey, TValue>
public sealed class AsyncCompressedFileSystemWriteAheadLog<TKey, TValue> : IWriteAheadLog<TKey, TValue>
{
readonly ILogger Logger;

Expand Down Expand Up @@ -54,7 +52,7 @@ public QueueItem(in TKey key, in TValue value, long opIndex)

public bool EnableIncrementalBackup { get; set; }

public LazyFileSystemWriteAheadLog(
public AsyncCompressedFileSystemWriteAheadLog(
ILogger logger,
IFileStreamProvider fileStreamProvider,
ISerializer<TKey> keySerializer,
Expand Down Expand Up @@ -289,7 +287,7 @@ public long ReplaceWriteAheadLog(TKey[] keys, TValue[] values, bool disableBacku
CancelWriter();
}
// Replacement crash recovery is not required here,
// because the lazy write ahead log is not durable.
// because the async-compressed write ahead log is not durable.
// implementing crash recovery here does not make it durable.
var existingLength = FileStream.Length;
FileStream.SetLength(0);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace Tenray.ZoneTree.WAL;

public sealed class LazyModeOptions
public sealed class AsyncCompressedModeOptions
{
/// <summary>
/// The delay in milliseconds before making the next poll
Expand Down
Loading

0 comments on commit 682648e

Please sign in to comment.