Minor changes

This commit is contained in:
andsel
2016-11-05 18:29:08 +01:00
parent b51b3214ba
commit 8e43f75f70
3 changed files with 41 additions and 27 deletions
@@ -18,8 +18,8 @@ package io.moquette.server;
import io.netty.channel.Channel; import io.netty.channel.Channel;
/** /**
* Value object to maintain the information of single connection, like ClientID, IoSession, * Value object to maintain the information of single connection, like ClientID, Channel,
* and other clean session fla. * and clean session flag.
* *
* *
* @author andrea * @author andrea
@@ -1,8 +1,11 @@
@GrabResolver(name='Paho', root='https://repo.eclipse.org/content/repositories/paho-releases/') @GrabResolver(name='Paho', root='https://repo.eclipse.org/content/repositories/paho-releases/')
@Grab(group='org.eclipse.paho', module='mqtt-client', version='0.4.0') //@Grab(group='org.eclipse.paho', module='mqtt-client', version='0.4.0')
@Grab(group='org.eclipse.paho', module='org.eclipse.paho.client.mqttv3', version='1.1.0')
@Grab(group='org.eclipse.jetty.toolchain', module='jetty-perf-helper', version='1.0.5') @Grab(group='org.eclipse.jetty.toolchain', module='jetty-perf-helper', version='1.0.5')
//@Grab(group='org.slf4j', module='slf4j-api', version='1.7.21')
//@Grab(group='org.slf4j', module='slf4j-jdk14', version='1.7.21')
import org.eclipse.paho.client.mqttv3.MqttAsyncClient import org.eclipse.paho.client.mqttv3.MqttClient
import org.eclipse.paho.client.mqttv3.MqttMessage import org.eclipse.paho.client.mqttv3.MqttMessage
import org.eclipse.paho.client.mqttv3.MqttException import org.eclipse.paho.client.mqttv3.MqttException
import org.eclipse.paho.client.mqttv3.MqttCallback import org.eclipse.paho.client.mqttv3.MqttCallback
@@ -11,8 +14,9 @@ import org.eclipse.paho.client.mqttv3.persist.MqttDefaultFilePersistence
import org.HdrHistogram.Histogram import org.HdrHistogram.Histogram
import org.eclipse.jetty.toolchain.perf.PlatformTimer import org.eclipse.jetty.toolchain.perf.PlatformTimer
import java.nio.ByteBuffer
import java.util.concurrent.Semaphore import java.util.concurrent.Semaphore
//import groovy.util.logging.Slf4j
/** /**
* Performance metric test for issue 204. * Performance metric test for issue 204.
@@ -26,9 +30,9 @@ import java.util.concurrent.Semaphore
* - disconnect * - disconnect
* [MEASURE STOP] * [MEASURE STOP]
* */ * */
//@Slf4j
class WorkflowTask implements MqttCallback { class WorkflowTask implements MqttCallback {
private MqttAsyncClient client private MqttClient client
private int clientCounter private int clientCounter
private long startTime private long startTime
private long numOfIterations private long numOfIterations
@@ -37,49 +41,59 @@ class WorkflowTask implements MqttCallback {
private PlatformTimer timer = PlatformTimer.detect() private PlatformTimer timer = PlatformTimer.detect()
private Semaphore disconnectReceived = new Semaphore(0) private Semaphore disconnectReceived = new Semaphore(0)
private static String printDate() {
return new Date().format("HH:mm:ss,SSS") + " " + Thread.currentThread().getName()
}
void execute() { void execute() {
client.callback = this client.callback = this
(1..numOfIterations).each { it -> (1..numOfIterations).each { it ->
startTime = System.nanoTime() startTime = System.nanoTime()
client.connect().waitForCompletion(1000) println "\nAsk connect " + printDate()
println "connected ${it}" client.connect()//.waitForCompletion()
println "connected ${it}, " + printDate()
client.subscribe("/topic${clientCounter}", 0) client.subscribe("/topic${clientCounter}", 0)
println "subscribed to /topic${clientCounter}" println "subscribed to /topic${clientCounter} " + printDate()
//byte[] bytes = ByteBuffer.allocate(8).putLong(System.currentTimeMillis()).array() byte[] bytes = "TestPayload ${it}".bytes
byte[] bytes = "TestPayload".bytes
client.publish("/topic${clientCounter}", bytes, 0, false) client.publish("/topic${clientCounter}", bytes, 0, false)
println "published to /topic${clientCounter}..wait for receive of message" println "published ${it}, " + printDate()
// println "published to /topic${clientCounter}..wait for receive of message"
disconnectReceived.acquire() disconnectReceived.acquire()
println "Acquired semaphore, value ${disconnectReceived.availablePermits()}" println "Acquired semaphore, value ${disconnectReceived.availablePermits()} " + printDate()
client.disconnect().waitForCompletion(1000) println "Ask disconnect " + printDate()
println "Disconnected" client.disconnect()//.waitForCompletion()
println "Disconnected ${it}" + printDate() + "\n"
client.debug.dumpClientDebug()
// client.close()
long stopTime = System.nanoTime() long stopTime = System.nanoTime()
long spentNanoSeconds = stopTime - startTime long spentNanoSeconds = stopTime - startTime
histogram.recordValue(spentNanoSeconds) histogram.recordValue(spentNanoSeconds)
//timer.sleep(pauseMicroseconds) // long waitMicroseconds = pauseMicroseconds - (spentNanoSeconds / 1000)
// println "${spentNanoSeconds} spent nanos, pauseMicroseconds: ${pauseMicroseconds}"
// timer.sleep(waitMicroseconds)
} }
println "Latency diagram (micro secs):\n" println "Latency diagram (micro secs):\n"
histogram.outputPercentileDistribution(System.out, 1000.0) histogram.outputPercentileDistribution(System.out, 1000.0)
} }
public void messageArrived(String topic, MqttMessage message) throws Exception { public void messageArrived(String topic, MqttMessage message) throws Exception {
println "Received published" println "Received published " + printDate()
if (topic != "/topic${clientCounter}".toString()) { if (topic != "/topic${clientCounter}".toString()) {
println "Error received a publish on not matching topic ${topic}" println "Error received a publish on not matching topic ${topic}"
return return
} }
long stopTime = System.nanoTime() // long stopTime = System.nanoTime()
long spentNanoSeconds = stopTime - startTime // long spentNanoSeconds = stopTime - startTime
disconnectReceived.release() disconnectReceived.release()
println "Released semaphore, value ${disconnectReceived.availablePermits()}" println "Released semaphore, value ${disconnectReceived.availablePermits()} " + printDate()
} }
public void connectionLost(Throwable cause) { public void connectionLost(Throwable cause) {
// println "Client ${clientCounter} lost connection" println "Client ${clientCounter} lost connection, caused by ${cause}"
} }
public void deliveryComplete(IMqttDeliveryToken token) { public void deliveryComplete(IMqttDeliveryToken token) {
@@ -88,10 +102,10 @@ class WorkflowTask implements MqttCallback {
} }
MqttAsyncClient createClient(int i) { MqttClient createClient(int i) {
String tmpDir = System.getProperty("java.io.tmpdir") String tmpDir = System.getProperty("java.io.tmpdir")
MqttDefaultFilePersistence dataStore = new MqttDefaultFilePersistence(tmpDir) MqttDefaultFilePersistence dataStore = new MqttDefaultFilePersistence(tmpDir)
new MqttAsyncClient("tcp://localhost:1883", "TestClient${i}", dataStore) new MqttClient("tcp://localhost:1883", "TestClient${i}", dataStore)
} }
Histogram histogram = new Histogram(5) Histogram histogram = new Histogram(5)
@@ -105,7 +119,7 @@ int duration = args[1] as int
long pauseMicroseconds = (1 / numOfIterationsPerSecond) * 1000 * 1000 long pauseMicroseconds = (1 / numOfIterationsPerSecond) * 1000 * 1000
long numOfIterations = numOfIterationsPerSecond * duration long numOfIterations = numOfIterationsPerSecond * duration
MqttAsyncClient client = createClient(0) MqttClient client = createClient(0)
def task = new WorkflowTask(client: client, clientCounter: 0, histogram: histogram, def task = new WorkflowTask(client: client, clientCounter: 0, histogram: histogram,
pauseMicroseconds: pauseMicroseconds, numOfIterations: numOfIterations) pauseMicroseconds: pauseMicroseconds, numOfIterations: numOfIterations)
@@ -43,13 +43,13 @@ MQTT sub = new MQTT()
//mqtt.setHost("test.mosquitto.org", 1883); //mqtt.setHost("test.mosquitto.org", 1883);
sub.setHost(host, 1883) sub.setHost(host, 1883)
sub.setCleanSession(true) sub.setCleanSession(true)
sub.setHost(host, 1883)
sub.setClientId("SubscriberClient${dialog_id}") sub.setClientId("SubscriberClient${dialog_id}")
BenchmarkSubscriber suscriberBench = new BenchmarkSubscriber(mqtt: sub, dialog_id: dialog_id) BenchmarkSubscriber suscriberBench = new BenchmarkSubscriber(mqtt: sub, dialog_id: dialog_id)
suscriberBench.connect() suscriberBench.connect()
BenchmarkPublisher publisherBench = new BenchmarkPublisher(mqtt: pub, numToSend: numToSend, messagesPerSecond: messagesPerSecond, dialog_id: dialog_id) BenchmarkPublisher publisherBench = new BenchmarkPublisher(mqtt: pub, numToSend: numToSend,
messagesPerSecond: messagesPerSecond, dialog_id: dialog_id)
publisherBench.connect() publisherBench.connect()
publisherBench.firePublishes() publisherBench.firePublishes()