[ 
https://issues.apache.org/jira/browse/FLINK-10082?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16586105#comment-16586105
 ] 

ASF GitHub Bot commented on FLINK-10082:
----------------------------------------

zentol closed pull request #6580: [FLINK-10082][metrics][slf4j] Provide initial 
size to StringBuilder
URL: https://github.com/apache/flink/pull/6580
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git 
a/flink-metrics/flink-metrics-slf4j/src/main/java/org/apache/flink/metrics/slf4j/Slf4jReporter.java
 
b/flink-metrics/flink-metrics-slf4j/src/main/java/org/apache/flink/metrics/slf4j/Slf4jReporter.java
index 5efac30637f..124efe227a3 100644
--- 
a/flink-metrics/flink-metrics-slf4j/src/main/java/org/apache/flink/metrics/slf4j/Slf4jReporter.java
+++ 
b/flink-metrics/flink-metrics-slf4j/src/main/java/org/apache/flink/metrics/slf4j/Slf4jReporter.java
@@ -42,6 +42,9 @@
        private static final Logger LOG = 
LoggerFactory.getLogger(Slf4jReporter.class);
        private static final String lineSeparator = System.lineSeparator();
 
+       // the initial size roughly fits ~150 metrics with default scope 
settings
+       private int previousSize = 16384;
+
        @VisibleForTesting
        Map<Gauge<?>, String> getGauges() {
                return gauges;
@@ -72,7 +75,10 @@ public void close() {
 
        @Override
        public void report() {
-               StringBuilder builder = new StringBuilder();
+               // initialize with previous size to avoid repeated resizing of 
backing array
+               // pad the size to allow deviations in the final string, for 
example due to different double value representations
+               StringBuilder builder = new StringBuilder((int) (previousSize * 
1.1));
+
                builder
                        .append(lineSeparator)
                        .append("=========================== Starting metrics 
report ===========================")
@@ -134,6 +140,8 @@ public void report() {
                        .append("=========================== Finished metrics 
report ===========================")
                        .append(lineSeparator);
                LOG.info(builder.toString());
+
+               previousSize = builder.length();
        }
 
        @Override


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


> Initialize StringBuilder in Slf4jReporter with estimated size
> -------------------------------------------------------------
>
>                 Key: FLINK-10082
>                 URL: https://issues.apache.org/jira/browse/FLINK-10082
>             Project: Flink
>          Issue Type: Improvement
>          Components: Metrics
>    Affects Versions: 1.5.2, 1.6.0
>            Reporter: Chesnay Schepler
>            Assignee: Chesnay Schepler
>            Priority: Major
>              Labels: pull-request-available
>
> The {{Slf4jReporter}} uses a StringBuilder to generate the report that is 
> later logged. Currently we don't pass the initial size, which for large 
> deployments can result in frequent resizing of the backing array.
> We could either estimate the expected size based on the # of metrics, or 
> store the size of the last report (given that the total metrics space is 
> fairly constant).



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to