Search code examples
hadoophdfsheap-memoryflumenetcat

Apache Flume: cannot commit transaction. Heap space limit reached


I am trying to stream some data into HDFS with Flume, with a single agent configured to have a netcat source, a memory channel, and an HDFS sink.

The configuration is the following one:

a1.sources = src1
a1.channels = ch1
a1.sinks = snk1

# SOURCES CONFIGURATION
a1.sources.src1.type = netcat
a1.sources.src1.bind = 0.0.0.0
a1.sources.src1.port = 99999
a1.sources.src1.ack-every-event = false

# SOURCE -> CHANNEL
a1.sources.src1.channels = ch1

# SINKS' CONFIGURATION
a1.sinks.snk1.type = hdfs
a1.sinks.snk1.hdfs.path = /somepath
a1.sinks.snk1.hdfs.writeFormat = Text
a1.sinks.snk1.hdfs.fileType = DataStream
a1.sinks.snk1.hdfs.inUseSuffix = .tmp
a1.sinks.snk1.hdfs.filePrefix = prefix_file
a1.sinks.snk1.hdfs.batchSize = 75000
a1.sinks.snk1.hdfs.rollInterval = 120
a1.sinks.snk1.hdfs.rollCount = 0
a1.sinks.snk1.hdfs.idleTimeout = 0
#128MB for each file maximum = 128 * 1024 (MB) * 1024 (KB) = ...
a1.sinks.snk1.hdfs.rollSize = 134217728

a1.sinks.snk1.hdfs.threadsPoolSize = 25

# SINK <- CHANNEL
a1.sinks.snk1.channel = ch1

# CHANNELS' CONFIGURATION
a1.channels.ch1.type = memory
a1.channels.ch1.capacity = 5000000
a1.channels.ch1.transactionCapacity = 100000
#412MB of byte capacity = 412 * 1024 * 1024 byte
#a1.channels.ch1.byteCapacity = 432013312

However, if I send messages above a certain bandwidth I get the following exception:

2014-11-21 05:48:07,035 (netcat-handler-0) [WARN - org.apache.flume.source.NetcatSource$NetcatSocketHandler.processEvents(NetcatSource.java:407)] Error processing event. Exception follows.
org.apache.flume.ChannelException: Unable to put event on required channel: org.apache.flume.channel.MemoryChannel{name: ch1}
        at org.apache.flume.channel.ChannelProcessor.processEvent(ChannelProcessor.java:275)
        at org.apache.flume.source.NetcatSource$NetcatSocketHandler.processEvents(NetcatSource.java:394)
        at org.apache.flume.source.NetcatSource$NetcatSocketHandler.run(NetcatSource.java:321)
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
        at java.util.concurrent.FutureTask.run(FutureTask.java:262)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
        at java.lang.Thread.run(Thread.java:745)
Caused by: org.apache.flume.ChannelException: Cannot commit transaction. Heap space limit of 3456106reached. Please increase heap space allocated to the channel as the sinks may not be keeping up with the sources
        at org.apache.flume.channel.MemoryChannel$MemoryTransaction.doCommit(MemoryChannel.java:123)
        at org.apache.flume.channel.BasicTransactionSemantics.commit(BasicTransactionSemantics.java:151)
        at org.apache.flume.channel.ChannelProcessor.processEvent(ChannelProcessor.java:267)
        ... 7 more

I don't get where I could change the value of heap space, in my conf/flume-env.sh I have:

JAVA_OPTS="-Xms256m -Xmx512m -Dcom.sun.management.jmxremote"

The size of the heap space in the exception should be indicated in byte, which means I have a heap space of 3,3MB which is veeery low, but I don't understand where that value is coming from...! How could I fix this? Thank you very much in advance!


Solution

  • You have a few nobs available to turn to get this working appropriately:

    1. Increase byteCapacity: a1.channels.ch1.byteCapacity = 6912212.
    2. Increase memory as suggested in the above comment (JAVA_OPTS="-Xms512m -Xmx1024m -Dcom.sun.management.jmxremote") is probably the best option. The reason being that the default byteCapacity is 80% of the processes max memory, which is already consuming a lot process memory.
    3. Shrink byteCapacityBufferPercentage which leaves less room for headers.