taoran92 commented on code in PR #4422:
URL: https://github.com/apache/flink-cdc/pull/4422#discussion_r3763455724


##########
flink-cdc-connect/flink-cdc-source-connectors/flink-connector-debezium/src/main/java/io/debezium/relational/CachedTableFilter.java:
##########
@@ -0,0 +1,67 @@
+/*
+ * 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 io.debezium.relational;
+
+import org.apache.flink.shaded.guava31.com.google.common.cache.CacheBuilder;
+import org.apache.flink.shaded.guava31.com.google.common.cache.CacheLoader;
+import org.apache.flink.shaded.guava31.com.google.common.cache.LoadingCache;
+
+import io.debezium.relational.Tables.TableFilter;
+
+/** A bounded cache for table filter results. */
+public class CachedTableFilter implements TableFilter {
+
+    private static final long TABLE_FILTER_CACHE_MAXIMUM_SIZE = 1024;
+
+    private final TableFilter rawTableFilter;
+    private final LoadingCache<TableId, Boolean> tableFilterCache;
+
+    private CachedTableFilter(TableFilter rawTableFilter) {
+        this.rawTableFilter = rawTableFilter;
+        this.tableFilterCache =
+                CacheBuilder.newBuilder()
+                        .maximumSize(TABLE_FILTER_CACHE_MAXIMUM_SIZE)

Review Comment:
   Q2. about cache size
   
   I suggest increasing the maximum cache size to 32 * 1024.
   
   The reported production case contains about 18,000 tables, so a size of 
1,024 covers only around 5.7% of the working set. Repeated full-table scans may 
therefore cause cache thrashing and result in almost no cache hits. A limit of 
32,768 can hold the complete working set while leaving reasonable headroom for 
newly added tables.
   
   Guava does not preallocate memory for the configured maximum size. Based on 
a Java 11 object-graph measurement, caching 18,000 TableId entries consumes 
approximately 4.25 MiB per cache instance, while a fully populated 32,768-entry 
cache consumes approximately 7.74 MiB. Actual usage may vary with identifier 
lengths and JVM configuration, but this remains a reasonable trade-off between 
performance and bounded memory usage.
   
   
   | Maximum size | Actual entries | Approximate memory per cache instance |
   | :--- | :--- | :--- |
   | 1,024 | 1,024 | 0.24 MiB |
   | 18,000 | 18,000 | 4.23 MiB |
   | 32,768 | 18,000 | 4.25 MiB |
   | 32,768 | 32,768 | 7.74 MiB |
   | 65,536 | 65,536 | 15.49 MiB |
   
   WDYT? cc @leonardBang @ruanhang1993 



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to