flume-ng性能优化与架构设计

来源:互联网 发布:淘宝涛哥电玩店 编辑:程序博客网 时间:2024/04/28 03:23

如图1所示,一个flume-ng agent主要包括source,channel和sink三部分,三部分运行在java JVM中,JVM一般运行在linux'操作系统上,因此,这些因素都可能影响最终的性能。flume-ng性能优化与架构设计,简单来讲,也主要包括以上部分。


1, 主键的参数设计
1.1 source的配置
有时候不需要每台主机均安装flume agent,可以和sshpass等命令结合使用,灵活收集日志.
1.2 channel的配置
可选的一般为memory channel和file channel,
内存足够的话,一般建议选择时效性更好的memory channel,
[plain] view plaincopy在CODE上查看代码片派生到我的代码片
  1. agent.channels.memory_chan_1.type = memory  
  2. agent.channels.memory_chan_1.keep-alive = 30  
  3. agent.channels.memory_chan_1.transactionCapacity = 20000  
  4. agent.channels.memory_chan_1.byteCapacityBufferPercentage = 40  
  5.   
  6. agent.channels.memory_chan_1.byteCapacity = 50000000  
  7. agent.channels.memory_chan_1.capacity = 500000  
相关参数说明
capacity: Maximum # of events that can be in the channel
transactionCapacity: Maximum # of events in one txn.
keepAlive: how long to wait to put/take an event
 channel性能的关键是设置合理的以上三个参数
1.3 sink的配置
已hdfs sink为例,可以使用压缩节省空间和网络流量,但会增加cpu消耗.
[plain] view plaincopy在CODE上查看代码片派生到我的代码片
  1. # Each sink's type must be defined  
  2. agent.sinks.hdfsSink_1.type = hdfs  
  3. agent.sinks.hdfsSink_1.channel = memory_chan_1  
  4. agent.sinks.hdfsSink_1.hdfs.path = /logdata/%Y%m%d/%{hostname}/%{filename}%{CRMLOG}  
  5. agent.sinks.hdfsSink_1.hdfs.filePrefix = %{filename}%{CRMLOG}  
  6. agent.sinks.hdfsSink_1.hdfs.rollInterval = 3600  
  7. agent.sinks.hdfsSink_1.hdfs.rollSize = 40000000  
  8. agent.sinks.hdfsSink_1.hdfs.rollCount = 0  
  9. agent.sinks.hdfsSink_1.hdfs.writeFormat = Writable  
  10. agent.sinks.hdfsSink_1.hdfs.fileType = CompressedStream  
  11. agent.sinks.hdfsSink_1.hdfs.batchSize = 10000  
  12. agent.sinks.hdfsSink_1.hdfs.serializer = avro_event  
  13. agent.sinks.hdfsSink_1.hdfs.threadsPoolSize = 100  
  14. agent.sinks.hdfsSink_1.hdfs.codeC = gzip  

影响sink的注意事项

Batch Size:越大性能越好,但太大影响时效性.一般可选为100,1000,10000,batch size最好源数据端大小相同
agent.sinks.flowSink-3-5.batch-size = 10000
agent.sinks.hdfsSink_1.hdfs.batchSize = 10000

sink是单线程处理的,所有一个channel要配置多个写入sink,来提高性能
2, JAVA内存的设计
主要通过修改 conf/flume-env.sh文件实现
主要设计Xmx和Xms两个参数,可以根据OS内存的大小进行合理设置,一般一个flume agent 1g左右大小即可
-Xms<size>        set initial Java heap size.........................
-Xmx<size>        set maximum Java heap size.........................

3,OS的内核参数调整
    如果单台服务器启动的flume agent过多的话,默认的内核参数设置偏小,需要调整,   调整方法基本和安装oracle数据库等类似,相关参数可以相应设置的大一点
  系统的参数限制,设置样例为
[plain] view plaincopy在CODE上查看代码片派生到我的代码片
  1. cat /etc/sysctl.conf      
  2. kernel.shmall = 33554432  
  3. kernel.shmmax = 137438953472  
  4. kernel.shmmni = 4096  
  5. kernel.sem = 250 32000 100 128  
  6. fs.file-max = 6815744  
  7. fs.aio-max-nr = 1048576  
  8. net.ipv4.ip_local_port_range = 9000 65500  
  9. net.core.rmem_default = 262144  
  10. net.core.rmem_max = 4194304  
  11. net.core.wmem_default = 262144  
  12.   
  13. net.core.wmem_max = 1048576  
 用户级别的参数设定
[plain] view plaincopy在CODE上查看代码片派生到我的代码片
  1.  vi /etc/security/limits.conf  
  2.   
  3. # End of file  
  4. hadoop             soft    nproc           32047  
  5. hadoop             hard    nproc           36384  
  6. hadoop             soft    nofile          31024  
  7. hadoop             hard    nofile          65536  

4,网络配置
flume日志和hadoop集群都是通过网络进行日志传送,所以网络不要成为性能瓶颈
5,架构设计,尽可能使用分布式和高可用的架构(重要)
建议使用loadbalnce+failover,实现了架构的可扩展性和高可用性,一台物理服务器上agent的数量不要超过core的数量
[plain] view plaincopy在CODE上查看代码片派生到我的代码片
  1. agent.sinks = flowSink-3-1 flowSink-3-2 flowSink-3-3 flowSink-3-4 flowSink-3-5  
  2. agent.sinkgroups = g1    
  3. agent.sinkgroups.g1.sinks = flowSink-3-1 flowSink-3-2 flowSink-3-3 flowSink-3-4 flowSink-3-5    
  4. agent.sinkgroups.g1.processor.type = load_balance    
  5. agent.sinkgroups.g1.processor.selector = round_robin    
  6. agent.sinkgroups.g1.processor.backoff = true  
  7. ...  
  8. agent.sinks.flowSink-3-1.type = avro  
  9. agent.sinks.flowSink-3-1.channel = memory_chan_1  
  10. agent.sinks.flowSink-3-1.hostname = 127.0.0.1  
  11. agent.sinks.flowSink-3-1.port = 41451  
  12. agent.sinks.flowSink-3-1.batch-size = 1000  
一个高可用,可扩展的架构示意图如下




参考文档

Building a Data Collection System with Apache Flume

http://flume.apache.org/FlumeUserGuide.html



转自:http://blog.csdn.net/hijk139/article/details/22861667

0 0
原创粉丝点击