This is an automated email from the ASF dual-hosted git repository.
liuhongyu pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shenyu.git
The following commit(s) were added to refs/heads/master by this push:
new 5bd78ff6bc perf(logging): Optimize the performance of log collection
(#5931)
5bd78ff6bc is described below
commit 5bd78ff6bc303925a4e419153ca48b645ec92c4a
Author: zongmingzhi <[email protected]>
AuthorDate: Thu Feb 13 18:04:09 2025 +0800
perf(logging): Optimize the performance of log collection (#5931)
- Adjust the serialization timing of the request body and response body to
avoid unnecessary string operations.
- Perform string conversion only after confirming the need to record logs
to reduce resource consumption.
Co-authored-by: 宗杰 <[email protected]>
---
.../shenyu/plugin/logging/common/body/LoggingServerHttpRequest.java | 2 +-
.../shenyu/plugin/logging/common/body/LoggingServerHttpResponse.java | 4 ++--
2 files changed, 3 insertions(+), 3 deletions(-)
diff --git
a/shenyu-plugin/shenyu-plugin-logging/shenyu-plugin-logging-common/src/main/java/org/apache/shenyu/plugin/logging/common/body/LoggingServerHttpRequest.java
b/shenyu-plugin/shenyu-plugin-logging/shenyu-plugin-logging-common/src/main/java/org/apache/shenyu/plugin/logging/common/body/LoggingServerHttpRequest.java
index e930bd9dc6..b0b0fda8c7 100644
---
a/shenyu-plugin/shenyu-plugin-logging/shenyu-plugin-logging-common/src/main/java/org/apache/shenyu/plugin/logging/common/body/LoggingServerHttpRequest.java
+++
b/shenyu-plugin/shenyu-plugin-logging/shenyu-plugin-logging-common/src/main/java/org/apache/shenyu/plugin/logging/common/body/LoggingServerHttpRequest.java
@@ -56,11 +56,11 @@ public class LoggingServerHttpRequest<L extends
ShenyuRequestLog> extends Server
}
}).doFinally(signal -> {
int size = writer.size();
- String body = writer.output();
boolean requestBodyTooLarge =
LogCollectConfigUtils.isRequestBodyTooLarge(size);
if (size == 0 || requestBodyTooLarge) {
return;
}
+ String body = writer.output();
logInfo.setRequestBody(body);
});
}
diff --git
a/shenyu-plugin/shenyu-plugin-logging/shenyu-plugin-logging-common/src/main/java/org/apache/shenyu/plugin/logging/common/body/LoggingServerHttpResponse.java
b/shenyu-plugin/shenyu-plugin-logging/shenyu-plugin-logging-common/src/main/java/org/apache/shenyu/plugin/logging/common/body/LoggingServerHttpResponse.java
index 993ee380bd..bb3d260236 100644
---
a/shenyu-plugin/shenyu-plugin-logging/shenyu-plugin-logging-common/src/main/java/org/apache/shenyu/plugin/logging/common/body/LoggingServerHttpResponse.java
+++
b/shenyu-plugin/shenyu-plugin-logging/shenyu-plugin-logging-common/src/main/java/org/apache/shenyu/plugin/logging/common/body/LoggingServerHttpResponse.java
@@ -171,8 +171,8 @@ public class LoggingServerHttpResponse<L extends
ShenyuRequestLog> extends Serve
}
if (Objects.nonNull(writer)) {
int size = writer.size();
- String body = writer.output();
if (size > 0 &&
!LogCollectConfigUtils.isResponseBodyTooLarge(size)) {
+ String body = writer.output();
logInfo.setResponseBody(body);
}
} else {
@@ -261,8 +261,8 @@ public class LoggingServerHttpResponse<L extends
ShenyuRequestLog> extends Serve
}
int size = bytes.length;
- String body = new String(bytes, StandardCharsets.UTF_8);
if (size > 0 && !LogCollectConfigUtils.isResponseBodyTooLarge(size)) {
+ String body = new String(bytes, StandardCharsets.UTF_8);
logInfo.setResponseBody(body);
}
// collect log