MQ内存消耗与积压分析-LMLPHP

MQ内存消耗与积压分析-LMLPHP

[root@iZ23nn1p4mjZ logs]# rabbitmqctl status
Status of node rabbit@iZ23nn1p4mjZ ...
[{pid,15425},
{running_applications,
[{rabbitmq_management,"RabbitMQ Management Console","3.5.6"},
{rabbitmq_management_agent,"RabbitMQ Management Agent","3.5.6"},
{rabbit,"RabbitMQ","3.5.6"},
{amqp_client,"RabbitMQ AMQP Client","3.5.6"},
{rabbitmq_web_dispatch,"RabbitMQ Web Dispatcher","3.5.6"},
{webmachine,"webmachine","1.10.3-rmq3.5.6-gite9359c7"},
{mochiweb,"MochiMedia Web Server","2.7.0-rmq3.5.6-git680dba8"},
{xmerl,"XML parser","1.3.9"},
{os_mon,"CPO CXC 138 46","2.4"},
{mnesia,"MNESIA CXC 138 12","4.13.2"},
{inets,"INETS CXC 138 49","6.1"},
{sasl,"SASL CXC 138 11","2.6.1"},
{stdlib,"ERTS CXC 138 10","2.7"},
{kernel,"ERTS CXC 138 10","4.1.1"}]},
{os,{unix,linux}},
{erlang_version,
"Erlang/OTP 18 [erts-7.2] [source-e6dd627] [64-bit] [smp:4:4] [async-threads:64] [hipe] [kernel-poll:true]\n"},
{memory,
[{total,658753984},
{connection_readers,59653208},
{connection_writers,5883032},
{connection_channels,16427472},
{connection_other,77342544},
{queue_procs,34311280},
{queue_slave_procs,0},
{plugins,1674624},
{other_proc,15139104},
{mnesia,2057392},
{mgmt_db,36575208},
{msg_index,5701536},
{other_ets,4435216},
{binary,359802776},
{code,20170175},
{atom,711569},
{other_system,18868848}]},
{alarms,[]},
{listeners,[{clustering,25672,"::"},{amqp,5672,"0.0.0.0"}]},
{vm_memory_high_watermark,0.4},
{vm_memory_limit,3301947801},
{disk_free_limit,50000000},
{disk_free,3977351168},
{file_descriptors,
[{total_limit,65435},
{total_used,2085},
{sockets_limit,58889},
{sockets_used,2082}]},
{processes,[{limit,1048576},{used,24844}]},
{run_queue,1},
{uptime,72713}]

可以发现,binary部分占用的内存特别多,这一部分主要是connection的消耗+一些额外小部分的元数据。每个连接占用的内存可通过/proc/sys/net/ipv4/tcp_rmem得到,例如:

[root@osm ~]# cat /proc/sys/net/ipv4/tcp_rmem
4096873804194304

也可以通过rabbitmq.config配置的下列部分进行覆盖:

[{rabbit, [{tcp_listen_options, [binary
                                  {sndbuf,        1024}, 
                                  {recbuf,        1024}, 
                                  {buffer,        1024}, 
                                  {packet,        raw}, 
                                  {reuseaddr,     true}, 
                                  {backlog,       128}, 
                                  {nodelay,       true}, 
                                  {linger,        {true, 0}}, 
                                  {exit_on_close, false}]}]}]

=ERROR REPORT==== 8-Dec-2016::08:49:28 ===
closing AMQP connection <0.5859.3> (127.0.0.1:49265 -> 127.0.0.1:5672):
Missed heartbeats from client, timeout: 10s

=ERROR REPORT==== 8-Dec-2016::08:49:28 ===
closing AMQP connection <0.30760.2> (127.0.0.1:45547 -> 127.0.0.1:5672):
Missed heartbeats from client, timeout: 10s

=ERROR REPORT==== 8-Dec-2016::08:49:29 ===
closing AMQP connection <0.10927.3> (127.0.0.1:50608 -> 127.0.0.1:5672):
{handshake_timeout,frame_header}

=ERROR REPORT==== 8-Dec-2016::08:49:29 ===
closing AMQP connection <0.11271.3> (127.0.0.1:50720 -> 127.0.0.1:5672):
{handshake_timeout,frame_header}

=WARNING REPORT==== 8-Dec-2016::08:49:29 ===
closing AMQP connection <0.10548.3> (101.69.255.190:38261 -> 120.27.140.42:5672):
connection_closed_abruptly

=WARNING REPORT==== 8-Dec-2016::08:49:29 ===
closing AMQP connection <0.10559.3> (101.69.255.190:38262 -> 120.27.140.42:5672):
connection_closed_abruptly

=WARNING REPORT==== 8-Dec-2016::08:49:29 ===
closing AMQP connection <0.10581.3> (101.69.255.190:38264 -> 120.27.140.42cn:5672):
connection_closed_abruptly

https://www.rabbitmq.com/blog/2014/10/30/understanding-memory-use-with-rabbitmq-3-4/

05-14 00:47