Merge pull request #255 from AndreasMager/subscription-store-performance-test
Great thanks a lot
This commit is contained in:
@@ -171,6 +171,13 @@
|
||||
<manifestFile>${project.build.outputDirectory}/META-INF/MANIFEST.MF</manifestFile>
|
||||
</archive>
|
||||
</configuration>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
<goal>test-jar</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.felix</groupId>
|
||||
|
||||
@@ -25,6 +25,19 @@
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>${project.groupId}</groupId>
|
||||
<artifactId>moquette-broker</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>${project.groupId}</groupId>
|
||||
<artifactId>moquette-broker</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<type>test-jar</type>
|
||||
</dependency>
|
||||
|
||||
<!--<dependency>-->
|
||||
<!--<groupId>io.netty</groupId>-->
|
||||
<!--<artifactId>netty-common</artifactId>-->
|
||||
|
||||
@@ -0,0 +1,84 @@
|
||||
|
||||
package io.moquette.spi.impl.subscriptions;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.lang.management.ManagementFactory;
|
||||
import java.lang.management.ThreadMXBean;
|
||||
import io.moquette.parser.proto.messages.AbstractMessage;
|
||||
import io.moquette.spi.ISessionsStore;
|
||||
import io.moquette.spi.impl.MemoryStorageService;
|
||||
|
||||
public class PerformanceTest {
|
||||
|
||||
// Set CPU governor and max frequency to lowest value for this test
|
||||
/* debian:
|
||||
cpufreq-set -g performance -u 800MHz -c 0
|
||||
cpufreq-set -g performance -u 800MHz -c 1
|
||||
cpufreq-set -g performance -u 800MHz -c 2
|
||||
cpufreq-set -g performance -u 800MHz -c 3
|
||||
*/
|
||||
public static void main(String[] args) throws IOException, InterruptedException {
|
||||
SubscriptionsStore store = new SubscriptionsStore();
|
||||
MemoryStorageService memStore = new MemoryStorageService();
|
||||
memStore.initStore();
|
||||
ISessionsStore aSessionsStore = memStore.sessionsStore();
|
||||
store.init(aSessionsStore);
|
||||
|
||||
int times = 10000;
|
||||
|
||||
int users = 500;
|
||||
int devices = 5;
|
||||
int values = 3;
|
||||
int subs = 2;
|
||||
int n = users * devices * values * subs;
|
||||
|
||||
ThreadMXBean b = ManagementFactory.getThreadMXBean();
|
||||
|
||||
String[] topics = new String[n];
|
||||
for (int i = 0; i < n; i++) {
|
||||
topics[i] = (i % users) + "/" + ((i / users) % devices) + "/" + ((i / (users * devices)) % values) + "/"
|
||||
+ ((i / (users * devices * values)) % subs);
|
||||
|
||||
Subscription sub = new Subscription("CLI_ID_" + (i % users), topics[i], AbstractMessage.QOSType.MOST_ONE);
|
||||
aSessionsStore.addNewSubscription(sub);
|
||||
store.add(sub.asClientTopicCouple());
|
||||
}
|
||||
|
||||
long min = Long.MAX_VALUE;
|
||||
//AtomicLong min = new AtomicLong(Long.MAX_VALUE);
|
||||
|
||||
System.out.println("Store size: " + store.size() + " " + n);
|
||||
|
||||
// warm up
|
||||
for (int i = 0; i < n; i++) {
|
||||
store.matches(topics[i]);
|
||||
}
|
||||
|
||||
System.out.println("press return for start");
|
||||
System.in.read();
|
||||
|
||||
// IntStream.range(0, times)
|
||||
// .parallel()
|
||||
// .forEach(j -> {
|
||||
|
||||
for (int j = 0; j < times; j++) {
|
||||
|
||||
System.gc();
|
||||
Thread.yield();
|
||||
|
||||
long time = b.getCurrentThreadCpuTime();
|
||||
for (int i = 0; i < n; i++) {
|
||||
store.matches(topics[i]);
|
||||
}
|
||||
long time2 = b.getCurrentThreadCpuTime() - time;
|
||||
min = Math.min(min, time2);
|
||||
// min.updateAndGet(c -> Math.min(c, time2));
|
||||
System.out.println(".." + j + ": " + time2 + " min:" + min);
|
||||
|
||||
}
|
||||
// });
|
||||
|
||||
System.out.println("min:" + min);
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user