private static async Task BenchSerialWriteAsync(IFdbDatabase db, int N, CancellationToken ct) { // read a lot of small keys, one by one Console.WriteLine($"=== BenchSerialWrite(N={N:N0}) ==="); var location = db.Root.ByKey("hello"); var sw = Stopwatch.StartNew(); IFdbTransaction trans = null; IDynamicKeySubspace subspace = null; try { for (int i = 0; i < N; i++) { if (trans == null) { trans = await db.BeginTransactionAsync(ct); subspace = await location.Resolve(trans); } trans.Set(subspace.Encode(i), Slice.FromInt32(i)); if (trans.Size > 100 * 1024) { await trans.CommitAsync(); trans.Dispose(); trans = null; } } await trans.CommitAsync(); } finally { trans?.Dispose(); } sw.Stop(); Console.WriteLine($"Took {sw.Elapsed.TotalSeconds:N3} sec to read {N:N0} items ({FormatTimeMicro(sw.Elapsed.TotalMilliseconds / N)}/read, {N/sw.Elapsed.TotalSeconds:N0} read/sec)"); Console.WriteLine(); }
private static async Task BenchSerialWriteAsync(IFdbDatabase db, int N, CancellationToken ct) { // read a lot of small keys, one by one var location = db.Partition("hello"); var sw = Stopwatch.StartNew(); IFdbTransaction trans = null; try { for (int i = 0; i < N; i++) { if (trans == null) { trans = db.BeginTransaction(ct); } trans.Set(location.Pack(i), Slice.FromInt32(i)); if (trans.Size > 100 * 1024) { await trans.CommitAsync(); trans.Dispose(); trans = null; } } await trans.CommitAsync(); } finally { if (trans != null) { trans.Dispose(); } } sw.Stop(); Console.WriteLine("Took " + sw.Elapsed + " to read " + N + " items (" + FormatTimeMicro(sw.Elapsed.TotalMilliseconds / N) + "/read)"); }
private async Task <List <PerformanceRecord> > WriteInternalAsync(string operation, IEnumerator <TestData> enumerator, long itemsPerTransaction, long numberOfTransactions, PerfTracker perfTracker, FdbDatabase db) { var sw = new Stopwatch(); byte[] valueToWrite = null; var records = new List <PerformanceRecord>(); var location = db.GlobalSpace; sw.Restart(); for (int transactions = 0; transactions < numberOfTransactions; transactions++) { sw.Restart(); using (IFdbTransaction tx = db.BeginTransaction()) { for (int i = 0; i < itemsPerTransaction; i++) { enumerator.MoveNext(); valueToWrite = GetValueToWrite(valueToWrite, enumerator.Current.ValueSize); tx.Set(location.Pack(enumerator.Current.Id), Slice.Create(valueToWrite)); } await tx.CommitAsync(); perfTracker.Record(sw.ElapsedMilliseconds); } sw.Stop(); records.Add(new PerformanceRecord { Operation = operation, Time = DateTime.Now, Duration = sw.ElapsedMilliseconds, ProcessedItems = itemsPerTransaction }); } sw.Stop(); return(records); }
public virtual Task CommitAsync() { ThrowIfDisposed(); return(m_transaction.CommitAsync()); }