private unsafe int GetOverflowPageHeaderSize() { if (((int)_openFlags & (int)LMDBEnvironmentFlags.WriteMap) == 0) { throw new InvalidOperationException("OverflowPageHeaderSize requires DbEnvironmentFlags.WriteMap flag"); } using (var txn = BeginTransaction()) { GCHandle handle; try { var db = new Database("temp", txn._impl, new DatabaseConfig(DbFlags.Create)); var bufferRef = 0L; var keyPtr = Unsafe.AsPointer(ref bufferRef); var key1 = new DirectBuffer(8, (nint)keyPtr); var value = DirectBuffer.LengthOnly((uint)PageSize * 10); db.Put(txn, ref key1, ref value, TransactionPutOptions.ReserveSpace); db.Dispose(); return(checked ((int)(((IntPtr)value.Data).ToInt64() % PageSize))); } finally { txn.Abort(); } } }
public unsafe void SimpleWriteReadBatchedBenchmark() { #pragma warning disable 618 Settings.DoAdditionalCorrectnessChecks = false; #pragma warning restore 618 var count = TestUtils.GetBenchCount(TestUtils.InDocker ? 100_000 : 1_000_000, 100_000); var rounds = 10; var extraRounds = 10; var path = "./data/benchmarkbatched"; if (Directory.Exists(path)) { Directory.Delete(path, true); } var dirS = Path.Combine(path, "Spreads"); var dirK = Path.Combine(path, "KdSoft"); Directory.CreateDirectory(dirS); Directory.CreateDirectory(dirK); var envS = LMDBEnvironment.Create(dirS, LMDBEnvironmentFlags.MapAsync, disableAsync: true); envS.MaxDatabases = 10; envS.MapSize = 256 * 1024 * 1024; envS.Open(); // envS.TouchSpace(100); Console.WriteLine("USED SIZE: " + envS.UsedSize); var dbS = envS.OpenDatabase("SimpleWrite", new DatabaseConfig(DbFlags.Create | DbFlags.IntegerKey)); for (int i = 0; i < 2; i++) { using (var txn = envS.BeginTransaction(TransactionBeginFlags.NoSync)) { var key = 0L; var keyPtr = Unsafe.AsPointer(ref key); var key1 = new DirectBuffer(TypeHelper <int> .FixedSize, (nint)keyPtr); var value = DirectBuffer.LengthOnly(32 * 1024 * 1024); dbS.Put(txn, ref key1, ref value, TransactionPutOptions.ReserveSpace); txn.Commit(); } using (var txn = envS.BeginTransaction(TransactionBeginFlags.NoSync)) { var key = 0L; var keyPtr = Unsafe.AsPointer(ref key); var key1 = new DirectBuffer(TypeHelper <int> .FixedSize, (nint)keyPtr); dbS.Delete(txn, ref key1); txn.Commit(); } } // var garbage1 = new byte[1]; for (int r = 0; r < rounds; r++) { using (Benchmark.Run("Spreads Write", count, false)) { var tx = envS.BeginTransaction(); // using (tx) { for (long i = r * count; i < (r + 1) * count; i++) { dbS.Put(tx, i, i, TransactionPutOptions.AppendData); if (i % 10000 == 0) { tx.Commit(); tx.Dispose(); tx = envS.BeginTransaction(); } } tx.Commit(); tx.Dispose(); } } using (Benchmark.Run("Spreads Read", count * extraRounds, false)) { using (var tx = envS.BeginReadOnlyTransaction()) { for (long j = 0; j < extraRounds; j++) { for (long i = r * count; i < (r + 1) * count; i++) { dbS.TryGet(tx, ref i, out long val); if (val != i) { Assert.Fail(); } } } } } } dbS.Dispose(); envS.Close(); Benchmark.Dump("SimpleBatchedWrite/Read 10x1M longs"); // Console.WriteLine(garbage1[0]); }