I'll try to provide as much details as I can. In addition to rabbitmq.config and sysctl customizations (above), here is the output of rabbitmqctl status:
[{pid,1698},
{running_applications,
[{rabbitmq_topic_authorization,"RabbitMQ topic-based authorization",[]},
{rabbitmq_web_stomp,"Rabbit WEB-STOMP - WebSockets to Stomp adapter",
"3.6.12"},
{rabbitmq_stomp,"RabbitMQ STOMP plugin","3.6.12"},
{rabbitmq_mqtt,"RabbitMQ MQTT Adapter","3.6.12"},
{rabbitmq_management,"RabbitMQ Management Console","3.6.12"},
{rabbitmq_management_agent,"RabbitMQ Management Agent","3.6.12"},
{rabbitmq_event_exchange,"Event Exchange Type","3.6.12"},
{rabbitmq_auth_backend_http,"RabbitMQ HTTP Authentication Backend",
"3.6.12+2.g430e0e3"},
{rabbitmq_web_dispatch,"RabbitMQ Web Dispatcher","3.6.12"},
{rabbit,"RabbitMQ","3.6.12"},
{rabbitmq_auth_backend_cache,"RabbitMQ Authentication Backend cache",[]},
{amqp_client,"RabbitMQ AMQP Client","3.6.12"},
{rabbit_common,
"Modules shared by rabbitmq-server and rabbitmq-erlang-client",
"3.6.12"},
{sockjs,"SockJS","0.3.4"},
{xmerl,"XML parser","1.3.14"},
{cowboy,"Small, fast, modular HTTP server.","1.0.4"},
{cowlib,"Support library for manipulating Web protocols.","1.0.2"},
{syntax_tools,"Syntax tools","2.1.1"},
{mnesia,"MNESIA CXC 138 12","4.14.3"},
{inets,"INETS CXC 138 49","6.3.9"},
{ranch,"Socket acceptor pool for TCP protocols.","1.3.0"},
{ssl,"Erlang/OTP SSL application","8.1.3"},
{os_mon,"CPO CXC 138 46","2.4.2"},
{public_key,"Public key infrastructure","1.4"},
{crypto,"CRYPTO","3.7.4"},
{compiler,"ERTS CXC 138 10","7.0.4"},
{asn1,"The Erlang ASN1 compiler version 4.0.4","4.0.4"},
{sasl,"SASL CXC 138 11","3.0.3"},
{stdlib,"ERTS CXC 138 10","3.3"},
{kernel,"ERTS CXC 138 10","5.2"}]},
{os,{unix,linux}},
{erlang_version,
"Erlang/OTP 19 [erts-8.3.5] [source] [64-bit] [smp:8:8] [async-threads:128] [hipe] [kernel-poll:true]\n"},
{memory,
[{connection_readers,0},
{connection_writers,0},
{connection_channels,0},
{connection_other,3376512},
{queue_procs,1812168},
{queue_slave_procs,11240},
{plugins,88326640},
{other_proc,238397456},
{metrics,285464},
{mgmt_db,18407600},
{mnesia,83720},
{other_ets,2667272},
{binary,3312136},
{msg_index,44176},
{code,28833745},
{atom,1139913},
{other_system,2645091526},
{total,3031789568}]},
{alarms,[]},
{listeners,
[{clustering,25672,"::"},
{'http/web-stomp',15674,"::"},
{amqp,5672,"::"},
{http,15672,"::"},
{mqtt,1883,"::"},
{stomp,61613,"::"}]},
{vm_memory_calculation_strategy,rss},
{vm_memory_high_watermark,0.8},
{vm_memory_limit,26991175270},
{disk_free_limit,13495587635},
{disk_free,200424062976},
{file_descriptors,
[{total_limit,999900},
{total_used,97},
{sockets_limit,899908},
{sockets_used,95}]},
{processes,[{limit,1048576},{used,690}]},
{run_queue,0},
{uptime,6886},
{kernel,{net_ticktime,120}}]
This is a 2 nodes cluster.
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Random;
import java.util.UUID;
import java.util.concurrent.CountDownLatch;
import org.apache.commons.lang.math.RandomUtils;
import org.eclipse.paho.client.mqttv3.MqttClient;
import org.eclipse.paho.client.mqttv3.MqttConnectOptions;
import org.eclipse.paho.client.mqttv3.MqttMessage;
import org.eclipse.paho.client.mqttv3.persist.MemoryPersistence;
public class MqttTest {
public static int NB_CLIENTS;
public static int NB_THREADS;
public static boolean SEND_MSG = true;
public static long MSG_TO_SEND_PER_CLI;
public static long PAUSE_BTW_SEND = 200;
public static byte[] MSG_CONTENT = "some data".getBytes();
public static boolean JOIN_BEFORE_CON = true, JOIN_BEFORE_DISCO = true;
public static CountDownLatch START_SIGNAL = new CountDownLatch(1),
STOP_SIGNAL = new CountDownLatch(NB_THREADS);
public static int SLEEP_BEFORE_DISCO = 1000000;
public static int MQTT_PING_INTERVAL = 10;
public static List<String> NODE_IPS = Arrays.asList("IP_NODE1", "IP_NODE2");
public static String RABBIT_USERNAME = "username";
public static String RABBIT_PASSWORD = "password";
static class Worker implements Runnable {
List<MqttClient> clients = new ArrayList<>();
MqttConnectOptions connOpts = new MqttConnectOptions();
public Worker() throws Exception {
connOpts.setUserName(RABBIT_USERNAME);
connOpts.setPassword(RABBIT_PASSWORD.toCharArray());
connOpts.setKeepAliveInterval(MQTT_PING_INTERVAL);
connOpts.setCleanSession(true);
for (int i = 0; i < (NB_CLIENTS / NB_THREADS); i++) {
MqttClient client = new MqttClient("tcp://" + getNodeIp() + ":1883",
UUID.randomUUID().toString().substring(0, 7), new MemoryPersistence());
clients.add(client);
}
}
@Override
public void run() {
try {
if (JOIN_BEFORE_CON) {
START_SIGNAL.await();
}
for (MqttClient client : clients) {
client.connect(connOpts);
client.subscribe("device/" + client.getClientId() + "/*");
}
if (SEND_MSG) {
for (int i = 0; i < MSG_TO_SEND_PER_CLI; i++) {
for (MqttClient client : clients) {
client.publish("device/" + client.getClientId() + "/fake",
new MqttMessage(MSG_CONTENT));
}
Thread.sleep(PAUSE_BTW_SEND * RandomUtils.nextInt(5));
}
}
Thread.sleep(SLEEP_BEFORE_DISCO);
STOP_SIGNAL.countDown();
} catch (Exception e) {
e.printStackTrace();
}
}
}
public static void main(String[] args) throws Exception {
NB_CLIENTS = Integer.parseInt(args[0]);
NB_THREADS = Integer.parseInt(args[1]);
MSG_TO_SEND_PER_CLI = Integer.parseInt(args[2]);
for (int i = 0; i < NB_THREADS; i++) {
new Thread(new Worker()).start();
}
START_SIGNAL.countDown();
if (JOIN_BEFORE_DISCO)
STOP_SIGNAL.await();
}
private static final Random random = new Random();
private static String getNodeIp() {
return NODE_IPS.get(random.nextInt(NODE_IPS.size()));
}
}
You have to change NODE_IPS, RABBIT_USERNAME, RABBIT_PASSWORD.
java -Xmx16G -Xss256k -cp . MqttClientsThroughput <NB_CLIENTS> <NB_WORKERS> <MESSAGES_PER_CLIENT>
NB_CLIENTS = 10000 is enough. Once this number is reached, just Ctrl-C. In RabbitMQ Management UI connections count drops to 0 almost instantly, whereas queues get evicted little by little (~300 every 5s). Until it reaches 0, no new connection is allowed (times out).