Skip to content

Commit a9a8e7b

Browse files
Add the option to enable GRPC health checking to model_server. This is useful for clients that want to use health checking with load balancing channels (if not we get errors on the client side). The current implementation is trivial, once we open our serving port we assume we we always be healthy but users may want to tweak this, specially if they need a mandated version, etc.
PiperOrigin-RevId: 608545737
1 parent ae9da21 commit a9a8e7b

File tree

4 files changed

+19
-5
lines changed

4 files changed

+19
-5
lines changed

tensorflow_serving/model_servers/BUILD

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -498,6 +498,7 @@ cc_library(
498498
"//tensorflow_serving/servables/tensorflow:thread_pool_factory_config_cc_proto",
499499
"//tensorflow_serving/servables/tensorflow:util",
500500
"//tensorflow_serving/util:proto_util",
501+
"@com_github_grpc_grpc//:grpc",
501502
"@com_github_grpc_grpc//:grpc++",
502503
"@com_google_absl//absl/memory",
503504
"@com_google_protobuf//:cc_wkt_protos",

tensorflow_serving/model_servers/main.cc

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -297,10 +297,12 @@ int main(int argc, char** argv) {
297297
"If non-empty, read an ascii ThreadPoolConfig protobuf "
298298
"from the supplied file name."),
299299
tensorflow::Flag("mixed_precision", &options.mixed_precision,
300-
"specify mixed_precision mode"),
300+
"specify mixed_precision mode"),
301301
tensorflow::Flag("skip_initialize_tpu", &options.skip_initialize_tpu,
302-
"Whether to skip auto initializing TPU.")};
303-
302+
"Whether to skip auto initializing TPU."),
303+
tensorflow::Flag("enable_grpc_healthcheck_service",
304+
&options.enable_grpc_healthcheck_service,
305+
"Enable the standard gRPC healthcheck service.")};
304306

305307
const auto& usage = tensorflow::Flags::Usage(argv[0], flag_list);
306308
if (!tensorflow::Flags::Parse(&argc, argv, flag_list)) {

tensorflow_serving/model_servers/server.cc

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ limitations under the License.
2525

2626
#include "google/protobuf/wrappers.pb.h"
2727
#include "grpc/grpc.h"
28+
#include "grpcpp/health_check_service_interface.h"
2829
#include "grpcpp/resource_quota.h"
2930
#include "grpcpp/security/server_credentials.h"
3031
#include "grpcpp/server_builder.h"
@@ -404,8 +405,17 @@ Status Server::BuildAndStart(const Options& server_options) {
404405
::grpc::ResourceQuota res_quota;
405406
res_quota.SetMaxThreads(server_options.grpc_max_threads);
406407
builder.SetResourceQuota(res_quota);
407-
408+
::grpc::EnableDefaultHealthCheckService(
409+
server_options.enable_grpc_healthcheck_service);
408410
grpc_server_ = builder.BuildAndStart();
411+
412+
if (server_options.enable_grpc_healthcheck_service) {
413+
grpc_server_->GetHealthCheckService()->SetServingStatus("ModelService",
414+
true);
415+
grpc_server_->GetHealthCheckService()->SetServingStatus("PredictionService",
416+
true);
417+
}
418+
409419
if (grpc_server_ == nullptr) {
410420
return errors::InvalidArgument("Failed to BuildAndStart gRPC server");
411421
}

tensorflow_serving/model_servers/server.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,8 @@ class Server {
103103
bool enable_profiler = true;
104104
tensorflow::string mixed_precision;
105105
bool skip_initialize_tpu = false;
106-
106+
// Misc GRPC features
107+
bool enable_grpc_healthcheck_service = false;
107108
Options();
108109
};
109110

0 commit comments

Comments
 (0)