static async Task LogWriterAsync(FasterLog log, byte[] entry) { // Enter in some entries then wait on this separate thread await log.EnqueueAsync(entry); await log.EnqueueAsync(entry); await log.EnqueueAsync(entry); await log.WaitForCommitAsync(log.TailAddress); }
/// <summary> /// Async version of enqueue /// </summary> static async Task AsyncLogWriter(int id) { bool batched = false; await Task.Yield(); if (!batched) { // Single commit version - append each item and wait for commit // Needs high parallelism (NumParallelTasks) for perf // Needs separate commit thread to perform regular commit // Otherwise we commit only at page boundaries while (true) { try { await log.EnqueueAndWaitForCommitAsync(staticEntry); } catch (Exception ex) { Console.WriteLine($"{nameof(AsyncLogWriter)}({id}): {ex}"); } } } else { // Batched version - we enqueue many entries to memory, // then wait for commit periodically int count = 0; while (true) { await log.EnqueueAsync(staticEntry); if (count++ % 100 == 0) { await log.WaitForCommitAsync(); } } } }
public async ValueTask WaitForCommitAsync(long untilAddress = 0, CancellationToken token = default) { await logger.WaitForCommitAsync(untilAddress, token); }