为什么二进制内存使用量会在rabbitmq上增长

时间:2017-06-18 10:27:07

标签: memory memory-management rabbitmq amqp

如何找到二进制内存使用量增长的原因(取决于连接数)

我使用了rabbitmqctl eval'[garbage_collect(P)|| P< - processes()]。' 但在统计数据

memory detail picture
binary detail picture

root@Broker1:~# /usr/sbin/rabbitmqctl status | grep binary    
  {binary,6709401976},   

root@Broker1:~# free -m   
           total       used       free     shared    buffers     cached
Mem:         16084       4147      11937         22        161       1550
-/+ buffers/cache:       2435      13649
Swap:         4183          0       4183
root@Broker2:~# /usr/sbin/rabbitmqctl status 


 Status of node rabbit@Broker2 ...
[{pid,515},
  {running_applications,
 [{rabbitmq_web_mqtt,"RabbitMQ MQTT-over-WebSockets adapter","3.6.9"},
  {rabbitmq_mqtt,"RabbitMQ MQTT Adapter","3.6.9"},
  {rabbitmq_web_stomp,"Rabbit WEB-STOMP - WebSockets to Stomp adapter",
      "3.6.9"},
  {rabbitmq_stomp,"RabbitMQ STOMP plugin","3.6.9"},
  {rabbitmq_management,"RabbitMQ Management Console","3.6.9"},
  {rabbitmq_web_dispatch,"RabbitMQ Web Dispatcher","3.6.9"},
  {rabbitmq_management_agent,"RabbitMQ Management Agent","3.6.9"},
  {rabbit,"RabbitMQ","3.6.9"},
  {os_mon,"CPO  CXC 138 46","2.3"},
  {cowboy,"Small, fast, modular HTTP server.","1.0.4"},
  {ranch,"Socket acceptor pool for TCP protocols.","1.3.0"},
  {ssl,"Erlang/OTP SSL application","5.3.6"},
  {public_key,"Public key infrastructure","0.22.1"},
  {cowlib,"Support library for manipulating Web protocols.","1.0.2"},
  {crypto,"CRYPTO","3.4.1"},
  {amqp_client,"RabbitMQ AMQP Client","3.6.9"},
  {rabbit_common,
      "Modules shared by rabbitmq-server and rabbitmq-erlang-client",
      "3.6.9"},
  {inets,"INETS  CXC 138 49","5.10.3"},
  {mnesia,"MNESIA  CXC 138 12","4.12.3"},
  {compiler,"ERTS  CXC 138 10","5.0.2"},
  {sockjs,"SockJS","0.3.4"},
  {xmerl,"XML parser","1.3.7"},
  {syntax_tools,"Syntax tools","1.6.16"},
  {asn1,"The Erlang ASN1 compiler version 3.0.2","3.0.2"},
  {sasl,"SASL  CXC 138 11","2.4.1"},
  {stdlib,"ERTS  CXC 138 10","2.2"},
  {kernel,"ERTS  CXC 138 10","3.0.3"}]},
 {os,{unix,linux}},
 {erlang_version,
 "Erlang/OTP 17 [erts-6.2] [source] [64-bit] [smp:10:10] [async-threads:160] [kernel-poll:true]\n"},
 {memory,
 [{total,3874499056},
  {connection_readers,598416},
  {connection_writers,139368},
  {connection_channels,774752},
  {connection_other,176069624},
  {queue_procs,36524016},
  {queue_slave_procs,0},
  {plugins,80184008},
  {other_proc,0},
  {mnesia,48042392},
  {metrics,7245632},
  {mgmt_db,74517952},
  {msg_index,1751384},
  {other_ets,14801208},
  {binary,3379246384},
  {code,28040419},
  {atom,1000601},
  {other_system,33438764}]},
 {alarms,[]},
 {listeners,
 [{clustering,2000,"::"},
  {amqp,5672,"::"},
  {http,15672,"::"},
  {stomp,61613,"::"},
  {'http/web-stomp',15674,"::"},
  {mqtt,1883,"::"},
  {'http/web-mqtt',15675,"::"}]},
 {vm_memory_high_watermark,{absolute,"12288MiB"}},
{vm_memory_limit,12884901888},
{disk_free_limit,50000000},
{disk_free,91027542016},
{file_descriptors,
 [{total_limit,65435},
  {total_used,9214},
  {sockets_limit,58889},
  {sockets_used,9002}]},
 {processes,[{limit,1048576},{used,42726}]},
 {run_queue,0},
 {uptime,82689},
 {kernel,{net_ticktime,60}}
]
             total       used       free     shared    buffers     cached
