Memory required by each Source or Sink
The heap memory used by a single event is dominated by the data in the event body with some incremental usage by any headers added. So in general, a source or a sink will allocate roughly the size of the event body + maybe 100 bytes of headers (this is affected by headers added by the txn agent). To get the total memory used by a single batch, multiply your average (or 90th percentile) event
size (plus some additional buffer) by the maximum batch size. This will give you the memory needed by a single batch.
The memory required for each Sink is the memory needed for a single batch and the memory required for each Source is the memory needed for a single batch, multiplied by the number of clients simultaneously connected to the Source. Keep this in mind, and plan your event delivery according to your expected throughput.
Memory required by each File Channel
Under normal operation, each File Channel uses some heap memory and some direct memory. Give each File channel roughly 30MB of heap memory for basic operational overhead. Each File channel also needs an amount of direct memory roughly equal to 1MB + (capacity of channel * 8) bytes because Flume is storing the updates in a hashmap.
For fast replay without a checkpoint, the file channel can use up to (channel capacity * 32) bytes of heap memory. The amount of memory actually used depends on the number of events present in the log files being replayed. So, if the file channel holds 100 million events, the replay will require about 3.2 GB of heap memory. In order to enable fast checkpoint-less replay, you must set the configuration option use-fast-replay to true, i.e.:
agent.channels.ch-0.use-fast-replay = true
If that option is not explicitly enabled, then replay without a checkpoint will be slower, but it will use significantly less memory: on the order of normal operation of the file channel as specified above.
Memory required by the Flume core itself
Add to the total heap size roughly 50MB for the Flume core. Finally, adding a healthy buffer to calculated estimates is recommended. JVM memory usage in production can be monitored & graphed using JMX, to get a better understanding of real-world memory allocation behavior given a particular workload. We wrote a article about JMX monitoring in past.
Example memory settings
As you know, Flume reads out the environment variables over their flume-env.sh, which is disabled per default (named as $FLUME/conf/flume-env.sh.template). Simply rename them into flume-env.sh.template and tweak the settings according your requirements you have calculated. Also it is always a good idea to initialize the needed memory on startup, instead to add them later to avoid Juliet pauses when fresh memory will be allocated.
A example for a larger memory tweaking with GC tuning could look like
# sets minimum memory to 2GB, max to 16GB, max direct memory to 256MB
# also uses the parallel new and concurrent garbage collectors to reduce the likelihood of long stop-the-world GC pauses
JAVA_OPTS="-Xms2000m -Xmx16000m -Xss128k -XX:MaxDirectMemorySize=256m