译自:Scaling a flume agent to handle 120K events_sec – Data Collective – Medium
Apache Flume 是一种用来收集大量数据(如日志)的分布式服务。Flume agent 有三个组成部分:source, channel and sink.。简而言之,数据通过Channel从Source到Sink。Source生产数据,Channel缓冲数据并且Sink将数据写入存储。我们可以通过以下方法增加Flume Agent的吞吐量。
Batching
我们可以调整Source和Sink的批处理大小(batchSize)和批处理等待耗时(batchDurationMillis )来增加吞吐量。这些属性值依赖于Source、Sink的类型以及我们可以提供的接收延迟。通过调整批量大小和吞吐量,我们能够获取15K Events/秒。
<agent_name>.sinks.<sink_name>.batchSize = 10000
<agent_name>.sinks.<sink_name>.batchDurationMillis = 10000
Sink Parallelization
在我们的例子中,由于处理速度慢Sinik变成了管道的瓶颈。我们试图通过以下的方法增加Sink的吞吐量。
Sink Group
Sink Group 允许我们将多个Sinks组合为一个。我们配置Sink Group,将带有负载均衡的Sink处理器将Events数据写入多个Sink,但整个过程保持不变。检查论坛后我们发现,在Sink Group中只有一个Sink处于活动状态,因此性能和单个Sink一样。
Multiple Sinks
不是将Sink Group附加到Channel上,而是将Sinks直接和Channel联系在一起。吞吐量应该增加,因为每一个Sink都在自己的线程上运行,但是我们看不到任何明显的改进。经过各种测试后,我们发现现在Channel变成了瓶颈,因为多个Sinks正在竞争单个Channel的资源。
Multiple Sinks—Multiple Channels
我们配置了多个Channels并且每个Channel都连接了一个Sink。Channel选择器(channe lselector)用于将events复制到所有的channels。
吞吐量随每个Channel-Sink对线性增加。我们必须找到一种方法将events分发到多个Channels。
Multiplexing Channel Selector
Flume本身支持两个Channel Selectors(选择器):复制(replicating)和多路复用(multiplexing)。在这种情况下,不能使用复制(replicating),因为它会将相同的event复制到所有的Channels。使用多路复用(multiplexing),我们可以根据特定标头的值将events映射到特定的Channel。这种方法需要均匀的分布密钥,并且Channel的数量限制于密钥的基数。很难为每一个事件流(event stream)找到这种类型的密钥。
Round-Robin Channel Selector
为了克服多路复用Channel选择器的问题,我们开发了轮询 channel 选择器(Round-Robin channel selector),以轮询的方式它将events分发到所有的Channel。
Build Round-Robin Channel Selector
git clone https://github.com/saravsars/flume-round- robin-channel-selector.git
cd flume-round-robin-channel-selector mvn clean package
cd target
cp flume-round-robin-channel-selector-1.0.jar FLUME_CLASSPATH/
Configure Round-Robin Channel Selector
agent.sources = source1
agent.sinks = sink1 sink2
agent.channels = channel1 channel2
agent.sources.source1.channels = channel1 channel2
agent.sinks.sink1.channel = channel1 agent.sinks.sink2.channel = channel2
agent.sources.source1.selector.type = com.sars.flume.RoundRobinChannelSelector
启用批处理和轮询Channel选择器(Round-Robin channel selector)后,我们能够在八核机器中实现120K events/秒