/// <summary> /// Loads model on server /// </summary> public void LoadModel() { var grpcClient = new TritonGrpcClient(); var models = new List <string> { _ModelName }; grpcClient.LoadModels(models, _IpAddress, GrpcPort); WaitUntilModelsLoaded(grpcClient); }
/// <summary> /// Checks that Triton server is running /// </summary> /// <returns>True if server running, else false</returns> public static bool IsServerRunning() { var client = new TritonGrpcClient(); if (IsPortReady(client)) { return(true); } return(false); }
/// <summary> /// Checks if the server's GRPC port is ready /// </summary> /// <param name="client">Triton's GRPC client.</param> /// <returns>True if port ready, else false.</returns> public static bool IsPortReady(TritonGrpcClient client) { bool ready; try { ready = client.GetStatus(_IpAddress, GrpcPort).ReadyState.Equals(ServerReadyState.ServerReady); } catch (Grpc.Core.RpcException exception) when(exception.StatusCode == Grpc.Core.StatusCode.Unavailable) { return(false); } return(ready); }
/// <summary> /// Process waits until the model is ready or times out /// </summary> /// <param name="client">Triton's GRPC client.</param> private void WaitUntilModelsLoaded(TritonGrpcClient client) { var timeoutSeconds = (int)_MaxRetryTime.TotalSeconds; for (var i = 0; i < timeoutSeconds; i++) { if (IsModelReady(client)) { return; } Thread.Sleep(TimeSpan.FromSeconds(1)); } throw new TimeoutException("Maximum loading time exceeded: models not yet ready"); }
/// <summary> /// Wait on process until the server's GRPC port is ready /// </summary> /// <param name="process">Process whose output to hide.</param> public void WaitUntilPortReady() { var client = new TritonGrpcClient(); var currentRetryDelay = _InitialRetryDelay; var currentRetryTime = TimeSpan.Zero; while (!IsPortReady(client)) { currentRetryDelay = currentRetryDelay > _MaxRetryDelay ? _MaxRetryDelay : currentRetryDelay; Thread.Sleep(currentRetryDelay); currentRetryTime += currentRetryDelay; currentRetryDelay *= RetryDelayMultiplier; if (currentRetryTime >= _MaxRetryTime) { throw new TimeoutException("Unable to connect to Triton port: maximum attempts reached"); } } }
/// <summary> /// Checks if model is loaded on server /// </summary> /// <param name="client">Triton's GRPC client.</param> /// <returns>Returns true if model loaded, else false.</returns> private bool IsModelReady(TritonGrpcClient client) { var models = client.GetStatus(_IpAddress, GrpcPort).ModelStatus; foreach (var model in models) { if (model.Key.Equals(_ModelName)) { foreach (var status in model.Value) { if (!status.Value.Equals(ModelReadyState.ModelReady)) { return(false); } } return(true); } } return(false); }