public void Emit(ConnectionMetrics metrics) { var sb = new StringBuilder(nameof(ConnectionMetrics) + " {\n"); sb.Append($"\tconnection ID: {metrics.connection_id}\n"); sb.Append($"\tendpoints: {metrics.local_endpoint} <-> {metrics.remote_endpoint}\n"); sb.Append($"\tduration millis: {metrics.duration_millis}\n"); sb.Append($"\tshutdown reason: {metrics.shutdown_reason}\n"); sb.Append("}\n"); Console.Write(sb); }
public static RequestMetrics StartRequestMetrics(ConnectionMetrics connectionMetrics) { return new RequestMetrics { request_id = NewId(), connection_id = connectionMetrics.connection_id, local_endpoint = connectionMetrics.local_endpoint, remote_endpoint = connectionMetrics.remote_endpoint, error = null }; }
public static RequestMetrics StartRequestMetrics(ConnectionMetrics connectionMetrics) { return(new RequestMetrics { request_id = NewId(), connection_id = connectionMetrics.connection_id, local_endpoint = connectionMetrics.local_endpoint, remote_endpoint = connectionMetrics.remote_endpoint, error = null }); }
public void ProgressQueue(DateTime currentTime) { if (!IsActive) { return; } if (_waitTimer < 0) { _waitTimer = 0; } var connectionMetrics = new ConnectionMetrics() { MessagesInQueue = _queue.Count, Throughput = _settings.Bandwidth, Time = currentTime, Connection = string.Join('-', _settings.NodeIds), Tag = ResourceProvider.Tag }; while (_waitTimer < _timeDelta) { var dataToTransmit = _queue.TryDequeue(out var data); if (!dataToTransmit) { break; } _waitTimer += data.Delay; var capacity = _timeDelta - _waitTimer < 0 ? 0 : _timeDelta - _waitTimer; data.Delay -= capacity; if (data.Delay <= 0) { data.Receiver.Receive(data.Message); continue; } // Should split available bandwidth equally between all messages _queue.Enqueue(data); } connectionMetrics.MessagesSent = connectionMetrics.MessagesInQueue - _queue.Count; connectionMetrics.Load = _waitTimer / _timeDelta; ResourceProvider.MetricsLogger.WriteConnectionMetrics(connectionMetrics); _waitTimer -= _timeDelta; }
private static RequestMetrics StartRequestMetrics(string methodName, ConnectionMetrics connectionMetrics) { var requestMetrics = new RequestMetrics { request_id = Guid.NewGuid().ToString(), connection_id = connectionMetrics.connection_id, local_endpoint = connectionMetrics.local_endpoint, remote_endpoint = connectionMetrics.remote_endpoint, method_name = methodName, error = null }; return(requestMetrics); }
public async Task DispatchEvent( string methodName, ReceiveContext context, IMessage message, ConnectionMetrics connectionMetrics) { var totalTime = Stopwatch.StartNew(); Stopwatch serviceTime = null; var requestMetrics = StartRequestMetrics(methodName, connectionMetrics); Log.Information("{0}.{1}: Got event [{2}] from {3}.", nameof(ServiceHost), nameof(DispatchEvent), methodName, context.Connection); ServiceMethodInfo methodInfo; lock (dispatchTableLock) { if (!dispatchTable.TryGetValue(methodName, out methodInfo)) { Log.Error("{0}.{1}: Got request for unknown method [{2}].", nameof(ServiceHost), nameof(DispatchEvent), methodName); return; } } if (methodInfo.CallbackType != ServiceCallbackType.Event) { Log.Error("{0}.{1}: Method [{2}] invoked as if it were {3}, but it was registered as {4}.", nameof(ServiceHost), nameof(DispatchEvent), methodName, ServiceCallbackType.Event, methodInfo.CallbackType); return; } try { serviceTime = Stopwatch.StartNew(); await methodInfo.Callback(message, context, CancellationToken.None); } catch (Exception ex) { Log.Error(ex, "{0}.{1}: Failed to complete method [{2}]. With exception: {3}", nameof(ServiceHost), nameof(DispatchEvent), methodName, ex.Message); } FinishRequestMetrics(requestMetrics, totalTime, serviceTime); Metrics.Emit(requestMetrics); }
public void Emit(ConnectionMetrics metrics) { Sink?.Emit(metrics); }
protected SendContext(ConnectionMetrics connectionMetrics, RequestMetrics requestMetrics) : base(connectionMetrics, requestMetrics) {}
protected ReceiveContext(ConnectionMetrics connectionMetrics, RequestMetrics requestMetrics) : base(connectionMetrics, requestMetrics) {}
public static void FinishConnectionMetrics(ConnectionMetrics connectionMetrics, Stopwatch duration) { connectionMetrics.duration_millis = duration.Elapsed.TotalMilliseconds; }
public void Emit(ConnectionMetrics metrics) { LastConnectionMetrics = metrics; ConnectionMetricsReceived++; }
public async Task <IMessage> DispatchRequest( string methodName, ReceiveContext context, IMessage message, ConnectionMetrics connectionMetrics) { var totalTime = Stopwatch.StartNew(); Stopwatch serviceTime = null; var requestMetrics = StartRequestMetrics(methodName, connectionMetrics); Log.Information("{0}.{1}: Got request [{2}] from {3}.", nameof(ServiceHost), nameof(DispatchRequest), methodName, context.Connection); ServiceMethodInfo methodInfo; lock (dispatchTableLock) { if (!dispatchTable.TryGetValue(methodName, out methodInfo)) { var errorMessage = "Got request for unknown method [" + methodName + "]."; Log.Error("{0}.{1}: {2}", nameof(ServiceHost), nameof(DispatchRequest), errorMessage); var error = new Error { message = errorMessage, error_code = (int)ErrorCode.MethodNotFound }; return(Message.FromError(error)); } } if (methodInfo.CallbackType != ServiceCallbackType.RequestResponse) { var errorMessage = "Method [" + methodName + "] invoked as if it were " + ServiceCallbackType.RequestResponse + ", but it was registered as " + methodInfo.CallbackType + "."; Log.Error("{0}.{1}: {2}", nameof(ServiceHost), nameof(DispatchRequest), errorMessage); var error = new Error { message = errorMessage, error_code = (int)ErrorCode.InvalidInvocation }; return(Message.FromError(error)); } IMessage result = null; try { serviceTime = Stopwatch.StartNew(); // Cast to appropriate return type which we validated when registering the service result = await(Task <IMessage>) methodInfo.Callback(message, context, CancellationToken.None); serviceTime.Stop(); } catch (Exception ex) { Log.Error(ex, "{0}.{1}: Failed to complete method [{2}]. With exception: {3}", nameof(ServiceHost), nameof(DispatchRequest), methodName, ex.Message); result = Message.FromError(Transport.MakeInternalServerError(ex)); } FinishRequestMetrics(requestMetrics, totalTime, serviceTime); Metrics.Emit(requestMetrics); return(result); }
public void Emit(ConnectionMetrics metrics) { ConnectionMetricses.Add(metrics); }
public void WriteConnectionMetrics(ConnectionMetrics connectionMetrics) { //var writeApi = _provider.GetWriteApi(); _writeApi.WriteMeasurement(WritePrecision.S, connectionMetrics); //_tasks.Add(task); }
protected ReceiveContext(ConnectionMetrics connectionMetrics, RequestMetrics requestMetrics) : base(connectionMetrics, requestMetrics) { }
protected SendContext(ConnectionMetrics connectionMetrics, RequestMetrics requestMetrics) : base(connectionMetrics, requestMetrics) { }
protected Context(ConnectionMetrics connectionMetrics, RequestMetrics requestMetrics) { ConnectionMetrics = connectionMetrics; RequestMetrics = requestMetrics; }
public SimpleInMemSendContext(SimpleInMemConnection connection, ConnectionMetrics connectionMetrics, RequestMetrics requestMetrics) : base(connectionMetrics, requestMetrics) { Connection = connection; }
public static void Emit(ConnectionMetrics metrics) { handler?.Handle(metrics); }
public EpoxyReceiveContext(EpoxyConnection connection, ConnectionMetrics connectionMetrics, RequestMetrics requestMetrics) : base(connectionMetrics, requestMetrics) { Connection = connection; }
public RelayEpoxySendContext(RelayEpoxyConnection connection, ConnectionMetrics connectionMetrics, RequestMetrics requestMetrics) : base(connectionMetrics, requestMetrics) { Connection = connection; }
public EpoxySendContext(EpoxyConnection connection, ConnectionMetrics connectionMetrics, RequestMetrics requestMetrics) : base(connectionMetrics, requestMetrics) { Connection = connection; }