Example #1
0
def serve(models, max_workers: int = 1, port: int = 9000):
    server = grpc.server(futures.ThreadPoolExecutor(max_workers=max_workers),
                         options=[('grpc.max_send_message_length', GIGABYTE),
                                  ('grpc.max_receive_message_length', GIGABYTE)
                                  ])
    prediction_service_pb2_grpc.add_PredictionServiceServicer_to_server(
        PredictionServiceServicer(models=models), server)
    model_service_pb2_grpc.add_ModelServiceServicer_to_server(
        ModelServiceServicer(models=models), server)
    server.add_insecure_port('[::]:{}'.format(port))
    server.start()
    logger.info("Server listens on port {port} and will be "
                "serving models: {models}".format(port=port,
                                                  models=list(models.keys())))
    try:
        while True:
            if FILE_SYSTEM_POLL_WAIT_SECONDS > 0:
                time.sleep(FILE_SYSTEM_POLL_WAIT_SECONDS)
                for model in models:
                    models[model].update()
            else:
                time.sleep(_ONE_DAY_IN_SECONDS)
    except KeyboardInterrupt:
        server.stop(0)
        sys.exit(0)
Example #2
0
def get_grpc_service_for_model_status(get_fake_model):
    _real_time = grpc_testing.strict_real_time()
    servicer = ModelServiceServicer(models={'test': get_fake_model})
    descriptors_to_servicers = {MODEL_SERVICE: servicer}
    _real_time_server = grpc_testing.server_from_dictionary(
        descriptors_to_servicers, _real_time)

    return _real_time_server