/// <inheritdoc /> public void Run(Action <string> log) { var dir = Path.GetTempPath(); try { var logger = new OperationLogger(dir); var payload = Enumerable.Range(0, PayloadSize).Select(i => (byte)i).ToArray(); var sw = new Stopwatch(); int gen0 = GC.CollectionCount(0), gen1 = GC.CollectionCount(1), gen2 = GC.CollectionCount(2); sw.Start(); for (int i = 0; i < OperationCount; i++) { var op = new OperationData(payload); logger.WriteOperations(i, op).GetAwaiter().GetResult(); } logger.Close(); sw.Stop(); var rate = OperationCount / sw.Elapsed.TotalSeconds; log($"OPerationLogger: {sw.Elapsed} QPS={rate:G3}"); log($" Gen0={GC.CollectionCount(0) - gen0} Gen1={GC.CollectionCount(1) - gen1} Gen2={GC.CollectionCount(2) - gen2}\n"); } finally { File.Delete(Path.Combine(dir, "0.log")); } }
/// <summary> /// Initializes a new instance of the <see cref="VegaServiceProviderReplica"/> class. /// </summary> /// <param name="serviceContext">Replicator service context.</param> public VegaServiceProviderReplica(ReplicatorServiceContext serviceContext) { this.serviceContext = serviceContext; // TODO: read directory name from setting this.operationLogger = new OperationLogger(this.serviceContext.ServiceContext.CodePackageActivationContext.LogDirectory); }
/// <inheritdoc/> protected override async Task RunAsync(CancellationToken cancellationToken) { // Find a better log directory this.operationLoggerPrimary = new OperationLogger(this.Context.CodePackageActivationContext.LogDirectory); FabricReplicator replicator = null; while ((replicator = this.serviceContext.Replicator) == null) { await Task.Delay(125).ConfigureAwait(false); } this.stateReplicator = replicator.StateReplicator; this.cancellationTokenSource = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken); var unusedTask = Task.Run(this.ProcessIncomingRequests); ServiceEventSource.Current.ServiceMessage(this.Context, "Replicator is ready"); try { while (!cancellationToken.IsCancellationRequested) { ServiceEventSource.Current.ServiceMessage( this.Context, "RunAsync alive: {0} - pending operations {1} LSN {2}", DateTime.UtcNow, this.pendingOperations.Count, this.lastSequenceNumber); await Task.Delay(1000 * 30, cancellationToken).ConfigureAwait(false); } } catch (TaskCanceledException) { } }