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 2021/07/21 14:08:59 UTC

[GitHub] [flink] akalash opened a new pull request #16556: [FLINK-23452][runtime] Added the throughput meter for measurement of …

akalash opened a new pull request #16556:
URL: https://github.com/apache/flink/pull/16556


   …the subtask level throughput which subtract the idle time from the calculation
   
   <!--
   *Thank you very much for contributing to Apache Flink - we are happy that you want to help us improve Flink. To help the community review your contribution in the best possible way, please go through the checklist below, which will get the contribution into a shape in which it can be best reviewed.*
   
   *Please understand that we do not do this to make contributions to Flink a hassle. In order to uphold a high standard of quality for code contributions, while at the same time managing a large number of contributions, we need contributors to prepare the contributions well, and give reviewers enough contextual information for the review. Please also understand that contributions that do not follow this guide will take longer to review and thus typically be picked up with lower priority by the community.*
   
   ## Contribution Checklist
   
     - Make sure that the pull request corresponds to a [JIRA issue](https://issues.apache.org/jira/projects/FLINK/issues). Exceptions are made for typos in JavaDoc or documentation files, which need no JIRA issue.
     
     - Name the pull request in the form "[FLINK-XXXX] [component] Title of the pull request", where *FLINK-XXXX* should be replaced by the actual issue number. Skip *component* if you are unsure about which is the best component.
     Typo fixes that have no associated JIRA issue should be named following this pattern: `[hotfix] [docs] Fix typo in event time introduction` or `[hotfix] [javadocs] Expand JavaDoc for PuncuatedWatermarkGenerator`.
   
     - Fill out the template below to describe the changes contributed by the pull request. That will give reviewers the context they need to do the review.
     
     - Make sure that the change passes the automated tests, i.e., `mvn clean verify` passes. You can set up Azure Pipelines CI to do that following [this guide](https://cwiki.apache.org/confluence/display/FLINK/Azure+Pipelines#AzurePipelines-Tutorial:SettingupAzurePipelinesforaforkoftheFlinkrepository).
   
     - Each pull request should address only one issue, not mix up code from multiple issues.
     
     - Each commit in the pull request has a meaningful commit message (including the JIRA id)
   
     - Once all items of the checklist are addressed, remove the above text and this checklist, leaving only the filled out template below.
   
   
   **(The sections below can be removed for hotfixes of typos)**
   -->
   
   ## What is the purpose of the change
   
   *This PR implements the calculation of the subtask level throughput which doesn't take into account idle time during the calculation*
   
   
   ## Brief change log
   
     - *Implementaion of the EMA algorithm for calculation of throughput*
     - *The periodic calculation of  throughput via mailbox*
     - *Wrapper for the idle time measurement*
   
   
   ## Verifying this change
   
   This change added tests and can be verified as follows:
   
     - *Unit tests for checking correctness of the throughput calculation*
   
   ## Does this pull request potentially affect one of the following parts:
   
     - Dependencies (does it add or upgrade a dependency): (yes / **no**)
     - The public API, i.e., is any changed class annotated with `@Public(Evolving)`: (**yes** / no)
     - The serializers: (yes / **no** / don't know)
     - The runtime per-record code paths (performance sensitive): (**yes** / no / don't know)
     - Anything that affects deployment or recovery: JobManager (and its components), Checkpointing, Kubernetes/Yarn, ZooKeeper: (yes / **no** / don't know)
     - The S3 file system connector: (yes / **no** / don't know)
   
   ## Documentation
   
     - Does this pull request introduce a new feature? (**yes** / no)
     - If yes, how is the feature documented? (not applicable / docs / JavaDocs / not documented)
   


-- 
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 #16556: [FLINK-23452][runtime] Added the throughput meter for measurement of …

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


   <!--
   Meta data
   {
     "version" : 1,
     "metaDataEntries" : [ {
       "hash" : "a7ef9c2b42f44c4ab4c1ba034a7c7f90640eef58",
       "status" : "UNKNOWN",
       "url" : "TBD",
       "triggerID" : "a7ef9c2b42f44c4ab4c1ba034a7c7f90640eef58",
       "triggerType" : "PUSH"
     } ]
   }-->
   ## CI report:
   
   * a7ef9c2b42f44c4ab4c1ba034a7c7f90640eef58 UNKNOWN
   
   <details>
   <summary>Bot commands</summary>
     The @flinkbot bot supports the following commands:
   
    - `@flinkbot run travis` re-run the last Travis build
    - `@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



[GitHub] [flink] flinkbot edited a comment on pull request #16556: [FLINK-23452][runtime] Added the throughput meter for measurement of …

Posted by GitBox <gi...@apache.org>.
flinkbot edited a comment on pull request #16556:
URL: https://github.com/apache/flink/pull/16556#issuecomment-884238774


   <!--
   Meta data
   {
     "version" : 1,
     "metaDataEntries" : [ {
       "hash" : "a7ef9c2b42f44c4ab4c1ba034a7c7f90640eef58",
       "status" : "DELETED",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=20794",
       "triggerID" : "a7ef9c2b42f44c4ab4c1ba034a7c7f90640eef58",
       "triggerType" : "PUSH"
     }, {
       "hash" : "814871decf09be535af651215adb650f678b70e1",
       "status" : "SUCCESS",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=20802",
       "triggerID" : "814871decf09be535af651215adb650f678b70e1",
       "triggerType" : "PUSH"
     } ]
   }-->
   ## CI report:
   
   * 814871decf09be535af651215adb650f678b70e1 Azure: [SUCCESS](https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=20802) 
   
   <details>
   <summary>Bot commands</summary>
     The @flinkbot bot supports the following commands:
   
    - `@flinkbot run travis` re-run the last Travis build
    - `@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



[GitHub] [flink] flinkbot edited a comment on pull request #16556: [FLINK-23452][runtime] Added the throughput meter for measurement of …

Posted by GitBox <gi...@apache.org>.
flinkbot edited a comment on pull request #16556:
URL: https://github.com/apache/flink/pull/16556#issuecomment-884238774


   <!--
   Meta data
   {
     "version" : 1,
     "metaDataEntries" : [ {
       "hash" : "a7ef9c2b42f44c4ab4c1ba034a7c7f90640eef58",
       "status" : "DELETED",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=20794",
       "triggerID" : "a7ef9c2b42f44c4ab4c1ba034a7c7f90640eef58",
       "triggerType" : "PUSH"
     }, {
       "hash" : "814871decf09be535af651215adb650f678b70e1",
       "status" : "DELETED",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=20802",
       "triggerID" : "814871decf09be535af651215adb650f678b70e1",
       "triggerType" : "PUSH"
     }, {
       "hash" : "8c76db43092d6df17f52862a0d098dfb3a4a5ab3",
       "status" : "SUCCESS",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=20833",
       "triggerID" : "8c76db43092d6df17f52862a0d098dfb3a4a5ab3",
       "triggerType" : "PUSH"
     }, {
       "hash" : "4033dd607f8ea9d375c48e3054f070221f897674",
       "status" : "UNKNOWN",
       "url" : "TBD",
       "triggerID" : "4033dd607f8ea9d375c48e3054f070221f897674",
       "triggerType" : "PUSH"
     } ]
   }-->
   ## CI report:
   
   * 8c76db43092d6df17f52862a0d098dfb3a4a5ab3 Azure: [SUCCESS](https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=20833) 
   * 4033dd607f8ea9d375c48e3054f070221f897674 UNKNOWN
   
   <details>
   <summary>Bot commands</summary>
     The @flinkbot bot supports the following commands:
   
    - `@flinkbot run travis` re-run the last Travis build
    - `@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



[GitHub] [flink] akalash commented on a change in pull request #16556: [FLINK-23452][runtime] Added the throughput meter for measurement of …

Posted by GitBox <gi...@apache.org>.
akalash commented on a change in pull request #16556:
URL: https://github.com/apache/flink/pull/16556#discussion_r677591594



##########
File path: flink-runtime/src/main/java/org/apache/flink/runtime/throughput/ThroughputMeter.java
##########
@@ -0,0 +1,82 @@
+/*
+ * 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.runtime.throughput;
+
+import org.apache.flink.util.clock.Clock;
+
+/** Class for measuring the throughput based on incoming data size and busy + backpressure time. */
+public class ThroughputMeter {
+    private static final long NOT_TRACKED = -1;
+    private final Clock clock;
+    private final AverageThroughputCalculator averageThroughputCalculator;
+
+    /** Accumulated data size for current period. */
+    private long currentSize;
+
+    /** Total busy time for current period(the total time minus idle time). */
+    private long currentTime;
+
+    /** The start of busy time. */
+    private long startTime;
+
+    /** The last throughput . */
+    private long effectiveThroughput;
+
+    public ThroughputMeter(Clock clock, AverageThroughputCalculator averageThroughputCalculator) {
+        this.clock = clock;
+        this.averageThroughputCalculator = averageThroughputCalculator;
+    }
+
+    /** @param size The size of received data. */
+    public void incomingDataSize(long size) {
+        currentSize += size;
+    }
+
+    /** Mark when idle time is started. */
+    public void idleStart() {
+        if (startTime != NOT_TRACKED) {
+            currentTime += clock.relativeTimeMillis() - startTime;
+        }
+        startTime = NOT_TRACKED;
+    }
+
+    /** Mark when idle time is ended. */
+    public void idleEnd() {
+        startTime = clock.relativeTimeMillis();
+    }
+
+    /**
+     * Calculate throughput based on the collected data for the last period.
+     *
+     * @return {@code -1} if it is impossible to calculate throughput and actual value otherwise.
+     */
+    public long calculateThroughput() {

Review comment:
       It is exactly the target. `currentTime == 0` => `throughput == lastThroughput == 0`(according to current implementation) => `bufferSize == minConfiguredSize` or it can be left unchangable(I need to think). But if we initialise it in constructor it indeed will lead to the low throughput because there is some time will pass beetwen constructor and actual handling the data.(worth to mention about the recovery which happens beetween these two events).




-- 
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 edited a comment on pull request #16556: [FLINK-23452][runtime] Added the throughput meter for measurement of …

Posted by GitBox <gi...@apache.org>.
flinkbot edited a comment on pull request #16556:
URL: https://github.com/apache/flink/pull/16556#issuecomment-884238774


   <!--
   Meta data
   {
     "version" : 1,
     "metaDataEntries" : [ {
       "hash" : "a7ef9c2b42f44c4ab4c1ba034a7c7f90640eef58",
       "status" : "PENDING",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=20794",
       "triggerID" : "a7ef9c2b42f44c4ab4c1ba034a7c7f90640eef58",
       "triggerType" : "PUSH"
     } ]
   }-->
   ## CI report:
   
   * a7ef9c2b42f44c4ab4c1ba034a7c7f90640eef58 Azure: [PENDING](https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=20794) 
   
   <details>
   <summary>Bot commands</summary>
     The @flinkbot bot supports the following commands:
   
    - `@flinkbot run travis` re-run the last Travis build
    - `@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



[GitHub] [flink] pnowojski commented on a change in pull request #16556: [FLINK-23452][runtime] Added the throughput meter for measurement of …

Posted by GitBox <gi...@apache.org>.
pnowojski commented on a change in pull request #16556:
URL: https://github.com/apache/flink/pull/16556#discussion_r678304043



##########
File path: flink-streaming-java/src/test/java/org/apache/flink/streaming/runtime/tasks/StreamTaskTest.java
##########
@@ -1727,6 +1731,99 @@ protected void cancelTask() {
         assertTrue(OpenFailingOperator.wasClosed);
     }
 
+    @Test
+    public void testMailboxNotifyThroughputMeterAboutIdleTime() throws Exception {
+        final long sleepTimeOutsideMail = 42;
+        final long sleepTimeInsideMail = 44;
+        int incomingDataSize = 10_000;
+
+        @Nullable WaitingThread waitingThread = null;
+        try (final MockEnvironment environment = setupEnvironment(true, true)) {
+            final UnAvailableTestInputProcessor inputProcessor =
+                    new UnAvailableTestInputProcessor();
+            final StreamTask task =
+                    new MockStreamTaskBuilder(environment)
+                            .setStreamInputProcessor(inputProcessor)
+                            .build();
+            TaskIOMetricGroup ioMetricGroup =
+                    task.getEnvironment().getMetricGroup().getIOMetricGroup();
+            ThroughputCalculator throughputCalculator = environment.getThroughputMeter();
+
+            final MailboxExecutor executor = task.mailboxProcessor.getMainMailboxExecutor();
+            final RunnableWithException completeFutureTask =
+                    () ->
+                            inputProcessor
+                                    .availabilityProvider
+                                    .getUnavailableToResetAvailable()
+                                    .complete(null);
+
+            waitingThread =
+                    new WaitingThread(
+                            executor,
+                            completeFutureTask,
+                            sleepTimeInsideMail,
+                            sleepTimeOutsideMail,
+                            ioMetricGroup.getIdleTimeMsPerSecond());
+            // Make sure WaitingThread is started after Task starts processing.
+            executor.submit(
+                    waitingThread::start,
+                    "Start WaitingThread after Task starts processing input.");
+
+            long startTs = System.currentTimeMillis();
+            throughputCalculator.calculateThroughput();
+            throughputCalculator.incomingDataSize(incomingDataSize);
+            task.invoke();
+            long resultThroughput = throughputCalculator.calculateThroughput();
+            long totalDuration = System.currentTimeMillis() - startTs;
+
+            assertThat(
+                    resultThroughput,
+                    greaterThanOrEqualTo(
+                            incomingDataSize * 1000 / (totalDuration - sleepTimeOutsideMail)));
+        } finally {
+            if (waitingThread != null) {
+                waitingThread.join();
+            }
+        }
+    }
+
+    @Test
+    public void testThroughputSchedulerStartsOnInvoke() throws Exception {
+        // given: Throughput meter which finishes the task when calculateThroughput was called.
+        UnAvailableTestInputProcessor inputProcessor = new UnAvailableTestInputProcessor();
+        AtomicInteger desirableNumberOfCalculation = new AtomicInteger(2);
+        try (MockEnvironment mockEnvironment =
+                new MockEnvironmentBuilder()
+                        .setTaskConfiguration(
+                                new Configuration().set(IN_FLIGHT_DATA_ADJUSTMENT_PERIOD, 1))
+                        .setThroughputMeter(
+                                new ThroughputCalculator(SystemClock.getInstance(), 10) {
+                                    @Override
+                                    public long calculateThroughput() {
+                                        if (desirableNumberOfCalculation.decrementAndGet() == 0) {
+                                            inputProcessor
+                                                    .availabilityProvider
+                                                    .getUnavailableToResetAvailable()
+                                                    .complete(null);
+                                        }
+                                        return super.calculateThroughput();
+                                    }
+                                })
+                        .build()) {
+
+            StreamTask task =
+                    new MockStreamTaskBuilder(mockEnvironment)
+                            .setStreamInputProcessor(inputProcessor)
+                            .build();
+
+            // when: Starting the task.
+            task.invoke();
+
+            // then: The task successfully finishes because throughput calculation was called from
+            // scheduler which leads to the finish of the task
+        }
+    }

Review comment:
       Thanks for the explanation. Makes sense. Can you maybe copy paste the above explanation in the java doc of this test?




-- 
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 #16556: [FLINK-23452][runtime] Added the throughput meter for measurement of …

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


   


-- 
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 edited a comment on pull request #16556: [FLINK-23452][runtime] Added the throughput meter for measurement of …

Posted by GitBox <gi...@apache.org>.
flinkbot edited a comment on pull request #16556:
URL: https://github.com/apache/flink/pull/16556#issuecomment-884238774


   <!--
   Meta data
   {
     "version" : 1,
     "metaDataEntries" : [ {
       "hash" : "a7ef9c2b42f44c4ab4c1ba034a7c7f90640eef58",
       "status" : "DELETED",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=20794",
       "triggerID" : "a7ef9c2b42f44c4ab4c1ba034a7c7f90640eef58",
       "triggerType" : "PUSH"
     }, {
       "hash" : "814871decf09be535af651215adb650f678b70e1",
       "status" : "DELETED",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=20802",
       "triggerID" : "814871decf09be535af651215adb650f678b70e1",
       "triggerType" : "PUSH"
     }, {
       "hash" : "8c76db43092d6df17f52862a0d098dfb3a4a5ab3",
       "status" : "DELETED",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=20833",
       "triggerID" : "8c76db43092d6df17f52862a0d098dfb3a4a5ab3",
       "triggerType" : "PUSH"
     }, {
       "hash" : "4033dd607f8ea9d375c48e3054f070221f897674",
       "status" : "FAILURE",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=21046",
       "triggerID" : "4033dd607f8ea9d375c48e3054f070221f897674",
       "triggerType" : "PUSH"
     }, {
       "hash" : "0e57037543be0c39d28407180f15715cd0d30d7d",
       "status" : "PENDING",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=21118",
       "triggerID" : "0e57037543be0c39d28407180f15715cd0d30d7d",
       "triggerType" : "PUSH"
     } ]
   }-->
   ## CI report:
   
   * 4033dd607f8ea9d375c48e3054f070221f897674 Azure: [FAILURE](https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=21046) 
   * 0e57037543be0c39d28407180f15715cd0d30d7d Azure: [PENDING](https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=21118) 
   
   <details>
   <summary>Bot commands</summary>
     The @flinkbot bot supports the following commands:
   
    - `@flinkbot run travis` re-run the last Travis build
    - `@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



[GitHub] [flink] flinkbot edited a comment on pull request #16556: [FLINK-23452][runtime] Added the throughput meter for measurement of …

Posted by GitBox <gi...@apache.org>.
flinkbot edited a comment on pull request #16556:
URL: https://github.com/apache/flink/pull/16556#issuecomment-884238774


   <!--
   Meta data
   {
     "version" : 1,
     "metaDataEntries" : [ {
       "hash" : "a7ef9c2b42f44c4ab4c1ba034a7c7f90640eef58",
       "status" : "FAILURE",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=20794",
       "triggerID" : "a7ef9c2b42f44c4ab4c1ba034a7c7f90640eef58",
       "triggerType" : "PUSH"
     }, {
       "hash" : "814871decf09be535af651215adb650f678b70e1",
       "status" : "UNKNOWN",
       "url" : "TBD",
       "triggerID" : "814871decf09be535af651215adb650f678b70e1",
       "triggerType" : "PUSH"
     } ]
   }-->
   ## CI report:
   
   * a7ef9c2b42f44c4ab4c1ba034a7c7f90640eef58 Azure: [FAILURE](https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=20794) 
   * 814871decf09be535af651215adb650f678b70e1 UNKNOWN
   
   <details>
   <summary>Bot commands</summary>
     The @flinkbot bot supports the following commands:
   
    - `@flinkbot run travis` re-run the last Travis build
    - `@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



[GitHub] [flink] flinkbot edited a comment on pull request #16556: [FLINK-23452][runtime] Added the throughput meter for measurement of …

Posted by GitBox <gi...@apache.org>.
flinkbot edited a comment on pull request #16556:
URL: https://github.com/apache/flink/pull/16556#issuecomment-884238774


   <!--
   Meta data
   {
     "version" : 1,
     "metaDataEntries" : [ {
       "hash" : "a7ef9c2b42f44c4ab4c1ba034a7c7f90640eef58",
       "status" : "DELETED",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=20794",
       "triggerID" : "a7ef9c2b42f44c4ab4c1ba034a7c7f90640eef58",
       "triggerType" : "PUSH"
     }, {
       "hash" : "814871decf09be535af651215adb650f678b70e1",
       "status" : "SUCCESS",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=20802",
       "triggerID" : "814871decf09be535af651215adb650f678b70e1",
       "triggerType" : "PUSH"
     }, {
       "hash" : "8c76db43092d6df17f52862a0d098dfb3a4a5ab3",
       "status" : "UNKNOWN",
       "url" : "TBD",
       "triggerID" : "8c76db43092d6df17f52862a0d098dfb3a4a5ab3",
       "triggerType" : "PUSH"
     } ]
   }-->
   ## CI report:
   
   * 814871decf09be535af651215adb650f678b70e1 Azure: [SUCCESS](https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=20802) 
   * 8c76db43092d6df17f52862a0d098dfb3a4a5ab3 UNKNOWN
   
   <details>
   <summary>Bot commands</summary>
     The @flinkbot bot supports the following commands:
   
    - `@flinkbot run travis` re-run the last Travis build
    - `@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



[GitHub] [flink] pnowojski commented on a change in pull request #16556: [FLINK-23452][runtime] Added the throughput meter for measurement of …

Posted by GitBox <gi...@apache.org>.
pnowojski commented on a change in pull request #16556:
URL: https://github.com/apache/flink/pull/16556#discussion_r678054692



##########
File path: flink-streaming-java/src/main/java/org/apache/flink/streaming/runtime/tasks/StreamTask.java
##########
@@ -665,6 +674,19 @@ private void executeInvoke() throws Exception {
         afterInvoke();
     }
 
+    private void throughputCalculationSetup() {
+        systemTimerService.registerTimer(
+                systemTimerService.getCurrentProcessingTime()

Review comment:
       `systemTimerService.scheduleAtFixedRate()`?




-- 
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 change in pull request #16556: [FLINK-23452][runtime] Added the throughput meter for measurement of …

Posted by GitBox <gi...@apache.org>.
pnowojski commented on a change in pull request #16556:
URL: https://github.com/apache/flink/pull/16556#discussion_r676542558



##########
File path: flink-libraries/flink-state-processing-api/src/main/java/org/apache/flink/state/api/runtime/SavepointEnvironment.java
##########
@@ -285,6 +286,11 @@ public TaskEventDispatcher getTaskEventDispatcher() {
         throw new UnsupportedOperationException(ERROR_MSG);
     }
 
+    @Override
+    public ThroughputMeter getThroughputMeter() {
+        return null;

Review comment:
       `null`? `throw new UnsupportedOperationException()`?

##########
File path: flink-runtime/src/main/java/org/apache/flink/runtime/throughput/EMAThroughputCalculator.java
##########
@@ -0,0 +1,53 @@
+/*
+ * 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.runtime.throughput;
+
+import static org.apache.flink.util.Preconditions.checkArgument;
+
+/** Implementation of 'Exponential moving average' algorithm. */
+public class EMAThroughputCalculator implements AverageThroughputCalculator {
+    private SMAThroughputCalculator smaThroughputCalculator;
+    private long currentThroughput;
+
+    /** EMA algorithm specific constant which responsible for speed of reaction. */
+    private final double alpha;
+
+    public EMAThroughputCalculator(int numberOfPreviousValues) {
+        smaThroughputCalculator = new SMAThroughputCalculator(numberOfPreviousValues);
+        alpha = 2.0 / (numberOfPreviousValues + 1);
+    }
+
+    @Override
+    public long calculateThroughput(long dataSize, long time) {
+        checkArgument(dataSize >= 0, "Size of data should be non negative");
+        checkArgument(time >= 0, "Time should be non negative");
+
+        if (time == 0) {
+            return currentThroughput;
+        }
+
+        if (smaThroughputCalculator.isWarmedUp()) {

Review comment:
       Why do we need `SMAThroughputCalculator`? Why are we sampling many throughputs to calculate `EMA`? Is it only in order to handle the "warm up" period? If so, why don't you just initialise first EMA's value with the first sample? 

##########
File path: flink-runtime/src/main/java/org/apache/flink/runtime/operators/util/TaskConfig.java
##########
@@ -238,6 +240,19 @@
 
     private static final String SOLUTION_SET_OBJECTS = "itertive.ss.obj";
 
+    public static final ConfigOption<Integer> THROUGHPUT_CALCULATION_PERIOD =
+            ConfigOptions.key("io.throughput.calculationPeriod")

Review comment:
       `calculation-period` instead of camel case (https://ci.apache.org/projects/flink/flink-docs-release-1.13/docs/deployment/config/)

##########
File path: flink-runtime/src/main/java/org/apache/flink/runtime/throughput/ThroughputMeter.java
##########
@@ -0,0 +1,82 @@
+/*
+ * 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.runtime.throughput;
+
+import org.apache.flink.util.clock.Clock;
+
+/** Class for measuring the throughput based on incoming data size and busy + backpressure time. */

Review comment:
       I wouldn't mention backpressure/idle/busy here, it's I think not necessary on this level of abstraction. Instead of `idleStart()` or `idleEnd()` you could just have `pause/startMeasurement()` and that would make this class more generic.

##########
File path: flink-streaming-java/src/main/java/org/apache/flink/streaming/api/graph/StreamConfig.java
##########
@@ -427,6 +428,14 @@ public void setInPhysicalEdges(List<StreamEdge> inEdges) {
         }
     }
 
+    public void setThroughputCalculationPeriod(int throughputCalculationPeriod) {
+        config.set(THROUGHPUT_CALCULATION_PERIOD, throughputCalculationPeriod);
+    }
+
+    public int getThroughputCalculationPeriod() {
+        return config.get(THROUGHPUT_CALCULATION_PERIOD);
+    }

Review comment:
       Why do we need those changes?

##########
File path: flink-streaming-java/src/main/java/org/apache/flink/streaming/runtime/tasks/mailbox/PeriodTimer.java
##########
@@ -0,0 +1,26 @@
+/*
+ * 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;
+
+/** Interface for the measurement of the period of time. */
+public interface PeriodTimer {
+    void markStart();
+
+    void markEnd();
+}

Review comment:
       Extracting/introducing this could also have been another pure "refactor" commit

##########
File path: flink-runtime/src/main/java/org/apache/flink/runtime/throughput/ThroughputMeter.java
##########
@@ -0,0 +1,82 @@
+/*
+ * 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.runtime.throughput;
+
+import org.apache.flink.util.clock.Clock;
+
+/** Class for measuring the throughput based on incoming data size and busy + backpressure time. */
+public class ThroughputMeter {
+    private static final long NOT_TRACKED = -1;
+    private final Clock clock;
+    private final AverageThroughputCalculator averageThroughputCalculator;
+
+    /** Accumulated data size for current period. */
+    private long currentSize;
+
+    /** Total busy time for current period(the total time minus idle time). */
+    private long currentTime;
+
+    /** The start of busy time. */
+    private long startTime;
+
+    /** The last throughput . */
+    private long effectiveThroughput;
+
+    public ThroughputMeter(Clock clock, AverageThroughputCalculator averageThroughputCalculator) {
+        this.clock = clock;
+        this.averageThroughputCalculator = averageThroughputCalculator;
+    }
+
+    /** @param size The size of received data. */
+    public void incomingDataSize(long size) {
+        currentSize += size;
+    }
+
+    /** Mark when idle time is started. */
+    public void idleStart() {
+        if (startTime != NOT_TRACKED) {
+            currentTime += clock.relativeTimeMillis() - startTime;
+        }
+        startTime = NOT_TRACKED;
+    }
+
+    /** Mark when idle time is ended. */
+    public void idleEnd() {
+        startTime = clock.relativeTimeMillis();
+    }
+
+    /**
+     * Calculate throughput based on the collected data for the last period.
+     *
+     * @return {@code -1} if it is impossible to calculate throughput and actual value otherwise.
+     */
+    public long calculateThroughput() {

Review comment:
       First call to this method will/might return very very low throughput, as `startTime == 0`. Initialise `startTime = clock.relativeTimeMillis()` in the constructor?

##########
File path: flink-runtime/src/main/java/org/apache/flink/runtime/throughput/EMAThroughputCalculator.java
##########
@@ -0,0 +1,53 @@
+/*
+ * 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.runtime.throughput;
+
+import static org.apache.flink.util.Preconditions.checkArgument;
+
+/** Implementation of 'Exponential moving average' algorithm. */
+public class EMAThroughputCalculator implements AverageThroughputCalculator {
+    private SMAThroughputCalculator smaThroughputCalculator;

Review comment:
       `final`

##########
File path: flink-runtime/src/main/java/org/apache/flink/runtime/throughput/ThroughputMeter.java
##########
@@ -0,0 +1,82 @@
+/*
+ * 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.runtime.throughput;
+
+import org.apache.flink.util.clock.Clock;
+
+/** Class for measuring the throughput based on incoming data size and busy + backpressure time. */
+public class ThroughputMeter {

Review comment:
        you could have added `ThroughputMeter` (and tests for it?) as independent commit.

##########
File path: flink-runtime/src/main/java/org/apache/flink/runtime/operators/util/TaskConfig.java
##########
@@ -238,6 +240,19 @@
 
     private static final String SOLUTION_SET_OBJECTS = "itertive.ss.obj";
 
+    public static final ConfigOption<Integer> THROUGHPUT_CALCULATION_PERIOD =
+            ConfigOptions.key("io.throughput.calculationPeriod")
+                    .intType()
+                    .defaultValue(500)
+                    .withDescription("The amount of time between calculation the throughput(ms).");
+
+    public static final ConfigOption<Integer> THROUGHPUT_EMA_LAST_VALUES =

Review comment:
       `taskmanager.memory.network.in-flight-data-adjustment.period` +
   `taskmanager.memory.network.in-flight-data-adjustment.samples` +
   move to `TaskManagerOptions`?
   
   Exposing configuration also could have been another commit - it would be easier to pull in someone else to verify that the config names/placement make sense.




-- 
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 edited a comment on pull request #16556: [FLINK-23452][runtime] Added the throughput meter for measurement of …

Posted by GitBox <gi...@apache.org>.
flinkbot edited a comment on pull request #16556:
URL: https://github.com/apache/flink/pull/16556#issuecomment-884238774


   <!--
   Meta data
   {
     "version" : 1,
     "metaDataEntries" : [ {
       "hash" : "a7ef9c2b42f44c4ab4c1ba034a7c7f90640eef58",
       "status" : "FAILURE",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=20794",
       "triggerID" : "a7ef9c2b42f44c4ab4c1ba034a7c7f90640eef58",
       "triggerType" : "PUSH"
     } ]
   }-->
   ## CI report:
   
   * a7ef9c2b42f44c4ab4c1ba034a7c7f90640eef58 Azure: [FAILURE](https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=20794) 
   
   <details>
   <summary>Bot commands</summary>
     The @flinkbot bot supports the following commands:
   
    - `@flinkbot run travis` re-run the last Travis build
    - `@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



[GitHub] [flink] flinkbot edited a comment on pull request #16556: [FLINK-23452][runtime] Added the throughput meter for measurement of …

Posted by GitBox <gi...@apache.org>.
flinkbot edited a comment on pull request #16556:
URL: https://github.com/apache/flink/pull/16556#issuecomment-884238774


   <!--
   Meta data
   {
     "version" : 1,
     "metaDataEntries" : [ {
       "hash" : "a7ef9c2b42f44c4ab4c1ba034a7c7f90640eef58",
       "status" : "DELETED",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=20794",
       "triggerID" : "a7ef9c2b42f44c4ab4c1ba034a7c7f90640eef58",
       "triggerType" : "PUSH"
     }, {
       "hash" : "814871decf09be535af651215adb650f678b70e1",
       "status" : "DELETED",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=20802",
       "triggerID" : "814871decf09be535af651215adb650f678b70e1",
       "triggerType" : "PUSH"
     }, {
       "hash" : "8c76db43092d6df17f52862a0d098dfb3a4a5ab3",
       "status" : "SUCCESS",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=20833",
       "triggerID" : "8c76db43092d6df17f52862a0d098dfb3a4a5ab3",
       "triggerType" : "PUSH"
     }, {
       "hash" : "4033dd607f8ea9d375c48e3054f070221f897674",
       "status" : "PENDING",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=21046",
       "triggerID" : "4033dd607f8ea9d375c48e3054f070221f897674",
       "triggerType" : "PUSH"
     } ]
   }-->
   ## CI report:
   
   * 8c76db43092d6df17f52862a0d098dfb3a4a5ab3 Azure: [SUCCESS](https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=20833) 
   * 4033dd607f8ea9d375c48e3054f070221f897674 Azure: [PENDING](https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=21046) 
   
   <details>
   <summary>Bot commands</summary>
     The @flinkbot bot supports the following commands:
   
    - `@flinkbot run travis` re-run the last Travis build
    - `@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



[GitHub] [flink] flinkbot commented on pull request #16556: [FLINK-23452][runtime] Added the throughput meter for measurement of …

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


   Thanks a lot for your contribution to the Apache Flink project. I'm the @flinkbot. I help the community
   to review your pull request. We will use this comment to track the progress of the review.
   
   
   ## Automated Checks
   Last check on commit a7ef9c2b42f44c4ab4c1ba034a7c7f90640eef58 (Wed Jul 21 14:12:14 UTC 2021)
   
   **Warnings:**
    * No documentation files were touched! Remember to keep the Flink docs up to date!
   
   
   <sub>Mention the bot in a comment to re-run the automated checks.</sub>
   ## Review Progress
   
   * ❓ 1. The [description] looks good.
   * ❓ 2. There is [consensus] that the contribution should go into to Flink.
   * ❓ 3. Needs [attention] from.
   * ❓ 4. The change fits into the overall [architecture].
   * ❓ 5. Overall code [quality] is good.
   
   Please see the [Pull Request Review Guide](https://flink.apache.org/contributing/reviewing-prs.html) for a full explanation of the review process.<details>
    The Bot is tracking the review progress through labels. Labels are applied according to the order of the review items. For consensus, approval by a Flink committer of PMC member is required <summary>Bot commands</summary>
     The @flinkbot bot supports the following commands:
   
    - `@flinkbot approve description` to approve one or more aspects (aspects: `description`, `consensus`, `architecture` and `quality`)
    - `@flinkbot approve all` to approve all aspects
    - `@flinkbot approve-until architecture` to approve everything until `architecture`
    - `@flinkbot attention @username1 [@username2 ..]` to require somebody's attention
    - `@flinkbot disapprove architecture` to remove an approval you gave earlier
   </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



[GitHub] [flink] flinkbot edited a comment on pull request #16556: [FLINK-23452][runtime] Added the throughput meter for measurement of …

Posted by GitBox <gi...@apache.org>.
flinkbot edited a comment on pull request #16556:
URL: https://github.com/apache/flink/pull/16556#issuecomment-884222616


   Thanks a lot for your contribution to the Apache Flink project. I'm the @flinkbot. I help the community
   to review your pull request. We will use this comment to track the progress of the review.
   
   
   ## Automated Checks
   Last check on commit 2adc6fbcf2a79a142e50d6c2dc57b3c6ea002c1e (Thu Sep 23 18:09:35 UTC 2021)
   
   **Warnings:**
    * No documentation files were touched! Remember to keep the Flink docs up to date!
   
   
   <sub>Mention the bot in a comment to re-run the automated checks.</sub>
   ## Review Progress
   
   * ❓ 1. The [description] looks good.
   * ❓ 2. There is [consensus] that the contribution should go into to Flink.
   * ❓ 3. Needs [attention] from.
   * ❓ 4. The change fits into the overall [architecture].
   * ❓ 5. Overall code [quality] is good.
   
   Please see the [Pull Request Review Guide](https://flink.apache.org/contributing/reviewing-prs.html) for a full explanation of the review process.<details>
    The Bot is tracking the review progress through labels. Labels are applied according to the order of the review items. For consensus, approval by a Flink committer of PMC member is required <summary>Bot commands</summary>
     The @flinkbot bot supports the following commands:
   
    - `@flinkbot approve description` to approve one or more aspects (aspects: `description`, `consensus`, `architecture` and `quality`)
    - `@flinkbot approve all` to approve all aspects
    - `@flinkbot approve-until architecture` to approve everything until `architecture`
    - `@flinkbot attention @username1 [@username2 ..]` to require somebody's attention
    - `@flinkbot disapprove architecture` to remove an approval you gave earlier
   </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



[GitHub] [flink] flinkbot edited a comment on pull request #16556: [FLINK-23452][runtime] Added the throughput meter for measurement of …

Posted by GitBox <gi...@apache.org>.
flinkbot edited a comment on pull request #16556:
URL: https://github.com/apache/flink/pull/16556#issuecomment-884238774


   <!--
   Meta data
   {
     "version" : 1,
     "metaDataEntries" : [ {
       "hash" : "a7ef9c2b42f44c4ab4c1ba034a7c7f90640eef58",
       "status" : "DELETED",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=20794",
       "triggerID" : "a7ef9c2b42f44c4ab4c1ba034a7c7f90640eef58",
       "triggerType" : "PUSH"
     }, {
       "hash" : "814871decf09be535af651215adb650f678b70e1",
       "status" : "DELETED",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=20802",
       "triggerID" : "814871decf09be535af651215adb650f678b70e1",
       "triggerType" : "PUSH"
     }, {
       "hash" : "8c76db43092d6df17f52862a0d098dfb3a4a5ab3",
       "status" : "SUCCESS",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=20833",
       "triggerID" : "8c76db43092d6df17f52862a0d098dfb3a4a5ab3",
       "triggerType" : "PUSH"
     } ]
   }-->
   ## CI report:
   
   * 8c76db43092d6df17f52862a0d098dfb3a4a5ab3 Azure: [SUCCESS](https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=20833) 
   
   <details>
   <summary>Bot commands</summary>
     The @flinkbot bot supports the following commands:
   
    - `@flinkbot run travis` re-run the last Travis build
    - `@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



[GitHub] [flink] pnowojski commented on a change in pull request #16556: [FLINK-23452][runtime] Added the throughput meter for measurement of …

Posted by GitBox <gi...@apache.org>.
pnowojski commented on a change in pull request #16556:
URL: https://github.com/apache/flink/pull/16556#discussion_r676542558



##########
File path: flink-libraries/flink-state-processing-api/src/main/java/org/apache/flink/state/api/runtime/SavepointEnvironment.java
##########
@@ -285,6 +286,11 @@ public TaskEventDispatcher getTaskEventDispatcher() {
         throw new UnsupportedOperationException(ERROR_MSG);
     }
 
+    @Override
+    public ThroughputMeter getThroughputMeter() {
+        return null;

Review comment:
       why `null`? maybe `throw new UnsupportedOperationException()`?




-- 
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] akalash commented on a change in pull request #16556: [FLINK-23452][runtime] Added the throughput meter for measurement of …

Posted by GitBox <gi...@apache.org>.
akalash commented on a change in pull request #16556:
URL: https://github.com/apache/flink/pull/16556#discussion_r678126200



##########
File path: flink-streaming-java/src/main/java/org/apache/flink/streaming/runtime/tasks/StreamTask.java
##########
@@ -665,6 +674,19 @@ private void executeInvoke() throws Exception {
         afterInvoke();
     }
 
+    private void throughputCalculationSetup() {
+        systemTimerService.registerTimer(
+                systemTimerService.getCurrentProcessingTime()

Review comment:
       I thought about that but if the delay happens it can lead to the situation when `scheduleAtFixedRate` submit several throughput calculations which don't make sense. It is better to submit the calculation only when the last calculation was finished.




-- 
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] akalash commented on a change in pull request #16556: [FLINK-23452][runtime] Added the throughput meter for measurement of …

Posted by GitBox <gi...@apache.org>.
akalash commented on a change in pull request #16556:
URL: https://github.com/apache/flink/pull/16556#discussion_r674015219



##########
File path: flink-runtime/src/main/java/org/apache/flink/runtime/operators/util/TaskConfig.java
##########
@@ -238,6 +240,19 @@
 
     private static final String SOLUTION_SET_OBJECTS = "itertive.ss.obj";
 
+    public static final ConfigOption<Integer> THROUGHPUT_CALCULATION_PERIOD =
+            ConfigOptions.key("io.throughput.calculationPeriod")
+                    .intType()
+                    .defaultValue(500)
+                    .withDescription("The amount of time between calculation the throughput(ms).");
+
+    public static final ConfigOption<Integer> THROUGHPUT_EMA_LAST_VALUES =

Review comment:
       It is actually not clear where should be both these configurations. THROUGHPUT_CALCULATION_PERIOD relates to streaming and perhaps it is better to move it to StreamConfig but holding them in separate places is also not a good idea. 
   So any ideas for the right place for these configs?

##########
File path: flink-runtime/src/main/java/org/apache/flink/runtime/throughput/EMAThroughputCalculator.java
##########
@@ -0,0 +1,53 @@
+/*
+ * 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.runtime.throughput;
+
+import static org.apache.flink.util.Preconditions.checkArgument;
+
+/** Implementation of 'Exponential moving average' algorithm. */
+public class EMAThroughputCalculator implements AverageThroughputCalculator {
+    private SMAThroughputCalculator smaThroughputCalculator;
+    private long currentThroughput;
+
+    /** EMA algorithm specific constant which responsible for speed of reaction. */
+    private final double alpha;
+
+    public EMAThroughputCalculator(int numberOfPreviousValues) {
+        smaThroughputCalculator = new SMAThroughputCalculator(numberOfPreviousValues);
+        alpha = 2.0 / (numberOfPreviousValues + 1);
+    }
+
+    @Override
+    public long calculateThroughput(long dataSize, long time) {
+        checkArgument(dataSize >= 0, "Size of data should be non negative");
+        checkArgument(time >= 0, "Time should be non negative");
+
+        if (time == 0) {
+            return currentThroughput;
+        }
+
+        if (smaThroughputCalculator.isWarmedUp()) {
+            currentThroughput += alpha * (dataSize * MILLIS_IN_SECOND / time - currentThroughput);

Review comment:
       > dataSize * MILLIS_IN_SECOND
   
   Maybe it is not so critical but can lead to overflow, so perhaps, it is better to rewrite it.

##########
File path: flink-runtime/src/main/java/org/apache/flink/runtime/taskmanager/Task.java
##########
@@ -417,11 +424,18 @@ public Task(
                         .toArray(new IndexedInputGate[0]);
 
         this.inputGates = new IndexedInputGate[gates.length];
+        this.throughputMeter =
+                new ThroughputMeter(
+                        SystemClock.getInstance(),
+                        new EMAThroughputCalculator(
+                                taskConfiguration.get(THROUGHPUT_EMA_LAST_VALUES)));

Review comment:
       One more sign of the problem with the configuration. I don't sure that we should get this directly from taskConfiguration but I don't now another way for now.

##########
File path: flink-runtime/src/main/java/org/apache/flink/runtime/throughput/SMAThroughputCalculator.java
##########
@@ -0,0 +1,70 @@
+/*
+ * 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.runtime.throughput;
+
+import static org.apache.flink.runtime.throughput.AverageThroughputCalculator.instantThroughput;
+import static org.apache.flink.util.Preconditions.checkArgument;
+import static org.apache.flink.util.Preconditions.checkState;
+
+/** Implementation of 'Simple moving average' algorithm. */
+public class SMAThroughputCalculator implements AverageThroughputCalculator {
+    /** The sum of the last throughputs.length throughputs. */
+    private long totalThroughput;
+    /** The buffer of the last calculated throughput. */
+    private long[] throughputs;
+    /** Current position in the throughputs. */
+    private int currentIndex = -1;
+    /** The number of last values which should be taken into account during calculation. */
+    private int numberOfPreviousValues = 0;
+
+    /**
+     * @param numberOfPreviousValues How many previous values should be taken into account during
+     *     the calculation.
+     */
+    public SMAThroughputCalculator(int numberOfPreviousValues) {
+        checkState(numberOfPreviousValues > 0, "Number of previous values should be positive.");
+        throughputs = new long[numberOfPreviousValues];
+    }
+
+    @Override
+    public long calculateThroughput(long dataSize, long time) {
+        checkArgument(dataSize >= 0, "Size of data should be non negative");
+        checkArgument(time >= 0, "Time should be non negative");
+
+        if (time == 0) {
+            return numberOfPreviousValues == 0 ? 0 : totalThroughput / numberOfPreviousValues;
+        }
+
+        long newThroughput = instantThroughput(dataSize, time);
+
+        currentIndex = (currentIndex + 1) % throughputs.length;
+        totalThroughput -= throughputs[currentIndex];
+        totalThroughput += (throughputs[currentIndex] = newThroughput);

Review comment:
       totalThroughput can be overflowed because it is the sum of the several last values. So it is possible to rewrite it via the previous value:
   `throughputPrevious + (currentInstantThrougput - instantThroughputNValuesAgo)/N` where N is number of desirable last values
   This approach is not applicable for the warm-up period, so the final solution will be a little more difficult.




-- 
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] akalash commented on a change in pull request #16556: [FLINK-23452][runtime] Added the throughput meter for measurement of …

Posted by GitBox <gi...@apache.org>.
akalash commented on a change in pull request #16556:
URL: https://github.com/apache/flink/pull/16556#discussion_r674160368



##########
File path: flink-streaming-java/src/main/java/org/apache/flink/streaming/runtime/tasks/StreamTask.java
##########
@@ -660,6 +668,19 @@ private void executeInvoke() throws Exception {
         afterInvoke();
     }
 
+    private void throughputCalculationSetup() {
+        systemTimerService.registerTimer(

Review comment:
       Perhaps, we should have the way to disable the throughput calculation. throughputCalculationPeriod == -1?




-- 
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 edited a comment on pull request #16556: [FLINK-23452][runtime] Added the throughput meter for measurement of …

Posted by GitBox <gi...@apache.org>.
flinkbot edited a comment on pull request #16556:
URL: https://github.com/apache/flink/pull/16556#issuecomment-884238774


   <!--
   Meta data
   {
     "version" : 1,
     "metaDataEntries" : [ {
       "hash" : "a7ef9c2b42f44c4ab4c1ba034a7c7f90640eef58",
       "status" : "DELETED",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=20794",
       "triggerID" : "a7ef9c2b42f44c4ab4c1ba034a7c7f90640eef58",
       "triggerType" : "PUSH"
     }, {
       "hash" : "814871decf09be535af651215adb650f678b70e1",
       "status" : "DELETED",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=20802",
       "triggerID" : "814871decf09be535af651215adb650f678b70e1",
       "triggerType" : "PUSH"
     }, {
       "hash" : "8c76db43092d6df17f52862a0d098dfb3a4a5ab3",
       "status" : "DELETED",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=20833",
       "triggerID" : "8c76db43092d6df17f52862a0d098dfb3a4a5ab3",
       "triggerType" : "PUSH"
     }, {
       "hash" : "4033dd607f8ea9d375c48e3054f070221f897674",
       "status" : "FAILURE",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=21046",
       "triggerID" : "4033dd607f8ea9d375c48e3054f070221f897674",
       "triggerType" : "PUSH"
     }, {
       "hash" : "0e57037543be0c39d28407180f15715cd0d30d7d",
       "status" : "UNKNOWN",
       "url" : "TBD",
       "triggerID" : "0e57037543be0c39d28407180f15715cd0d30d7d",
       "triggerType" : "PUSH"
     } ]
   }-->
   ## CI report:
   
   * 4033dd607f8ea9d375c48e3054f070221f897674 Azure: [FAILURE](https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=21046) 
   * 0e57037543be0c39d28407180f15715cd0d30d7d UNKNOWN
   
   <details>
   <summary>Bot commands</summary>
     The @flinkbot bot supports the following commands:
   
    - `@flinkbot run travis` re-run the last Travis build
    - `@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



[GitHub] [flink] flinkbot edited a comment on pull request #16556: [FLINK-23452][runtime] Added the throughput meter for measurement of …

Posted by GitBox <gi...@apache.org>.
flinkbot edited a comment on pull request #16556:
URL: https://github.com/apache/flink/pull/16556#issuecomment-884238774


   <!--
   Meta data
   {
     "version" : 1,
     "metaDataEntries" : [ {
       "hash" : "a7ef9c2b42f44c4ab4c1ba034a7c7f90640eef58",
       "status" : "DELETED",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=20794",
       "triggerID" : "a7ef9c2b42f44c4ab4c1ba034a7c7f90640eef58",
       "triggerType" : "PUSH"
     }, {
       "hash" : "814871decf09be535af651215adb650f678b70e1",
       "status" : "SUCCESS",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=20802",
       "triggerID" : "814871decf09be535af651215adb650f678b70e1",
       "triggerType" : "PUSH"
     }, {
       "hash" : "8c76db43092d6df17f52862a0d098dfb3a4a5ab3",
       "status" : "PENDING",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=20833",
       "triggerID" : "8c76db43092d6df17f52862a0d098dfb3a4a5ab3",
       "triggerType" : "PUSH"
     } ]
   }-->
   ## CI report:
   
   * 814871decf09be535af651215adb650f678b70e1 Azure: [SUCCESS](https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=20802) 
   * 8c76db43092d6df17f52862a0d098dfb3a4a5ab3 Azure: [PENDING](https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=20833) 
   
   <details>
   <summary>Bot commands</summary>
     The @flinkbot bot supports the following commands:
   
    - `@flinkbot run travis` re-run the last Travis build
    - `@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



[GitHub] [flink] flinkbot edited a comment on pull request #16556: [FLINK-23452][runtime] Added the throughput meter for measurement of …

Posted by GitBox <gi...@apache.org>.
flinkbot edited a comment on pull request #16556:
URL: https://github.com/apache/flink/pull/16556#issuecomment-884238774


   <!--
   Meta data
   {
     "version" : 1,
     "metaDataEntries" : [ {
       "hash" : "a7ef9c2b42f44c4ab4c1ba034a7c7f90640eef58",
       "status" : "DELETED",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=20794",
       "triggerID" : "a7ef9c2b42f44c4ab4c1ba034a7c7f90640eef58",
       "triggerType" : "PUSH"
     }, {
       "hash" : "814871decf09be535af651215adb650f678b70e1",
       "status" : "DELETED",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=20802",
       "triggerID" : "814871decf09be535af651215adb650f678b70e1",
       "triggerType" : "PUSH"
     }, {
       "hash" : "8c76db43092d6df17f52862a0d098dfb3a4a5ab3",
       "status" : "DELETED",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=20833",
       "triggerID" : "8c76db43092d6df17f52862a0d098dfb3a4a5ab3",
       "triggerType" : "PUSH"
     }, {
       "hash" : "4033dd607f8ea9d375c48e3054f070221f897674",
       "status" : "FAILURE",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=21046",
       "triggerID" : "4033dd607f8ea9d375c48e3054f070221f897674",
       "triggerType" : "PUSH"
     } ]
   }-->
   ## CI report:
   
   * 4033dd607f8ea9d375c48e3054f070221f897674 Azure: [FAILURE](https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=21046) 
   
   <details>
   <summary>Bot commands</summary>
     The @flinkbot bot supports the following commands:
   
    - `@flinkbot run travis` re-run the last Travis build
    - `@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



[GitHub] [flink] pnowojski commented on a change in pull request #16556: [FLINK-23452][runtime] Added the throughput meter for measurement of …

Posted by GitBox <gi...@apache.org>.
pnowojski commented on a change in pull request #16556:
URL: https://github.com/apache/flink/pull/16556#discussion_r678020154



##########
File path: flink-runtime/src/main/java/org/apache/flink/runtime/throughput/ThroughputMeter.java
##########
@@ -0,0 +1,82 @@
+/*
+ * 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.runtime.throughput;
+
+import org.apache.flink.util.clock.Clock;
+
+/** Class for measuring the throughput based on incoming data size and busy + backpressure time. */
+public class ThroughputMeter {
+    private static final long NOT_TRACKED = -1;
+    private final Clock clock;
+    private final AverageThroughputCalculator averageThroughputCalculator;
+
+    /** Accumulated data size for current period. */
+    private long currentSize;
+
+    /** Total busy time for current period(the total time minus idle time). */
+    private long currentTime;
+
+    /** The start of busy time. */
+    private long startTime;
+
+    /** The last throughput . */
+    private long effectiveThroughput;
+
+    public ThroughputMeter(Clock clock, AverageThroughputCalculator averageThroughputCalculator) {
+        this.clock = clock;
+        this.averageThroughputCalculator = averageThroughputCalculator;
+    }
+
+    /** @param size The size of received data. */
+    public void incomingDataSize(long size) {
+        currentSize += size;
+    }
+
+    /** Mark when idle time is started. */
+    public void idleStart() {
+        if (startTime != NOT_TRACKED) {
+            currentTime += clock.relativeTimeMillis() - startTime;
+        }
+        startTime = NOT_TRACKED;
+    }
+
+    /** Mark when idle time is ended. */
+    public void idleEnd() {
+        startTime = clock.relativeTimeMillis();
+    }
+
+    /**
+     * Calculate throughput based on the collected data for the last period.
+     *
+     * @return {@code -1} if it is impossible to calculate throughput and actual value otherwise.
+     */
+    public long calculateThroughput() {

Review comment:
       If so, why don't you set `startTime = currentTimeMillis()` inside `incomingDataSize()` if it is still `0`?




-- 
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] akalash commented on a change in pull request #16556: [FLINK-23452][runtime] Added the throughput meter for measurement of …

Posted by GitBox <gi...@apache.org>.
akalash commented on a change in pull request #16556:
URL: https://github.com/apache/flink/pull/16556#discussion_r674159692



##########
File path: flink-streaming-java/src/main/java/org/apache/flink/streaming/runtime/tasks/StreamTask.java
##########
@@ -660,6 +668,19 @@ private void executeInvoke() throws Exception {
         afterInvoke();
     }
 
+    private void throughputCalculationSetup() {
+        systemTimerService.registerTimer(
+                systemTimerService.getCurrentProcessingTime()
+                        + configuration.getThroughputCalculationPeriod(),
+                timestamp ->
+                        mainMailboxExecutor.submit(
+                                () -> {
+                                    throughputMeter.calculateThroughput();
+                                    throughputCalculationSetup();

Review comment:
       Is it possible to add the listener on the future somehow instead of doing it inside of the run?

##########
File path: flink-streaming-java/src/main/java/org/apache/flink/streaming/runtime/tasks/StreamTask.java
##########
@@ -660,6 +668,19 @@ private void executeInvoke() throws Exception {
         afterInvoke();
     }
 
+    private void throughputCalculationSetup() {
+        systemTimerService.registerTimer(

Review comment:
       Perhaps, we should have the configuration to disable the throughput calculation. throughputCalculationPeriod == -1?




-- 
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 edited a comment on pull request #16556: [FLINK-23452][runtime] Added the throughput meter for measurement of …

Posted by GitBox <gi...@apache.org>.
flinkbot edited a comment on pull request #16556:
URL: https://github.com/apache/flink/pull/16556#issuecomment-884238774


   <!--
   Meta data
   {
     "version" : 1,
     "metaDataEntries" : [ {
       "hash" : "a7ef9c2b42f44c4ab4c1ba034a7c7f90640eef58",
       "status" : "FAILURE",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=20794",
       "triggerID" : "a7ef9c2b42f44c4ab4c1ba034a7c7f90640eef58",
       "triggerType" : "PUSH"
     }, {
       "hash" : "814871decf09be535af651215adb650f678b70e1",
       "status" : "PENDING",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=20802",
       "triggerID" : "814871decf09be535af651215adb650f678b70e1",
       "triggerType" : "PUSH"
     } ]
   }-->
   ## CI report:
   
   * a7ef9c2b42f44c4ab4c1ba034a7c7f90640eef58 Azure: [FAILURE](https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=20794) 
   * 814871decf09be535af651215adb650f678b70e1 Azure: [PENDING](https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=20802) 
   
   <details>
   <summary>Bot commands</summary>
     The @flinkbot bot supports the following commands:
   
    - `@flinkbot run travis` re-run the last Travis build
    - `@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



[GitHub] [flink] pnowojski commented on a change in pull request #16556: [FLINK-23452][runtime] Added the throughput meter for measurement of …

Posted by GitBox <gi...@apache.org>.
pnowojski commented on a change in pull request #16556:
URL: https://github.com/apache/flink/pull/16556#discussion_r678020435



##########
File path: flink-runtime/src/main/java/org/apache/flink/runtime/throughput/ThroughputCalculator.java
##########
@@ -0,0 +1,81 @@
+/*
+ * 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.runtime.throughput;
+
+import org.apache.flink.util.clock.Clock;
+
+/** Class for measuring the throughput based on incoming data size and measurement period. */
+public class ThroughputCalculator {
+    private static final long NOT_TRACKED = -1;
+    private final Clock clock;
+    private final ThroughputEMA throughputEMA;
+
+    /** Accumulated data size for current period. */
+    private long currentSize;
+
+    /** Total measurement time for current period. */
+    private long currentTime;
+
+    /** The start of measurement time. */
+    private long startTime = NOT_TRACKED;
+
+    /** The last throughput . */

Review comment:
       nit: noop comment?

##########
File path: flink-core/src/main/java/org/apache/flink/configuration/TaskManagerOptions.java
##########
@@ -512,6 +512,21 @@
                                     + " the configured min/max size, the min/max size will be used. The exact size of Network Memory can be"
                                     + " explicitly specified by setting the min/max size to the same value.");
 
+    /** The period between recalculation amount of the in-flight data. */
+    public static final ConfigOption<Integer> IN_FLIGHT_DATA_ADJUSTMENT_PERIOD =
+            ConfigOptions.key("taskmanager.memory.network.in-flight-data-adjustment.period")
+                    .intType()
+                    .defaultValue(500)
+                    .withDescription("The amount of time between calculation the throughput(ms).");

Review comment:
       adjust the description?

##########
File path: flink-streaming-java/src/test/java/org/apache/flink/streaming/runtime/tasks/StreamTaskTest.java
##########
@@ -1727,6 +1731,99 @@ protected void cancelTask() {
         assertTrue(OpenFailingOperator.wasClosed);
     }
 
+    @Test
+    public void testMailboxNotifyThroughputMeterAboutIdleTime() throws Exception {
+        final long sleepTimeOutsideMail = 42;
+        final long sleepTimeInsideMail = 44;
+        int incomingDataSize = 10_000;
+
+        @Nullable WaitingThread waitingThread = null;
+        try (final MockEnvironment environment = setupEnvironment(true, true)) {
+            final UnAvailableTestInputProcessor inputProcessor =
+                    new UnAvailableTestInputProcessor();
+            final StreamTask task =
+                    new MockStreamTaskBuilder(environment)
+                            .setStreamInputProcessor(inputProcessor)
+                            .build();
+            TaskIOMetricGroup ioMetricGroup =
+                    task.getEnvironment().getMetricGroup().getIOMetricGroup();
+            ThroughputCalculator throughputCalculator = environment.getThroughputMeter();
+
+            final MailboxExecutor executor = task.mailboxProcessor.getMainMailboxExecutor();
+            final RunnableWithException completeFutureTask =
+                    () ->
+                            inputProcessor
+                                    .availabilityProvider
+                                    .getUnavailableToResetAvailable()
+                                    .complete(null);
+
+            waitingThread =
+                    new WaitingThread(
+                            executor,
+                            completeFutureTask,
+                            sleepTimeInsideMail,
+                            sleepTimeOutsideMail,
+                            ioMetricGroup.getIdleTimeMsPerSecond());
+            // Make sure WaitingThread is started after Task starts processing.
+            executor.submit(
+                    waitingThread::start,
+                    "Start WaitingThread after Task starts processing input.");
+
+            long startTs = System.currentTimeMillis();
+            throughputCalculator.calculateThroughput();
+            throughputCalculator.incomingDataSize(incomingDataSize);
+            task.invoke();
+            long resultThroughput = throughputCalculator.calculateThroughput();
+            long totalDuration = System.currentTimeMillis() - startTs;
+
+            assertThat(
+                    resultThroughput,
+                    greaterThanOrEqualTo(
+                            incomingDataSize * 1000 / (totalDuration - sleepTimeOutsideMail)));
+        } finally {
+            if (waitingThread != null) {
+                waitingThread.join();
+            }
+        }
+    }
+
+    @Test
+    public void testThroughputSchedulerStartsOnInvoke() throws Exception {
+        // given: Throughput meter which finishes the task when calculateThroughput was called.
+        UnAvailableTestInputProcessor inputProcessor = new UnAvailableTestInputProcessor();
+        AtomicInteger desirableNumberOfCalculation = new AtomicInteger(2);
+        try (MockEnvironment mockEnvironment =
+                new MockEnvironmentBuilder()
+                        .setTaskConfiguration(
+                                new Configuration().set(IN_FLIGHT_DATA_ADJUSTMENT_PERIOD, 1))
+                        .setThroughputMeter(
+                                new ThroughputCalculator(SystemClock.getInstance(), 10) {
+                                    @Override
+                                    public long calculateThroughput() {
+                                        if (desirableNumberOfCalculation.decrementAndGet() == 0) {
+                                            inputProcessor
+                                                    .availabilityProvider
+                                                    .getUnavailableToResetAvailable()
+                                                    .complete(null);
+                                        }
+                                        return super.calculateThroughput();
+                                    }
+                                })
+                        .build()) {
+
+            StreamTask task =
+                    new MockStreamTaskBuilder(mockEnvironment)
+                            .setStreamInputProcessor(inputProcessor)
+                            .build();
+
+            // when: Starting the task.
+            task.invoke();
+
+            // then: The task successfully finishes because throughput calculation was called from
+            // scheduler which leads to the finish of the task
+        }
+    }

Review comment:
       What is the purpose of this test? Isn't it superseded by/subset of the `testMailboxNotifyThroughputMeterAboutIdleTime`?

##########
File path: flink-core/src/main/java/org/apache/flink/configuration/TaskManagerOptions.java
##########
@@ -512,6 +512,21 @@
                                     + " the configured min/max size, the min/max size will be used. The exact size of Network Memory can be"
                                     + " explicitly specified by setting the min/max size to the same value.");
 
+    /** The period between recalculation amount of the in-flight data. */
+    public static final ConfigOption<Integer> IN_FLIGHT_DATA_ADJUSTMENT_PERIOD =
+            ConfigOptions.key("taskmanager.memory.network.in-flight-data-adjustment.period")

Review comment:
       as per offline discussion: 
   ```
   taskmanager.network.memory.automatic-buffer-adjustment.period
   taskmanager.network.memory.automatic-buffer-adjustment.samples
   taskmanager.network.memory.automatic-buffer-adjustment.enabled #(future PR)
   ```?

##########
File path: flink-runtime/src/main/java/org/apache/flink/runtime/throughput/ThroughputCalculator.java
##########
@@ -0,0 +1,81 @@
+/*
+ * 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.runtime.throughput;
+
+import org.apache.flink.util.clock.Clock;
+
+/** Class for measuring the throughput based on incoming data size and measurement period. */
+public class ThroughputCalculator {
+    private static final long NOT_TRACKED = -1;
+    private final Clock clock;
+    private final ThroughputEMA throughputEMA;
+
+    /** Accumulated data size for current period. */
+    private long currentSize;
+
+    /** Total measurement time for current period. */
+    private long currentTime;
+
+    /** The start of measurement time. */
+    private long startTime = NOT_TRACKED;
+
+    /** The last throughput . */
+    private long lastThroughput;
+
+    public ThroughputCalculator(Clock clock, int numberOfSamples) {
+        this.clock = clock;
+        this.throughputEMA = new ThroughputEMA(numberOfSamples);
+    }
+
+    /** @param size The size of received data. */

Review comment:
       nit: rename `size` -> `receivedDataSize` and drop the comment? 
   
   (and ditto in other places like `currentSize` -> `currentAccumulatedDataSize`, `currentTime` -> `currentMeasurementTime`, `startTime` -> `measurementStartTime`)?

##########
File path: flink-streaming-java/src/test/java/org/apache/flink/streaming/runtime/tasks/StreamTaskTest.java
##########
@@ -1727,6 +1731,99 @@ protected void cancelTask() {
         assertTrue(OpenFailingOperator.wasClosed);
     }
 
+    @Test
+    public void testMailboxNotifyThroughputMeterAboutIdleTime() throws Exception {
+        final long sleepTimeOutsideMail = 42;
+        final long sleepTimeInsideMail = 44;
+        int incomingDataSize = 10_000;
+
+        @Nullable WaitingThread waitingThread = null;
+        try (final MockEnvironment environment = setupEnvironment(true, true)) {
+            final UnAvailableTestInputProcessor inputProcessor =
+                    new UnAvailableTestInputProcessor();
+            final StreamTask task =
+                    new MockStreamTaskBuilder(environment)
+                            .setStreamInputProcessor(inputProcessor)
+                            .build();
+            TaskIOMetricGroup ioMetricGroup =
+                    task.getEnvironment().getMetricGroup().getIOMetricGroup();
+            ThroughputCalculator throughputCalculator = environment.getThroughputMeter();
+
+            final MailboxExecutor executor = task.mailboxProcessor.getMainMailboxExecutor();
+            final RunnableWithException completeFutureTask =
+                    () ->
+                            inputProcessor
+                                    .availabilityProvider
+                                    .getUnavailableToResetAvailable()
+                                    .complete(null);
+
+            waitingThread =
+                    new WaitingThread(
+                            executor,
+                            completeFutureTask,
+                            sleepTimeInsideMail,
+                            sleepTimeOutsideMail,
+                            ioMetricGroup.getIdleTimeMsPerSecond());
+            // Make sure WaitingThread is started after Task starts processing.
+            executor.submit(
+                    waitingThread::start,
+                    "Start WaitingThread after Task starts processing input.");
+
+            long startTs = System.currentTimeMillis();
+            throughputCalculator.calculateThroughput();
+            throughputCalculator.incomingDataSize(incomingDataSize);
+            task.invoke();
+            long resultThroughput = throughputCalculator.calculateThroughput();
+            long totalDuration = System.currentTimeMillis() - startTs;
+
+            assertThat(
+                    resultThroughput,
+                    greaterThanOrEqualTo(
+                            incomingDataSize * 1000 / (totalDuration - sleepTimeOutsideMail)));

Review comment:
       This test duplicates quite a lot of code from `testProcessWithUnAvailableInput`. I would either:
   1. put those highlighted lines inside `testProcessWithUnAvailableInput`
   2. or deduplicate in another way the test setup 
   
   I'm not sure how 2. could be done easily, so I would go with 1?




-- 
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 edited a comment on pull request #16556: [FLINK-23452][runtime] Added the throughput meter for measurement of …

Posted by GitBox <gi...@apache.org>.
flinkbot edited a comment on pull request #16556:
URL: https://github.com/apache/flink/pull/16556#issuecomment-884238774


   <!--
   Meta data
   {
     "version" : 1,
     "metaDataEntries" : [ {
       "hash" : "a7ef9c2b42f44c4ab4c1ba034a7c7f90640eef58",
       "status" : "DELETED",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=20794",
       "triggerID" : "a7ef9c2b42f44c4ab4c1ba034a7c7f90640eef58",
       "triggerType" : "PUSH"
     }, {
       "hash" : "814871decf09be535af651215adb650f678b70e1",
       "status" : "DELETED",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=20802",
       "triggerID" : "814871decf09be535af651215adb650f678b70e1",
       "triggerType" : "PUSH"
     }, {
       "hash" : "8c76db43092d6df17f52862a0d098dfb3a4a5ab3",
       "status" : "DELETED",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=20833",
       "triggerID" : "8c76db43092d6df17f52862a0d098dfb3a4a5ab3",
       "triggerType" : "PUSH"
     }, {
       "hash" : "4033dd607f8ea9d375c48e3054f070221f897674",
       "status" : "DELETED",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=21046",
       "triggerID" : "4033dd607f8ea9d375c48e3054f070221f897674",
       "triggerType" : "PUSH"
     }, {
       "hash" : "0e57037543be0c39d28407180f15715cd0d30d7d",
       "status" : "DELETED",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=21118",
       "triggerID" : "0e57037543be0c39d28407180f15715cd0d30d7d",
       "triggerType" : "PUSH"
     }, {
       "hash" : "2adc6fbcf2a79a142e50d6c2dc57b3c6ea002c1e",
       "status" : "SUCCESS",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=21122",
       "triggerID" : "2adc6fbcf2a79a142e50d6c2dc57b3c6ea002c1e",
       "triggerType" : "PUSH"
     } ]
   }-->
   ## CI report:
   
   * 2adc6fbcf2a79a142e50d6c2dc57b3c6ea002c1e Azure: [SUCCESS](https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=21122) 
   
   <details>
   <summary>Bot commands</summary>
     The @flinkbot bot supports the following commands:
   
    - `@flinkbot run travis` re-run the last Travis build
    - `@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



[GitHub] [flink] flinkbot edited a comment on pull request #16556: [FLINK-23452][runtime] Added the throughput meter for measurement of …

Posted by GitBox <gi...@apache.org>.
flinkbot edited a comment on pull request #16556:
URL: https://github.com/apache/flink/pull/16556#issuecomment-884238774


   <!--
   Meta data
   {
     "version" : 1,
     "metaDataEntries" : [ {
       "hash" : "a7ef9c2b42f44c4ab4c1ba034a7c7f90640eef58",
       "status" : "DELETED",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=20794",
       "triggerID" : "a7ef9c2b42f44c4ab4c1ba034a7c7f90640eef58",
       "triggerType" : "PUSH"
     }, {
       "hash" : "814871decf09be535af651215adb650f678b70e1",
       "status" : "DELETED",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=20802",
       "triggerID" : "814871decf09be535af651215adb650f678b70e1",
       "triggerType" : "PUSH"
     }, {
       "hash" : "8c76db43092d6df17f52862a0d098dfb3a4a5ab3",
       "status" : "DELETED",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=20833",
       "triggerID" : "8c76db43092d6df17f52862a0d098dfb3a4a5ab3",
       "triggerType" : "PUSH"
     }, {
       "hash" : "4033dd607f8ea9d375c48e3054f070221f897674",
       "status" : "FAILURE",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=21046",
       "triggerID" : "4033dd607f8ea9d375c48e3054f070221f897674",
       "triggerType" : "PUSH"
     }, {
       "hash" : "0e57037543be0c39d28407180f15715cd0d30d7d",
       "status" : "PENDING",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=21118",
       "triggerID" : "0e57037543be0c39d28407180f15715cd0d30d7d",
       "triggerType" : "PUSH"
     }, {
       "hash" : "2adc6fbcf2a79a142e50d6c2dc57b3c6ea002c1e",
       "status" : "PENDING",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=21122",
       "triggerID" : "2adc6fbcf2a79a142e50d6c2dc57b3c6ea002c1e",
       "triggerType" : "PUSH"
     } ]
   }-->
   ## CI report:
   
   * 4033dd607f8ea9d375c48e3054f070221f897674 Azure: [FAILURE](https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=21046) 
   * 0e57037543be0c39d28407180f15715cd0d30d7d Azure: [PENDING](https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=21118) 
   * 2adc6fbcf2a79a142e50d6c2dc57b3c6ea002c1e Azure: [PENDING](https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=21122) 
   
   <details>
   <summary>Bot commands</summary>
     The @flinkbot bot supports the following commands:
   
    - `@flinkbot run travis` re-run the last Travis build
    - `@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



[GitHub] [flink] akalash commented on a change in pull request #16556: [FLINK-23452][runtime] Added the throughput meter for measurement of …

Posted by GitBox <gi...@apache.org>.
akalash commented on a change in pull request #16556:
URL: https://github.com/apache/flink/pull/16556#discussion_r678133730



##########
File path: flink-streaming-java/src/test/java/org/apache/flink/streaming/runtime/tasks/StreamTaskTest.java
##########
@@ -1727,6 +1731,99 @@ protected void cancelTask() {
         assertTrue(OpenFailingOperator.wasClosed);
     }
 
+    @Test
+    public void testMailboxNotifyThroughputMeterAboutIdleTime() throws Exception {
+        final long sleepTimeOutsideMail = 42;
+        final long sleepTimeInsideMail = 44;
+        int incomingDataSize = 10_000;
+
+        @Nullable WaitingThread waitingThread = null;
+        try (final MockEnvironment environment = setupEnvironment(true, true)) {
+            final UnAvailableTestInputProcessor inputProcessor =
+                    new UnAvailableTestInputProcessor();
+            final StreamTask task =
+                    new MockStreamTaskBuilder(environment)
+                            .setStreamInputProcessor(inputProcessor)
+                            .build();
+            TaskIOMetricGroup ioMetricGroup =
+                    task.getEnvironment().getMetricGroup().getIOMetricGroup();
+            ThroughputCalculator throughputCalculator = environment.getThroughputMeter();
+
+            final MailboxExecutor executor = task.mailboxProcessor.getMainMailboxExecutor();
+            final RunnableWithException completeFutureTask =
+                    () ->
+                            inputProcessor
+                                    .availabilityProvider
+                                    .getUnavailableToResetAvailable()
+                                    .complete(null);
+
+            waitingThread =
+                    new WaitingThread(
+                            executor,
+                            completeFutureTask,
+                            sleepTimeInsideMail,
+                            sleepTimeOutsideMail,
+                            ioMetricGroup.getIdleTimeMsPerSecond());
+            // Make sure WaitingThread is started after Task starts processing.
+            executor.submit(
+                    waitingThread::start,
+                    "Start WaitingThread after Task starts processing input.");
+
+            long startTs = System.currentTimeMillis();
+            throughputCalculator.calculateThroughput();
+            throughputCalculator.incomingDataSize(incomingDataSize);
+            task.invoke();
+            long resultThroughput = throughputCalculator.calculateThroughput();
+            long totalDuration = System.currentTimeMillis() - startTs;
+
+            assertThat(
+                    resultThroughput,
+                    greaterThanOrEqualTo(
+                            incomingDataSize * 1000 / (totalDuration - sleepTimeOutsideMail)));
+        } finally {
+            if (waitingThread != null) {
+                waitingThread.join();
+            }
+        }
+    }
+
+    @Test
+    public void testThroughputSchedulerStartsOnInvoke() throws Exception {
+        // given: Throughput meter which finishes the task when calculateThroughput was called.
+        UnAvailableTestInputProcessor inputProcessor = new UnAvailableTestInputProcessor();
+        AtomicInteger desirableNumberOfCalculation = new AtomicInteger(2);
+        try (MockEnvironment mockEnvironment =
+                new MockEnvironmentBuilder()
+                        .setTaskConfiguration(
+                                new Configuration().set(IN_FLIGHT_DATA_ADJUSTMENT_PERIOD, 1))
+                        .setThroughputMeter(
+                                new ThroughputCalculator(SystemClock.getInstance(), 10) {
+                                    @Override
+                                    public long calculateThroughput() {
+                                        if (desirableNumberOfCalculation.decrementAndGet() == 0) {
+                                            inputProcessor
+                                                    .availabilityProvider
+                                                    .getUnavailableToResetAvailable()
+                                                    .complete(null);
+                                        }
+                                        return super.calculateThroughput();
+                                    }
+                                })
+                        .build()) {
+
+            StreamTask task =
+                    new MockStreamTaskBuilder(mockEnvironment)
+                            .setStreamInputProcessor(inputProcessor)
+                            .build();
+
+            // when: Starting the task.
+            task.invoke();
+
+            // then: The task successfully finishes because throughput calculation was called from
+            // scheduler which leads to the finish of the task
+        }
+    }

Review comment:
       This test checks the fact that throughput calculation is started automatically(just to be sure that the scheduler is configured). But the calculation inside of `testMailboxNotifyThroughputMeterAboutIdleTime` is triggered manually in order to have more predictable value.




-- 
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 edited a comment on pull request #16556: [FLINK-23452][runtime] Added the throughput meter for measurement of …

Posted by GitBox <gi...@apache.org>.
flinkbot edited a comment on pull request #16556:
URL: https://github.com/apache/flink/pull/16556#issuecomment-884238774


   <!--
   Meta data
   {
     "version" : 1,
     "metaDataEntries" : [ {
       "hash" : "a7ef9c2b42f44c4ab4c1ba034a7c7f90640eef58",
       "status" : "DELETED",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=20794",
       "triggerID" : "a7ef9c2b42f44c4ab4c1ba034a7c7f90640eef58",
       "triggerType" : "PUSH"
     }, {
       "hash" : "814871decf09be535af651215adb650f678b70e1",
       "status" : "DELETED",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=20802",
       "triggerID" : "814871decf09be535af651215adb650f678b70e1",
       "triggerType" : "PUSH"
     }, {
       "hash" : "8c76db43092d6df17f52862a0d098dfb3a4a5ab3",
       "status" : "DELETED",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=20833",
       "triggerID" : "8c76db43092d6df17f52862a0d098dfb3a4a5ab3",
       "triggerType" : "PUSH"
     }, {
       "hash" : "4033dd607f8ea9d375c48e3054f070221f897674",
       "status" : "FAILURE",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=21046",
       "triggerID" : "4033dd607f8ea9d375c48e3054f070221f897674",
       "triggerType" : "PUSH"
     }, {
       "hash" : "0e57037543be0c39d28407180f15715cd0d30d7d",
       "status" : "PENDING",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=21118",
       "triggerID" : "0e57037543be0c39d28407180f15715cd0d30d7d",
       "triggerType" : "PUSH"
     }, {
       "hash" : "2adc6fbcf2a79a142e50d6c2dc57b3c6ea002c1e",
       "status" : "UNKNOWN",
       "url" : "TBD",
       "triggerID" : "2adc6fbcf2a79a142e50d6c2dc57b3c6ea002c1e",
       "triggerType" : "PUSH"
     } ]
   }-->
   ## CI report:
   
   * 4033dd607f8ea9d375c48e3054f070221f897674 Azure: [FAILURE](https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=21046) 
   * 0e57037543be0c39d28407180f15715cd0d30d7d Azure: [PENDING](https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=21118) 
   * 2adc6fbcf2a79a142e50d6c2dc57b3c6ea002c1e UNKNOWN
   
   <details>
   <summary>Bot commands</summary>
     The @flinkbot bot supports the following commands:
   
    - `@flinkbot run travis` re-run the last Travis build
    - `@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



[GitHub] [flink] pnowojski commented on a change in pull request #16556: [FLINK-23452][runtime] Added the throughput meter for measurement of …

Posted by GitBox <gi...@apache.org>.
pnowojski commented on a change in pull request #16556:
URL: https://github.com/apache/flink/pull/16556#discussion_r676542558



##########
File path: flink-libraries/flink-state-processing-api/src/main/java/org/apache/flink/state/api/runtime/SavepointEnvironment.java
##########
@@ -285,6 +286,11 @@ public TaskEventDispatcher getTaskEventDispatcher() {
         throw new UnsupportedOperationException(ERROR_MSG);
     }
 
+    @Override
+    public ThroughputMeter getThroughputMeter() {
+        return null;

Review comment:
       why `null`? `throw new UnsupportedOperationException()`?




-- 
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