This is an automated email from the ASF dual-hosted git repository. morningman pushed a commit to branch branch-1.2-lts in repository https://gitbox.apache.org/repos/asf/doris.git
commit deb35dbb3264da32c0a7ab925f631c599d6a98ab Author: Xiangyu Wang <[email protected]> AuthorDate: Sat Feb 4 22:53:44 2023 +0800 [Enhancement](profile) lazy load profileContent string (#16354) Sometimes the profileContent of ProfileElement is very large (more than 30MB), and this kind of huge string object may cause performance problems for gc. But we use them only when we invoke profile relevant restful apis (such as /profile/{format}/{query_id}, /api/profile and so on), so we need to lazy load them. --- .../apache/doris/common/util/ProfileManager.java | 23 ++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/fe/fe-core/src/main/java/org/apache/doris/common/util/ProfileManager.java b/fe/fe-core/src/main/java/org/apache/doris/common/util/ProfileManager.java index c569d10c82..63a4cda0e9 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/common/util/ProfileManager.java +++ b/fe/fe-core/src/main/java/org/apache/doris/common/util/ProfileManager.java @@ -88,10 +88,26 @@ public class ProfileManager { START_TIME, END_TIME, TOTAL_TIME, QUERY_STATE, TRACE_ID)); private class ProfileElement { + public ProfileElement(RuntimeProfile profile) { + this.profile = profile; + } + + private final RuntimeProfile profile; + // cache the result of getProfileContent method + private volatile String profileContent; public Map<String, String> infoStrings = Maps.newHashMap(); - public String profileContent = ""; public MultiProfileTreeBuilder builder = null; public String errMsg = ""; + + // lazy load profileContent because sometimes profileContent is very large + public String getProfileContent() { + if (profileContent != null) { + return profileContent; + } + // no need to lock because the possibility of concurrent read is very low + profileContent = profile.toString(); + return profileContent; + } } // only protect queryIdDeque; queryIdToProfileMap is concurrent, no need to protect @@ -123,12 +139,11 @@ public class ProfileManager { } public ProfileElement createElement(RuntimeProfile profile) { - ProfileElement element = new ProfileElement(); + ProfileElement element = new ProfileElement(profile); RuntimeProfile summaryProfile = profile.getChildList().get(0).first; for (String header : PROFILE_HEADERS) { element.infoStrings.put(header, summaryProfile.getInfoString(header)); } - element.profileContent = profile.toString(); MultiProfileTreeBuilder builder = new MultiProfileTreeBuilder(profile); try { @@ -213,7 +228,7 @@ public class ProfileManager { if (element == null) { return null; } - return element.profileContent; + return element.getProfileContent(); } finally { readLock.unlock(); } --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
