You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@fluss.apache.org by "loserwang1024 (via GitHub)" <gi...@apache.org> on 2026/09/20 11:57:48 UTC

[PR] [client][metrics] Expose record accumulator memory usage metrics. [fluss]

loserwang1024 opened a new pull request, #4448:
URL: https://github.com/apache/fluss/pull/4448

   <!--
   *Thank you very much for contributing to Fluss - we are happy that you want to help us improve Fluss. 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.*
   
   ## Contribution Checklist
   
     - Make sure that the pull request corresponds to a [GitHub issue](https://github.com/apache/fluss/issues). Exceptions are made for typos in JavaDoc or documentation files, which need no issue.
   
     - Name the pull request in the format "[component] Title of the pull request", where *[component]* should be replaced by the name of the component being changed. Typically, this corresponds to the component label assigned to the issue (e.g., [kv], [log], [client], [flink], [rust], [python], [c++], [elixir]). Skip *[component]* if you are unsure about which is the best component.
   
     - 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.
   
     - Each pull request should address only one issue, not mix up code from multiple issues.
   
     - **Generative AI disclosure:** Indicate whether generative AI tools were used in authoring this PR. If yes, specify the tool below.
       - [ ] No generative AI tools used
       - [ ] Yes (please specify the tool below)
   
   **(The sections below can be removed for hotfixes or typos)**
   -->
   
   <!--
   Generated-by: [Tool Name and Version] following [the guidelines](https://github.com/apache/fluss/blob/main/AGENTS.md)
   -->
   
   ### Purpose
   
   <!-- Linking this pull request to the issue -->
   Linked issue: close https://github.com/apache/fluss/issues/4447
   
   <!-- What is the purpose of the change -->
   
   ### Brief change log
   
   <!-- Please describe the changes made in this pull request and explain how they address the issue -->
   
   ### Tests
   
   <!-- List UT and IT cases to verify this change -->
   
   ### API and Format
   
   <!-- Does this change affect API or storage format -->
   
   ### Documentation
   
   <!-- Does this change introduce a new feature -->
   


-- 
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@fluss.apache.org

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


Re: [PR] [client][metrics] Expose record accumulator memory usage metrics. [fluss]

Posted by "platinumhamburg (via GitHub)" <gi...@apache.org>.
platinumhamburg commented on code in PR #4448:
URL: https://github.com/apache/fluss/pull/4448#discussion_r4058955121


##########
fluss-common/src/main/java/org/apache/fluss/metrics/MetricNames.java:
##########
@@ -339,6 +337,12 @@ public class MetricNames {
     public static final String WRITER_RECORDS_PER_BATCH = "recordsPerBatch";
     public static final String WRITER_SEND_LATENCY_MS = "sendLatencyMs";
 
+    // for record accumulator memory
+    public static final String WRITER_ACCUMULATOR_HEAP_MEMORY_USED = "accumulatorHeapMemoryUsed";
+    public static final String WRITER_ACCUMULATOR_ARROW_MEMORY_USED = "accumulatorArrowMemoryUsed";
+    public static final String WRITER_ACCUMULATOR_NATIVE_MEMORY_ALLOCATED =
+            "accumulatorNativeMemoryAllocated";

Review Comment:
   The existing writer metrics use explicit Bytes suffix (bufferTotalBytes, bufferAvailableBytes), and other metrics follow the same convention (bytesIn, rocksdbBytesReadTotal, replicationBytesInPerSecond, etc.). These three new metrics have no unit indicator.
   Suggest renaming to:
   ```
   accumulatorHeapMemoryUsedBytes
   accumulatorArrowMemoryUsedBytes
   accumulatorNativeMemoryAllocatedBytes
   ```



##########
fluss-common/src/main/java/org/apache/fluss/shaded/arrow/org/apache/arrow/memory/ChunkedAllocationManager.java:
##########
@@ -403,12 +420,31 @@ public synchronized void close() {
             closed = true;
             while (!freeChunks.isEmpty()) {
                 Chunk poll = freeChunks.poll();
-                poll.destroy();
-            }
-            if (activeChunk != null && activeChunk.subAllocCount.get() == 0) {
-                activeChunk.destroy();
+                destroyChunk(poll);
             }
+            Chunk chunk = activeChunk;
             activeChunk = null;
+            if (chunk != null && chunk.subAllocCount.get() == 0) {
+                // Invalidate a pending onChunkDrained callback that observed this zero count before
+                // close acquired the factory lock.
+                chunk.drainGeneration++;
+                destroyChunk(chunk);
+            }
+        }
+
+        /** Returns the native memory, in bytes, currently allocated by this factory. */
+        public long getNativeMemorySize() {
+            return nativeMemorySize.get();
+        }
+
+        private void destroyChunk(Chunk chunk) {
+            chunk.destroy();

Review Comment:
   nit: chunk.destroy() frees native memory via freeMemory(address), so reading chunk.capacity (a final long on the heap) after it is safe today. But if destroy() ever gains additional logic (e.g., nulling fields, callbacks), this ordering would silently break accounting.
   Suggest capturing before freeing:
   ```
   private void destroyChunk(Chunk chunk) {
       long cap = chunk.capacity;
       chunk.destroy();
       nativeMemorySize.addAndGet(-cap);
   }
   ```



-- 
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@fluss.apache.org

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


Re: [PR] [client] Replace Unsafe with Netty direct memory in ChunkedAllocationManager and expose metrics. [fluss]

Posted by "platinumhamburg (via GitHub)" <gi...@apache.org>.
platinumhamburg commented on code in PR #4448:
URL: https://github.com/apache/fluss/pull/4448#discussion_r4063731636


##########
fluss-common/src/main/java/org/apache/fluss/metrics/MetricNames.java:
##########
@@ -339,6 +337,14 @@ public class MetricNames {
     public static final String WRITER_RECORDS_PER_BATCH = "recordsPerBatch";
     public static final String WRITER_SEND_LATENCY_MS = "sendLatencyMs";
 
+    // for record accumulator memory
+    public static final String WRITER_ACCUMULATOR_HEAP_MEMORY_USED_BYTES =
+            "accumulatorHeapMemoryUsedBytes";
+    public static final String WRITER_ACCUMULATOR_ARROW_MEMORY_USED_BYTES =
+            "accumulatorArrowMemoryUsedBytes";
+    public static final String WRITER_ACCUMULATOR_DIRECT_MEMORY_USED_BYTES =

Review Comment:
   nit: This gauge includes the full capacity of the active chunk and all cached chunks in freeChunks. It can therefore remain non-zero after all ArrowBuf allocations have been released.
   Would accumulatorDirectMemoryAllocatedBytes or accumulatorDirectMemoryReservedBytes describe the accounting semantics more accurately than UsedBytes? This would also help clarify that it overlaps with accumulatorArrowMemoryUsedBytes and should not be added to it.



-- 
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@fluss.apache.org

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


Re: [PR] [client] Replace Unsafe with Netty direct memory in ChunkedAllocationManager and expose metrics. [fluss]

Posted by "loserwang1024 (via GitHub)" <gi...@apache.org>.
loserwang1024 merged PR #4448:
URL: https://github.com/apache/fluss/pull/4448


-- 
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@fluss.apache.org

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


Re: [PR] [client] Replace Unsafe with Netty direct memory in ChunkedAllocationManager and expose metrics. [fluss]

Posted by "loserwang1024 (via GitHub)" <gi...@apache.org>.
loserwang1024 commented on PR #4448:
URL: https://github.com/apache/fluss/pull/4448#issuecomment-5757666775

   @platinumhamburg thanks for your throughout review. 
   
   I have also replace Unsafe with Netty direct memory in ChunkedAllocationManager , would you like to help review it? @platinumhamburg @leonardBang @AndreaBozzo , CC


-- 
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@fluss.apache.org

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


Re: [PR] [client] Replace Unsafe with Netty direct memory in ChunkedAllocationManager and expose metrics. [fluss]

Posted by "loserwang1024 (via GitHub)" <gi...@apache.org>.
loserwang1024 commented on PR #4448:
URL: https://github.com/apache/fluss/pull/4448#issuecomment-5773356381

   not merge it(still in testing)


-- 
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@fluss.apache.org

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


Re: [PR] [client][metrics] Expose record accumulator memory usage metrics. [fluss]

Posted by "loserwang1024 (via GitHub)" <gi...@apache.org>.
loserwang1024 commented on PR #4448:
URL: https://github.com/apache/fluss/pull/4448#issuecomment-5754970336

   @platinumhamburg I'm thinking about switching `MemoryUtil.UNSAFE.allocateMemory` to `ByteBuffer.allocateDirect`. The main motivation is that Unsafe-allocated memory is invisible to the JVM, while direct ByteBuffers are tracked against the JVM's direct memory limit (e.g. -XX:MaxDirectMemorySize), which gives us better memory governance.


-- 
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@fluss.apache.org

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


Re: [PR] [client][metrics] Expose record accumulator memory usage metrics. [fluss]

Posted by "loserwang1024 (via GitHub)" <gi...@apache.org>.
loserwang1024 commented on PR #4448:
URL: https://github.com/apache/fluss/pull/4448#issuecomment-5749649267

   @platinumhamburg @naivedogger , Would you like to help review this PR?


-- 
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@fluss.apache.org

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