You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@flink.apache.org by GitBox <gi...@apache.org> on 2022/11/17 09:45:38 UTC

[GitHub] [flink] rkhachatryan commented on a diff in pull request #21264: [WIP][FLINK-29928][runtime, state] Share RocksDB memory across TM slots

rkhachatryan commented on code in PR #21264:
URL: https://github.com/apache/flink/pull/21264#discussion_r1024964191


##########
flink-tests/src/test/java/org/apache/flink/test/state/TaskManagerWideRocksDbMemorySharingITCase.java:
##########
@@ -0,0 +1,257 @@
+/*
+ * 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.test.state;
+
+import org.apache.flink.api.common.JobID;
+import org.apache.flink.api.common.functions.RichMapFunction;
+import org.apache.flink.api.common.state.ListState;
+import org.apache.flink.api.common.state.ListStateDescriptor;
+import org.apache.flink.api.common.time.Deadline;
+import org.apache.flink.configuration.Configuration;
+import org.apache.flink.configuration.MemorySize;
+import org.apache.flink.configuration.StateBackendOptions;
+import org.apache.flink.configuration.TaskManagerOptions;
+import org.apache.flink.contrib.streaming.state.RocksDBNativeMetricOptions;
+import org.apache.flink.contrib.streaming.state.RocksDBOptions;
+import org.apache.flink.metrics.Gauge;
+import org.apache.flink.runtime.jobgraph.JobGraph;
+import org.apache.flink.runtime.testutils.InMemoryReporter;
+import org.apache.flink.runtime.testutils.MiniClusterResourceConfiguration;
+import org.apache.flink.streaming.api.CheckpointingMode;
+import org.apache.flink.streaming.api.datastream.DataStreamSource;
+import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
+import org.apache.flink.streaming.api.functions.sink.DiscardingSink;
+import org.apache.flink.test.util.MiniClusterWithClientResource;
+
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+import java.math.BigInteger;
+import java.time.Duration;
+import java.util.ArrayList;
+import java.util.DoubleSummaryStatistics;
+import java.util.List;
+import java.util.Random;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+
+import static org.apache.flink.api.common.restartstrategy.RestartStrategies.noRestart;
+import static org.apache.flink.contrib.streaming.state.RocksDBMemoryControllerUtils.calculateActualCacheCapacity;
+import static org.apache.flink.runtime.testutils.CommonTestUtils.waitForAllTaskRunning;
+import static org.apache.flink.util.Preconditions.checkState;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+/**
+ * Tests that memory sharing scope and {@link TaskManagerOptions#MANAGED_MEMORY_SHARED_FRACTION}
+ * work as expected, i.e. make RocksDB use the same BlockCache and WriteBufferManager objects. It
+ * does so using RocksDB metrics.
+ */
+public class TaskManagerWideRocksDbMemorySharingITCase {
+    private static final int PARALLELISM = 4;
+    private static final int NUMBER_OF_JOBS = 5;
+    private static final int NUMBER_OF_TASKS = NUMBER_OF_JOBS * PARALLELISM;
+
+    private static final int MANAGED_MEMORY_SIZE_BYTES = NUMBER_OF_TASKS * 25 * 1024 * 1024;
+    private static final double MANAGED_MEMORY_SHARED_FRACTION = .85d;
+    private static final double WRITE_BUFFER_RATIO = 0.5;
+    private static final double EXPECTED_BLOCK_CACHE_SIZE =
+            calculateActualCacheCapacity(
+                    (long) (MANAGED_MEMORY_SIZE_BYTES * MANAGED_MEMORY_SHARED_FRACTION),
+                    WRITE_BUFFER_RATIO);
+    // try to check that the memory usage is limited
+    // however, there is no hard limit actually
+    // because of https://issues.apache.org/jira/browse/FLINK-15532
+    private static final double EFFECTIVE_LIMIT = EXPECTED_BLOCK_CACHE_SIZE * 1.25;
+
+    private InMemoryReporter metricsReporter;
+    private MiniClusterWithClientResource cluster;
+
+    @Before
+    public void init() throws Exception {
+        metricsReporter = InMemoryReporter.create();
+        cluster =
+                new MiniClusterWithClientResource(
+                        new MiniClusterResourceConfiguration.Builder()
+                                .setConfiguration(getConfiguration(metricsReporter))
+                                .setNumberTaskManagers(1)
+                                .setNumberSlotsPerTaskManager(NUMBER_OF_TASKS)
+                                .build());
+        cluster.before();
+    }
+
+    @After
+    public void destroy() {
+        cluster.after();
+        metricsReporter.close();
+    }
+
+    @Test
+    public void testBlockCache() throws Exception {
+        List<JobID> jobIDs = new ArrayList<>(NUMBER_OF_JOBS);
+        try {
+            // launch jobs
+            for (int i = 0; i < NUMBER_OF_JOBS; i++) {
+                jobIDs.add(cluster.getRestClusterClient().submitJob(dag()).get());
+            }
+
+            // wait for init
+            Deadline initDeadline = Deadline.fromNow(Duration.ofMinutes(1));
+            for (JobID jid : jobIDs) {
+                waitForAllTaskRunning(cluster.getMiniCluster(), jid, false);
+                waitForAllMetricsReported(jid, initDeadline);
+            }
+
+            // check declared capacity
+            collectGaugeValues(jobIDs, "rocksdb.block-cache-capacity")

Review Comment:
   That's right, it measures the total **capacity** (among all backends on TM), regardless of how the memory was allocated.



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