diff --git a/fe/fe-core/src/main/java/com/starrocks/common/Config.java b/fe/fe-core/src/main/java/com/starrocks/common/Config.java index 1258ae74db193..8fc344d95c1c0 100644 --- a/fe/fe-core/src/main/java/com/starrocks/common/Config.java +++ b/fe/fe-core/src/main/java/com/starrocks/common/Config.java @@ -569,6 +569,12 @@ public class Config extends ConfigBase { @ConfField public static int http_max_chunk_size = 8192; + /** + * If a request takes longer than the configured time, a log will be generated to trace it. + */ + @ConfField(mutable = true) + public static int http_slow_request_threshold_ms = 5000; + /** * When obtaining hardware information, some sensitive commands will be executed indirectly through * the oshi library, such as: getent passwd diff --git a/fe/fe-core/src/main/java/com/starrocks/http/rest/RestBaseAction.java b/fe/fe-core/src/main/java/com/starrocks/http/rest/RestBaseAction.java index b2052b0238a37..8ef481ecb0f43 100644 --- a/fe/fe-core/src/main/java/com/starrocks/http/rest/RestBaseAction.java +++ b/fe/fe-core/src/main/java/com/starrocks/http/rest/RestBaseAction.java @@ -35,6 +35,7 @@ package com.starrocks.http.rest; import com.fasterxml.jackson.databind.ObjectMapper; +import com.starrocks.common.Config; import com.starrocks.common.DdlException; import com.starrocks.common.Pair; import com.starrocks.common.util.UUIDUtil; @@ -68,6 +69,7 @@ public RestBaseAction(ActionController controller) { @Override public void handleRequest(BaseRequest request) throws Exception { LOG.info("receive http request. url={}", request.getRequest().uri()); + long startTime = System.currentTimeMillis(); BaseResponse response = new BaseResponse(); try { execute(request, response); @@ -81,6 +83,12 @@ public void handleRequest(BaseRequest request) throws Exception { sendResult(request, response, new RestBaseResult(e.getMessage())); } } + long endTime = System.currentTimeMillis(); + long elapsedTime = endTime - startTime; + if (elapsedTime > Config.http_slow_request_threshold_ms) { + LOG.warn("Execution uri={} time exceeded {} ms and took {} ms.", request.getRequest().uri(), + Config.http_slow_request_threshold_ms, elapsedTime); + } } @Override