tsreaper commented on code in PR #1266:
URL: https://github.com/apache/incubator-paimon/pull/1266#discussion_r1213904637
##########
docs/content/engines/flink.md:
##########
@@ -210,3 +210,31 @@ All Flink data types are supported, except that
* `MULTISET` is not supported.
* `MAP` is not supported as primary keys.
+
+## Use Flink Managed Memory
+Paimon tasks can create memory pools based on executor memory which will be
managed by Flink executor, such as managed memory in Flink task manager. It
will improve the stability and performance of sinks by managing writer buffers
for multiple tasks through executor.
+
+The following properties can be set if using Flink managed memory:
+
+| Option | Default | Description
|
+|------------|----------|---------------------------------------------------------------------------------------------------------------------------------------------------------------|
+| sink.use-managed-memory-allocator | false | If true, flink sink will use
managed memory for merge tree; otherwise, it will create an independent memory
allocator, which means each task allocates and manages its own memory pool
(heap memory), if there are too many tasks in one Executor, it may cause
performance issues and even OOM. |
+| sink.managed.writer-buffer-memory | 256M | Weight of writer buffer in
managed memory, Flink will compute the memory size, for writer according to the
weight, the actual memory used depends on the running environment. For more
information, please refer to the [Use Allocator In Flink](#flinkallocator) |
+
+**Use In SQL**
+Users can set memory weight in SQL for Flink Managed Memory, then Flink sink
operator will get the memory pool size and create allocator for Paimon writer.
+
+```sql
+INSERT INTO paimon_table /*+
OPTIONS('sink.use-managed-memory-allocator'='true',
'sink.managed.writer-buffer-memory'='256M') */
+SELECT * FROM ....;
+```
+
+<span id="flinkallocator">**Use Allocator In Flink**</span>
+
+The process of using Managed Memory Allocator in Flink is divided into two
parts: compilation and runtime.
+
+In compilation, Paimon creates sink operator in `FlinkSink`. Paimon can get
`Transformation` from the sink operator, declare managed memory by
`Transformation.declareManagedMemoryUseCaseAtOperatorScope(OPERATOR, weight of
buffer)` according to options `sink.use-menaged-memory-allocator` and
`sink.managed.writer-buffer-memory` . We can find a description of this method
(`Transformation.declareManagedMemoryUseCaseAtOperatorScope(OPERATOR, weight of
buffer)` ) from the
[Javadoc](https://nightlies.apache.org/flink/flink-docs-release-1.17/api/java/org/apache/flink/api/dag/Transformation.html#declareManagedMemoryUseCaseAtOperatorScope-org.apache.flink.core.memory.ManagedMemoryUseCase-int-)
;
+
+**note:** It should be noted that when the first parameter of the method is
[`ManagedMemoryUseCase.OPERATOR`](https://nightlies.apache.org/flink/flink-docs-release-1.17/api/java/org/apache/flink/core/memory/ManagedMemoryUseCase.html#OPERATOR),
the second parameter are defined as mebibyte values.
+
+In runtime, Paimon sink operator calculates writer buffer size based on
`StreamConfig` and `MemoryManager` in `AbstractStoreWriteOperator.setup` , then
creates `FlinkMemorySegmentAllocator` and `MemorySegmentPool` . Finally Paimon
writer writes data to the memory pool and flush data to file system.
Review Comment:
I can't quite get what you're trying to explain. As a user I have no
interest in the implementation details. My main concern is that: is the memory
size defined in `sink.managed.writer-buffer-memory` equal to the exact memory
allocated to write buffer in runtime? If not, how can I adjust this value to
get my desired buffer size?
--
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]