Mem:         16084       4517      11567         27        160       2487
-/+ buffers/cache:       1869      14215
Swap:         4189          0       4189

我的记忆是免费的!但是在内存增长之后,连接到服务器的速度非常慢!!

群集:rabbit @ Broker1(更改)

RabbitMQ 3.6.9,Erlang 17.3

rabbitmq.config

[
    {log_levels,       [{connection, none},{channel,none}]},
    {file_descriptors, [{total_limit, 65000}]},
    {kernel, [
            {log_levels,       [{connection, none},{channel,none}]},
            {inet_dist_listen_min, 2000},
            {inet_dist_listen_max, 65000}
    ]},
    {rabbit, [
            {loopback_users, []},
            {vm_memory_high_watermark, {absolute, "12288MiB"}},
            {vm_memory_high_watermark_paging_ratio, 0.60},
            {tcp_listeners,    [5672]},
            {log_levels,       [{connection, none},{channel,none}]},
            {heartbeat, 10000}
    ]},
    {rabbitmq_mqtt, [
            {log_levels,       [{connection, none},{channel,none}]},
            {default_user,     <<"guest">>},
            {default_pass,     <<"guest">>},
            {allow_anonymous,  false},
            {vhost,            <<"test">>},
            {exchange,         <<"amq.topic">>},
            {subscription_ttl, 180000},
            {prefetch,         10},
            {tcp_listeners,    [1883]},
            {tcp_listen_options, [
                    binary,
                    {packet,    raw},
                    {reuseaddr, false},
                    {backlog,   8192},
                    {nodelay,   true}
            ]}
    ]},
    {rabbitmq_stomp, [
            {default_vhost, <<"test">>},
            {exchange,         <<"amq.topic">>},
            {tcp_listen_options, [
                    {backlog,   128},
                    {nodelay,   true}
            ]}
    ]}
].

1 个答案:

答案 0 :(得分:0)

我相信您的实施不正确。我正在使用RabbitMQ在现场网站上进行实时通知,它没有任何问题。我有一个高达3500的并发客户端,但8GB RAM实例运行良好。

那你必须做什么?

您尚未指定用例。但是根据rabbitmq文档,只有当你有大量未传递的消息时,内存才会增长。许多未传递的消息可能会导致磁盘空间/ RAM空间,具体取决于客户端与您的连接方式。

如果每个用户有一个代理,那就非常昂贵。相反,如果您的用户将在多个端点(例如,电话和网络同时)接收相同的消息,则每个用户进行一次交换。在这种情况下,使用扇出交换并让用户订阅它。当交换中的消息达到零时,始终启用自动删除标志。使用非持久性交换;但要减少你的经纪人。

如果您确定一个用户只能在一台设备上连接而不是更多,那么您不需要进行扇出交换,而是为每个用户构建一个队列。仍然,启用自动删除标志。

通过交换或队列保持较少数量的经纪人和处理请求是有效的。

如果适合您的使用案例,可以使用的另一个选项是消息到期。我们假设您正在使用RabbitMQ向您的用户发送通知。但是,您可以将它们写入数据库并发出通知,您可以通过RMQ发送。如果用户不在线,可能大约10分钟或更长时间,到期是一个不错的选择。因为它是实时消息传递,而不是持久消息传递。他打算从数据库中读取它

注意:如果您解释用例,我会详细帮助您。

阅读本文以了解更多信息:https://www.rabbitmq.com/blog/2014/10/30/understanding-memory-use-with-rabbitmq-3-4/

如上所述,

  

所有二进制使用都是由队列中的消息引起的。

最好的方法是使用非持久性队列和自动过期消息!

  

请注意&#34;在记忆中&#34;和#34;持久&#34;消息不是反义词:   一个非持久性消息可以在内存压力下被分页出来   持久性消息也可以在内存中。

这解释了你的问题!