seldon-core icon indicating copy to clipboard operation
seldon-core copied to clipboard

how to calculate every feature cost time in **wrapper.py**

Open zachma-820 opened this issue 1 year ago • 0 comments

how to calculate every feature cost time in wrapper.py I split every request data to json ,but it calls to OOM

    def Predict():
        requestJson = get_request(skip_decoding=PAYLOAD_PASSTHROUGH)
        data = ""
        biz_seq = ""
        sys_seq = ""
        if "jsonData" in requestJson:
            data = requestJson["jsonData"]
            if "biz_seq" in data:
                biz_seq = data["biz_seq"]
            if "sys_seq" in data:
                sys_seq = data["sys_seq"]
        logger.info("Predict Rest Request: %s, biz_seq: %s, sys_seq: %s", requestJson, biz_seq, sys_seq)

        if biz_seq == "" or sys_seq == "":
            final_response = seldon_core.seldon_methods.predict(
                user_model, requestJson, seldon_metrics
            )
        else:
            split_request_json_list, seq_list = _split_request_json_data(data)
            aggregate_predict_response_list = list()
            cost_time_list = list()
            for i, split_request_json in enumerate(split_request_json_list):
                logger.debug("Predict PER Rest Request: %s", split_request_json)
                start_time = int(time.time() * 1000)
                status = 0
                try:
                    response = seldon_core.seldon_methods.predict(
                        user_model, split_request_json, seldon_metrics
                    )
                except Exception as e:
                    status = 1
                    raise Exception(e)
                finally:
                    end_time = int(time.time() * 1000)
                    cost_time = end_time - start_time  # ms
                    logger.info("Predict PER Rest Sun task: %s, cost_time: %s", seq_list[i], cost_time)
                    cost_time_list.append(
                        {"biz_seq": biz_seq, "sys_seq": sys_seq, "service_global_id": SERVICE_GLOBAL_ID,
                         "start_time": start_time, "end_time": end_time, "trace_id": seq_list[i], "status": status,
                         "cost_time": cost_time})
                aggregate_predict_response_list.append(response)

            send_to_sidecar(cost_time_list)
            final_response = _aggregate_response_json_data(aggregate_predict_response_list)

        json_response = jsonify(final_response, skip_encoding=PAYLOAD_PASSTHROUGH)
        if (
                isinstance(final_response, dict)
                and "status" in final_response
                and "code" in final_response["status"]
        ):
            json_response.status_code = final_response["status"]["code"]

        if biz_seq != "":
            logger.info("Predict REST Response: %s, biz_seq is : %s, sys_seq is: %s", final_response, biz_seq,
                        sys_seq)
        else:
            logger.info("Predict REST Response: %s", final_response)
        return json_response

zachma-820 avatar Oct 14 '24 10:10 zachma-820