[英]Low throughput with hazelcast queue as soon as multi-node cluster?
我使用下面的測試來衡量我的吞吐量時間。 當我運行本地one- node集群時,吞吐量時間約為90k消息/秒。 一旦我向群集添加另一個本地節點,吞吐量就會下降到~5k消息/秒。 我是否會錯過任何重要的配置? 我配置了hazelcasts以跳過跨節點的數據復制,因此速度應該相同,無論節點數量多少,對吧?
我使用Hazelcast 3.11和以下配置:
<?xml version="1.0" encoding="UTF-8"?>
<hazelcast xsi:schemaLocation=
"http://www.hazelcast.com/schema/config hazelcast-config-3.7.xsd"
xmlns="http://www.hazelcast.com/schema/config"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<network>
<port auto-increment="true" port-count="20">5701</port>
<join>
<multicast enabled="false">
</multicast>
<tcp-ip enabled="true">
<member>localhost</member>
</tcp-ip>
</join>
</network>
<queue name="test">
<statistics-enabled>false</statistics-enabled>
<max-size>0</max-size>
<backup-count>0</backup-count>
<async-backup-count>0</async-backup-count>
<empty-queue-ttl>-1</empty-queue-ttl>
</queue>
</hazelcast>
吞吐量測試類:
package de.wipk.application.imdg;
import com.hazelcast.core.Hazelcast;
import com.hazelcast.core.HazelcastInstance;
import com.hazelcast.core.IQueue;
public class HCTest {
private static final int TOTAL = 1000000;
private static final int LAP = 100000;
public static void main(String[] args) throws InterruptedException {
final HazelcastInstance hz = Hazelcast.newHazelcastInstance();
final IQueue<Object> queue = hz.getQueue("test");
final long start = System.currentTimeMillis();
long lastLap = start;
Thread t = new Thread() {
long lastLap = start;
@Override
public void run() {
System.out.println((System.currentTimeMillis() - lastLap) + " Start receiving msgs");
for (int i = 1; i < TOTAL + 1; ++i) {
try {
Object msg = queue.take();
if (i % LAP == 0) {
final long lapTime = System.currentTimeMillis() - lastLap;
System.out.printf("<- messages %d/%d = %dms (%f msg/sec)\n", i, TOTAL, lapTime, ((float) LAP * 1000 / lapTime));
lastLap = System.currentTimeMillis();
}
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
};
t.start();
System.out.println((System.currentTimeMillis() - lastLap) + " Start sending msgs");
for (int i = 1; i < TOTAL + 1; ++i) {
queue.offer(i);
if (i % LAP == 0) {
final long lapTime = System.currentTimeMillis() - lastLap;
System.out.printf("-> messages %d/%d = %dms (%f msg/sec)\n", i, TOTAL, lapTime, ((float) LAP * 1000 / lapTime));
lastLap = System.currentTimeMillis();
}
}
System.out.println((System.currentTimeMillis() - start) + " Finished sending msgs");
t.join();
System.out.println((System.currentTimeMillis() - start) + " Test finished");
}
}
使用單節點集群,此行
final IQueue<Object> queue = hz.getQueue("test");
獲取對當前實例中隊列的引用,本質上是本地引用。
添加更多實例時,隊列本身可能會遷移到另一個實例托管,因此現在引用的是遠程隊列。
您可以通過多種方式驗證這一點。 可能最簡單的方法是延長測試時間,讓第二個節點加入中途,看看性能是否會發生變化。 您顯然只希望第一個進程執行offer()
/ take()
操作。
如果需要,請添加此項
System.out.println(hz.getPartitionService().getPartition("test").getOwner());
在其他成員加入群集時查找隊列所在的位置。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.