Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
zachma-820 opened this issue Oct 14, 2024 · 0 comments
Open

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

zachma-820 opened this issue Oct 14, 2024 · 0 comments

Comments

@zachma-820
Copy link

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 zachma-820 changed the title how to calculate every feature cost time in wrapper.py how to calculate every feature cost time in **wrapper.py** Oct 14, 2024
@zachma-820 zachma-820 reopened this Dec 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant