You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@flink.apache.org by GitBox <gi...@apache.org> on 2022/04/07 19:33:48 UTC

[GitHub] [flink] smattheis opened a new pull request, #19398: [FLINK-26864] Fix performance regression from mailbox latency measuement

smattheis opened a new pull request, #19398:
URL: https://github.com/apache/flink/pull/19398

   ## What is the purpose of the change
   
   * Fix performance regression from mailbox latency measuement
   * __Note:__ The performance implications, i.e., recovery of performance values, are documented in https://issues.apache.org/jira/browse/FLINK-26864. (Please review the performance results in the linked issue.) 
   
   ## Brief change log
   
   * Trigger mailbox latency measurement from `MailboxProcessor` class instead from `StreamTask` class. This way, measurement can be initiated selectively only when mails are executed which is, in particular, on any non-poison mail.
   * To resolve cyclic dependencies between `MailboxProcessor` which starts mailbox measurement with `StreamTask` which holds references to `MailboxExecutor` and `TimerServices` that are both needed for scheduling mailbox latency measurements an additional class `MailboxMetricsController` is introduced that holds the dependencies and provides control functions. 
   
   ## Verifying this change
   
   Please make sure both new and modified tests in this PR follows the conventions defined in our code quality guide: https://flink.apache.org/contributing/code-style-and-quality-common.html#testing
   
   This change is already covered by existing tests that are updated respectively. The relevant tests are:
   * StreamTaskTest#testMailboxMetricsScheduling
   * StreamTaskTest#testMailboxMetricsMeasurement
   * TaskMailboxProcessorTest#testRunDefaultActionAndMails
   
   ## Does this pull request potentially affect one of the following parts:
   
     - Dependencies (does it add or upgrade a dependency): __no__
     - The public API, i.e., is any changed class annotated with `@Public(Evolving)`: __no__
     - The serializers: __no__
     - The runtime per-record code paths (performance sensitive): __yes__
     - Anything that affects deployment or recovery: __no__
     - The S3 file system connector: __no__
   
   ## Documentation
   
     - Does this pull request introduce a new feature? __no__
     - If yes, how is the feature documented? __not applicable__
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [flink] pnowojski commented on a diff in pull request #19398: [FLINK-26864][metrics] Fix performance regression from mailbox latency measuement

Posted by GitBox <gi...@apache.org>.
pnowojski commented on code in PR #19398:
URL: https://github.com/apache/flink/pull/19398#discussion_r845916286


