Пример #1
0
def run(ip, port):
    channel = grpc.insecure_channel('%s:%s' % (ip, port))
    stub = model_pb2_grpc.PredictServiceStub(channel)
    response = stub.Predict(
        model_pb2.input(inputType='string',
                        inputStream='This is a plain text transaction'))
    print('Response {res}'.format(res=response.status))
Пример #2
0
def run(ip, port):
    timestamp = Timestamp()
    timestamp.GetCurrentTime()
    channel = grpc.insecure_channel('%s:%s'%(ip, port))
    stub = prediction_pb2_grpc.ProxyServerStub(channel)
    response = stub.downstream(prediction_pb2.request(input_ = model_pb2.input(inputType = 'string', inputStream = 'hello'),src_uri = "localhost", seq = 1, req_id =1, timestamp = timestamp))
    print('Response\n{res}'.format(res=response.status))
Пример #3
0
    def Predict(self, request, context):

        print("received request:{request}\n".format(request=request))
        #        input_type = request.inputType
        #        input_stream = request.inputStream

        #        output = predict_fn.predict(input_stream)

        #        print("goes here")

        #        return test_pb2.response(status = output)

        if (self.model_name == None or self.model_port == None):
            return model_pb2.response(status="ModelNotSet")

        channel = grpc.insecure_channel('{model_name}:{model_port}'.format(
            model_name=self.model_name, model_port=self.model_port))
        stub = model_pb2_grpc.PredictServiceStub(channel)
        response = stub.Predict(
            model_pb2.input(inputType=request.inputType,
                            inputStream=request.inputStream))
        print(
            'Prediction request [{request}] sent to {model}:{response}'.format(
                request=request,
                model=self.model_name,
                response=response.status))

        input_type = request.inputType
        input_stream = response.status

        reply = "============Output From Model%s ============\n%s\n" % (
            self.model_name, response.status)

        for proxy in self.post_list:
            channel = grpc.insecure_channel('{proxy_name}:{proxy_port}'.format(
                proxy_name=proxy, proxy_port=self.proxy_port))
            stub = proxy_pb2_grpc.ProxyServiceStub(channel)
            response = stub.Predict(
                proxy_pb2.input(inputType=input_type,
                                inputStream=input_stream))
            print('Prediction request [{request}] sent to {proxy}:{response}'.
                  format(request=request,
                         proxy=proxy,
                         response=response.status))

            reply = reply + response.status

        return proxy_pb2.response(status=reply)
Пример #4
0
def main():
    ip = sys.argv[1]
    channel = grpc.insecure_channel('%s:%s'%(ip, 22223))
    stub = prediction_pb2_grpc.ProxyServerStub(channel)
    
    counter = 0


    while(1):
        timestamp = Timestamp()
        timestamp.GetCurrentTime()
        print("sending request to proxy on", ip)
        req_content = str(counter) 
        response = stub.downstream(prediction_pb2.request(input_ = model_pb2.input(inputType = 'string', inputStream = req_content),src_uri = "front-end", seq = counter, req_id = counter, timestamp = timestamp))
        print('Response\n{res}'.format(res=response.status))
        sleep(0.1)
        counter = counter + 1
Пример #5
0
    def call(self, address, input_type, output):

        print('[Call]Set up channel to %s' % (address))

        channel = grpc.insecure_channel("%s:22222" % (address))

        stub = model_pb2_grpc.PredictServiceStub(channel)

        if (len(self.forward_list) == 1):
            print('[Call] self.forward_list == 1, keep the reduce index')
            t = input_type  ## IF only one forward, keep the reduce index - which is input_type
        else:
            print('[Call] generate reduce index')
            t = str(self.forward_list.index(
                address))  ## [TODO] If seperate forward, generate reduce index

        print('[Call]%s Forward Index' % (t))

        response = stub.Predict(
            model_pb2.input(inputType=t, inputStream=output))
        print('[Call]Sent to {address}'.format(address=address))

        return response.outputStream
Пример #6
0
def puredag(address):
    channel = grpc.insecure_channel(address)
    stub = model_pb2_grpc.PredictServiceStub(channel)
    response = stub.Predict(
        model_pb2.input(inputStream="Hello", inputType="String"))