private void Go(CommandRequest[] batch) { _batchSizes.Add(batch.Length); _journalWriter.AppendAsync(batch.Select(ctx => ctx.Command)) .ContinueWith(t => _dispatcher.Post(batch)); SetTimer(); }
/// <summary> /// Send the contents of the buffer to the /// journal and wait for the response /// </summary> private void Flush() { var commands = _buffer .Take(_bufferedRequests) .Select(e => e.Transaction as Command); _journal.AppendAsync(commands).Wait(); _bufferedRequests = 0; }
private void Go() { if (_commandBuffer.Count > 0) { var self = Self; var batch = _commandBuffer.ToArray(); var task = _journalWriter.AppendAsync(batch.Select(ctx => (Command)ctx.Transaction)); _commandBuffer.Clear(); _waitingForJournalAck.Enqueue(batch); task.ContinueWith(t => self.Tell(JournalAcknowledgement.Instance)); } }
private void QueueConsumer() { var buf = new List <Request>(10000); while (true) { Request request; if (_commandQueue.IsCompleted) { break; } //wait for a first item if (!_commandQueue.TryTake(out request, TimeSpan.FromSeconds(1))) { continue; } buf.Add(request); //take the rest but don't wait while (buf.Count < _batchSize && _commandQueue.TryTake(out request)) { buf.Add(request); } //at this point we have at least one request to process var requests = buf.ToArray(); buf.Clear(); var commands = requests.Select(r => (Command)r.Transaction); _journalWriter.AppendAsync(commands).ContinueWith(t => { foreach (var r in requests) { _executor.Push(r); } }); } }