##########
flink-streaming-java/src/main/java/org/apache/flink/streaming/runtime/tasks/mailbox/MailboxMetricsController.java:
##########
@@ -0,0 +1,154 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.flink.streaming.runtime.tasks.mailbox;
+
+import org.apache.flink.annotation.Internal;
+import org.apache.flink.annotation.VisibleForTesting;
+import org.apache.flink.api.common.operators.MailboxExecutor;
+import org.apache.flink.metrics.Counter;
+import org.apache.flink.metrics.Histogram;
+import org.apache.flink.streaming.runtime.tasks.TimerService;
+import org.apache.flink.util.clock.SystemClock;
+
+import javax.annotation.Nullable;
+
+/**
+ * Mailbox metrics controller class. The use of mailbox metrics, in particular scheduling latency
+ * measurements that require a {@link TimerService}, induce (cyclic) dependencies between {@link
+ * MailboxProcessor} and {@link org.apache.flink.streaming.runtime.tasks.StreamTask}. An instance of
+ * this class contains and gives control over these dependencies.
+ */
+@Internal
+public class MailboxMetricsController {
+    /** Default timer interval in milliseconds for triggering mailbox latency measurement. */
+    public final int defaultLatencyMeasurementInterval = 1000;
+
+    private final Histogram latencyHistogram;
+    private final Counter mailCounter;
+
+    @Nullable private TimerService timerService;
+    @Nullable private MailboxExecutor mailboxExecutor;
+    private int measurementInterval = defaultLatencyMeasurementInterval;
+    private boolean started = false;
+
+    /**
+     * Creates instance of {@link MailboxMetricsController} with references to metrics provided as
+     * parameters.
+     *
+     * @param latencyHistogram Histogram of mailbox latency measurements.
+     * @param mailCounter Counter for number of mails processed.
+     */
+    public MailboxMetricsController(Histogram latencyHistogram, Counter mailCounter) {
+        this.timerService = null;
+        this.mailboxExecutor = null;
+        this.latencyHistogram = latencyHistogram;
+        this.mailCounter = mailCounter;
+    }
+
+    /**
+     * Sets up latency measurement with required {@link TimerService} and {@link MailboxExecutor}.
+     *
+     * <p>Note: For each instance, latency measurement can be set up only once.
+     *
+     * @param timerService {@link TimerService} used for latency measurement.
+     * @param mailboxExecutor {@link MailboxExecutor} used for latency measurement.
+     */
+    public void setupLatencyMeasurement(
+            TimerService timerService, MailboxExecutor mailboxExecutor) {
+        if (isLatencyMeasurementSetup()) {
+            throw new IllegalStateException(
+                    "latency measurement has already been setup and cannot be setup twice");
+        }

Review Comment:
   Yeah, that would be fine :) (note also the other places)



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [flink] pnowojski commented on a diff in pull request #19398: [FLINK-26864][metrics] Fix performance regression from mailbox latency measuement

Posted by GitBox <gi...@apache.org>.
pnowojski commented on code in PR #19398:
URL: https://github.com/apache/flink/pull/19398#discussion_r845800146


##########
flink-streaming-java/src/main/java/org/apache/flink/streaming/runtime/tasks/mailbox/MailboxMetricsController.java:
##########
@@ -0,0 +1,154 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.flink.streaming.runtime.tasks.mailbox;
+
+import org.apache.flink.annotation.Internal;
+import org.apache.flink.annotation.VisibleForTesting;
+import org.apache.flink.api.common.operators.MailboxExecutor;
+import org.apache.flink.metrics.Counter;
+import org.apache.flink.metrics.Histogram;
+import org.apache.flink.streaming.runtime.tasks.TimerService;
+import org.apache.flink.util.clock.SystemClock;
+
+import javax.annotation.Nullable;
+
+/**
+ * Mailbox metrics controller class. The use of mailbox metrics, in particular scheduling latency
+ * measurements that require a {@link TimerService}, induce (cyclic) dependencies between {@link
+ * MailboxProcessor} and {@link org.apache.flink.streaming.runtime.tasks.StreamTask}. An instance of
+ * this class contains and gives control over these dependencies.
+ */
+@Internal
+public class MailboxMetricsController {
+    /** Default timer interval in milliseconds for triggering mailbox latency measurement. */
+    public final int defaultLatencyMeasurementInterval = 1000;
+
+    private final Histogram latencyHistogram;
+    private final Counter mailCounter;
+
+    @Nullable private TimerService timerService;
+    @Nullable private MailboxExecutor mailboxExecutor;
+    private int measurementInterval = defaultLatencyMeasurementInterval;
+    private boolean started = false;
+
+    /**
+     * Creates instance of {@link MailboxMetricsController} with references to metrics provided as
+     * parameters.
+     *
+     * @param latencyHistogram Histogram of mailbox latency measurements.
+     * @param mailCounter Counter for number of mails processed.
+     */
+    public MailboxMetricsController(Histogram latencyHistogram, Counter mailCounter) {
+        this.timerService = null;
+        this.mailboxExecutor = null;
+        this.latencyHistogram = latencyHistogram;
+        this.mailCounter = mailCounter;
+    }
+
+    /**
+     * Sets up latency measurement with required {@link TimerService} and {@link MailboxExecutor}.
+     *
+     * <p>Note: For each instance, latency measurement can be set up only once.
+     *
+     * @param timerService {@link TimerService} used for latency measurement.
+     * @param mailboxExecutor {@link MailboxExecutor} used for latency measurement.
+     */
+    public void setupLatencyMeasurement(
+            TimerService timerService, MailboxExecutor mailboxExecutor) {
+        if (isLatencyMeasurementSetup()) {
+            throw new IllegalStateException(
+                    "latency measurement has already been setup and cannot be setup twice");
+        }

Review Comment:
   nit:
   ```
   checkState(condition, message);
   ```
   is doing the same thing (and is more or less our convention)



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [flink] smattheis commented on pull request #19398: [FLINK-26864][metrics] Fix performance regression from mailbox latency measuement

Posted by GitBox <gi...@apache.org>.
smattheis commented on PR #19398:
URL: https://github.com/apache/flink/pull/19398#issuecomment-1094008704

   @pnowojski There was a merge conflict. Therefore, I pushed an update and reran the ci check which succeeded.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [flink] smattheis commented on pull request #19398: [FLINK-26864][metrics] Fix performance regression from mailbox latency measuement

Posted by GitBox <gi...@apache.org>.
smattheis commented on PR #19398:
URL: https://github.com/apache/flink/pull/19398#issuecomment-1093891085

   @flinkbot run azure


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [flink] smattheis commented on a diff in pull request #19398: [FLINK-26864][metrics] Fix performance regression from mailbox latency measuement

Posted by GitBox <gi...@apache.org>.
smattheis commented on code in PR #19398:
URL: https://github.com/apache/flink/pull/19398#discussion_r845908392


##########
flink-streaming-java/src/main/java/org/apache/flink/streaming/runtime/tasks/mailbox/MailboxMetricsController.java:
##########
@@ -0,0 +1,154 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.flink.streaming.runtime.tasks.mailbox;
+
+import org.apache.flink.annotation.Internal;
+import org.apache.flink.annotation.VisibleForTesting;
+import org.apache.flink.api.common.operators.MailboxExecutor;
+import org.apache.flink.metrics.Counter;
+import org.apache.flink.metrics.Histogram;
+import org.apache.flink.streaming.runtime.tasks.TimerService;
+import org.apache.flink.util.clock.SystemClock;
+
+import javax.annotation.Nullable;
+
+/**
+ * Mailbox metrics controller class. The use of mailbox metrics, in particular scheduling latency
+ * measurements that require a {@link TimerService}, induce (cyclic) dependencies between {@link
+ * MailboxProcessor} and {@link org.apache.flink.streaming.runtime.tasks.StreamTask}. An instance of
+ * this class contains and gives control over these dependencies.
+ */
+@Internal
+public class MailboxMetricsController {
+    /** Default timer interval in milliseconds for triggering mailbox latency measurement. */
+    public final int defaultLatencyMeasurementInterval = 1000;
+
+    private final Histogram latencyHistogram;
+    private final Counter mailCounter;
+
+    @Nullable private TimerService timerService;
+    @Nullable private MailboxExecutor mailboxExecutor;
+    private int measurementInterval = defaultLatencyMeasurementInterval;
+    private boolean started = false;
+
+    /**
+     * Creates instance of {@link MailboxMetricsController} with references to metrics provided as
+     * parameters.
+     *
+     * @param latencyHistogram Histogram of mailbox latency measurements.
+     * @param mailCounter Counter for number of mails processed.
+     */
+    public MailboxMetricsController(Histogram latencyHistogram, Counter mailCounter) {
+        this.timerService = null;
+        this.mailboxExecutor = null;
+        this.latencyHistogram = latencyHistogram;
+        this.mailCounter = mailCounter;
+    }
+
+    /**
+     * Sets up latency measurement with required {@link TimerService} and {@link MailboxExecutor}.
+     *
+     * <p>Note: For each instance, latency measurement can be set up only once.
+     *
+     * @param timerService {@link TimerService} used for latency measurement.
+     * @param mailboxExecutor {@link MailboxExecutor} used for latency measurement.
+     */
+    public void setupLatencyMeasurement(
+            TimerService timerService, MailboxExecutor mailboxExecutor) {
+        if (isLatencyMeasurementSetup()) {
+            throw new IllegalStateException(
+                    "latency measurement has already been setup and cannot be setup twice");
+        }

Review Comment:
   Is it okay like this:
   ``` java
       import static org.apache.flink.util.Preconditions.checkState;
   ...
       public void startLatencyMeasurement() {
           checkState(isLatencyMeasurementStarted(), "latency measurement has already been started");
           checkState(
                   !isLatencyMeasurementSetup(),
                   "timer service and mailbox executor must be setup for latency measurement");
           scheduleLatencyMeasurement();
           started = true;
       }
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [flink] pnowojski merged pull request #19398: [FLINK-26864][metrics] Fix performance regression from mailbox latency measuement

Posted by GitBox <gi...@apache.org>.
pnowojski merged PR #19398:
URL: https://github.com/apache/flink/pull/19398


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [flink] flinkbot commented on pull request #19398: [FLINK-26864] Fix performance regression from mailbox latency measuement

Posted by GitBox <gi...@apache.org>.
flinkbot commented on PR #19398:
URL: https://github.com/apache/flink/pull/19398#issuecomment-1092130998

   <!--
   Meta data
   {
     "version" : 1,
     "metaDataEntries" : [ {
       "hash" : "39433bafd06d05e400388ca6ef2db98491bbaefa",
       "status" : "UNKNOWN",
       "url" : "TBD",
       "triggerID" : "39433bafd06d05e400388ca6ef2db98491bbaefa",
       "triggerType" : "PUSH"
     } ]
   }-->
   ## CI report:
   
   * 39433bafd06d05e400388ca6ef2db98491bbaefa UNKNOWN
   
   <details>
   <summary>Bot commands</summary>
     The @flinkbot bot supports the following commands:
   
    - `@flinkbot run azure` re-run the last Azure build
   </details>


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org