![](/img/trans.png)
[英]mosquitto (mqtt broker) is refusing connections over websockets
[英]Scaling Mqtt connections to mosquitto broker
我正在嘗試建立到mqtt代理的多個(100k)mqtt連接,但是使用paho java客戶端不能超過5000。
我從另一個帖子中獲得了很好的指針,但是當我越過5000個線程限制時遇到了錯誤。 錯誤:java.lang.OutOfMemoryError:無法創建新的本機線程
我在雲中有一個16gb RAM / 16VCPU ubuntu實例,因此資源在這里看起來不是問題。
我當前的ulimit設置為以下。
ulimit -a
core file size (blocks, -c) 0
data seg size (kbytes, -d) unlimited
scheduling priority (-e) 0
file size (blocks, -f) unlimited
pending signals (-i) 128311
max locked memory (kbytes, -l) 64
max memory size (kbytes, -m) unlimited
open files (-n) 30000000
pipe size (512 bytes, -p) 8
POSIX message queues (bytes, -q) 819200
real-time priority (-r) 0
stack size (kbytes, -s) 8192
cpu time (seconds, -t) unlimited
max user processes (-u) 200000
virtual memory (kbytes, -v) unlimited
file locks (-x) unlimited
此外,該帖子還討論了添加21個虛擬地址的問題。 在此雲實例上,我將eth0.cfg設置為:
----------------------
# The primary network interface
auto eth0
iface eth0 inet dhcp
---------------------------
如何在此處添加虛擬IP地址?
這里的任何指針都會有所幫助。
謝謝。
編輯:這是我的線程類代碼-公共類SendMessage擴展了Thread {public String clientId; public String topicId; 公共字符串用戶名; 公共字符串密碼; 公共字符串有效負載類型;
SendMessage(String topicId,String clientId,String username,String password,String payloadType) {
this.topicId = topicId;
this.password = password;
this.username = username;
this.clientId = clientId;
this.payloadType = payloadType;
}
SendMessage(String topicId) {
this.topicId = topicId;
}
public void run() {
// Perform the requested action
try {
ArrayList<MqttClient> sampleClient = new ArrayList<MqttClient>();
MqttConnectOptions connOpts = new MqttConnectOptions();
connOpts.setCleanSession(true);
connOpts.setPassword(password.toCharArray());
connOpts.setUserName(username);
for (int i = 0; i < connectionCountPerThread ; i++) {
MqttClient newClient = new MqttClient("tcp://" + url, clientId + "_" +i);
sampleClient.add(newClient);
newClient.connect(connOpts);
}
MqttMessage message1;
int qos = 0;
MockObservations mo = new MockObservations();
for (int i = 0 ; i < msgCount ; i++) {
for (int conn = 0; conn < connectionCountPerThread ; conn++) {
message1 = new MqttMessage(mo.getSensorReading(payloadType).getBytes());
message1.setQos(qos);
sampleClient.get(conn).publish(topicId, message1);
}
}
for (int conn = 0; conn < connectionCountPerThread ; conn++) {
sampleClient.get(conn).disconnect();
}
} catch(MqttException me) {
System.out.println("reason "+me.getReasonCode());
System.out.println("msg "+me.getMessage());
System.out.println("loc "+me.getLocalizedMessage());
System.out.println("cause "+me.getCause());
System.out.println("excep "+me);
me.printStackTrace();
}
}
}
您創建了太多線程。 據我所知,Paho每個單獨的連接使用2個線程。 使用“每個連接線程數”模型不會太過分。 我相信自己創建這樣的負載測試工具的唯一方法是使用Java的NIO方法。
要獲得更高的連接(並且延遲很長),可以嘗試增加JVM堆大小。
這可能對您有幫助: https : //en.wikipedia.org/wiki/C10k_problem
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.