Added some benchmariking utils: benchmarker produces tiing csv and an html using Highcharts JS lib
This commit is contained in:
@@ -0,0 +1,112 @@
|
||||
//@GrabResolver(name='Paho', root='https://repo.eclipse.org/content/repositories/paho-snapshots/')
|
||||
//@Grab(group='org.eclipse.paho', module='org.eclipse.paho.client.mqttv3', version='1.0.1-SNAPSHOT')
|
||||
@GrabResolver(name='Paho', root='https://repo.eclipse.org/content/repositories/paho-releases/')
|
||||
@Grab(group='org.eclipse.paho', module='mqtt-client', version='0.4.0')
|
||||
|
||||
import org.eclipse.paho.client.mqttv3.MqttAsyncClient
|
||||
import org.eclipse.paho.client.mqttv3.MqttMessage
|
||||
import org.eclipse.paho.client.mqttv3.MqttException
|
||||
import org.eclipse.paho.client.mqttv3.MqttCallback
|
||||
import org.eclipse.paho.client.mqttv3.IMqttDeliveryToken
|
||||
import org.eclipse.paho.client.mqttv3.persist.MqttDefaultFilePersistence
|
||||
import java.util.concurrent.CountDownLatch
|
||||
import static groovy.json.JsonOutput.*
|
||||
import java.nio.ByteBuffer
|
||||
|
||||
|
||||
class SubscriberCallback implements MqttCallback {
|
||||
|
||||
int m_numReceived = 0
|
||||
long m_startTime
|
||||
boolean firstMessageReceived = false
|
||||
|
||||
private CountDownLatch m_latch = new CountDownLatch(1)
|
||||
|
||||
//Maps delay to num of messages reached with that delay
|
||||
protected Map<Long, Long> distribution = [:]
|
||||
|
||||
void waitFinish() {
|
||||
m_latch.await()
|
||||
}
|
||||
|
||||
public void connectionLost(Throwable cause) {
|
||||
m_latch.countDown()
|
||||
}
|
||||
|
||||
public void messageArrived(String topic, MqttMessage message) throws Exception {
|
||||
//println "Received message ${new String(message.payload)} on topic [${topic}]"
|
||||
if (!firstMessageReceived) {
|
||||
m_startTime = System.currentTimeMillis()
|
||||
firstMessageReceived = true
|
||||
}
|
||||
if (topic == "/exit") {
|
||||
long stopTime = System.currentTimeMillis()
|
||||
long spentTime = stopTime - m_startTime
|
||||
println "/exit received"
|
||||
println "subscriber disconnected, received ${m_numReceived} messages in ${spentTime} ms (from first received to last one on topic /exit)"
|
||||
client.disconnect()
|
||||
m_latch.countDown()
|
||||
} else {
|
||||
ByteBuffer bb = ByteBuffer.wrap(message.payload)
|
||||
long sentTime = bb.getLong()
|
||||
long delay = System.currentTimeMillis() - sentTime
|
||||
//println "-received in ${delay}(ms) on ${topic} with QoS ${message.qos}"
|
||||
//distribution[delay] = distribution[delay] != null ? distribution[delay]++ : 1
|
||||
if (distribution[delay] != null) {
|
||||
distribution[delay]++
|
||||
} else {
|
||||
distribution[delay] = 1
|
||||
}
|
||||
m_numReceived++
|
||||
}
|
||||
}
|
||||
|
||||
public void deliveryComplete(IMqttDeliveryToken token) {
|
||||
//To change body of implemented methods use File | Settings | File Templates.
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
def publishQos0(client, long numMessages) {
|
||||
print "publishing.."
|
||||
long startTime = System.currentTimeMillis()
|
||||
(1..numMessages).each {
|
||||
byte[] bytes = ByteBuffer.allocate(8).putLong(System.currentTimeMillis()).array();
|
||||
client.publish('topic', bytes, 0, false)
|
||||
}
|
||||
client.publish('/exit', 'Exit'.bytes, 0, false)
|
||||
long stopTime = System.currentTimeMillis()
|
||||
long spentTime = stopTime -startTime
|
||||
println "published in ${spentTime} ms"
|
||||
}
|
||||
|
||||
if (args.size() < 2) {
|
||||
println "Usage benchmarker <host> <numMessages>"
|
||||
return
|
||||
}
|
||||
|
||||
String host = args[0]
|
||||
long numMessages = args[1] as long
|
||||
String tmpDir = System.getProperty("java.io.tmpdir")
|
||||
MqttDefaultFilePersistence dataStore = new MqttDefaultFilePersistence(tmpDir)
|
||||
|
||||
int rnd = (Math.random() * 100) as int
|
||||
MqttAsyncClient client = new MqttAsyncClient("tcp://${host}:1883", "SubscriberClient${rnd}", dataStore)
|
||||
def callback = new SubscriberCallback()
|
||||
client.callback = callback
|
||||
client.connect().waitForCompletion(1000);
|
||||
client.subscribe("topic", 0)
|
||||
println "subscribed to topic"
|
||||
client.subscribe("/exit", 0)
|
||||
println "subscribed to /exit"
|
||||
|
||||
publishQos0(client, numMessages)
|
||||
|
||||
callback.waitFinish()
|
||||
Map sorted = callback.distribution.sort( { k1, k2 -> k1 <=> k2 } as Comparator)
|
||||
//println prettyPrint(toJson(sorted))
|
||||
File csv = new File("perf.csv")
|
||||
sorted.each {delay, count -> csv << "${delay}, ${count}\r\n"}
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,104 @@
|
||||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
|
||||
<title>Moquette performances</title>
|
||||
|
||||
|
||||
<!-- 1. Add these JavaScript inclusions in the head of your page -->
|
||||
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
|
||||
<script type="text/javascript" src="http://code.highcharts.com/highcharts.js"></script>
|
||||
|
||||
|
||||
<!-- 2. Add the JavaScript to initialize the chart on document ready -->
|
||||
<script type="text/javascript">
|
||||
$(document).ready(function() {
|
||||
|
||||
|
||||
var options = {
|
||||
chart: {
|
||||
renderTo: 'container',
|
||||
type: 'line'
|
||||
},
|
||||
title: {
|
||||
text: 'Moquette ping-pong Qos0'
|
||||
},
|
||||
xAxis: {
|
||||
categories: [],
|
||||
tickInterval: 100
|
||||
},
|
||||
yAxis: {
|
||||
title: {
|
||||
text: 'num msgs'
|
||||
}
|
||||
},
|
||||
series: []
|
||||
};
|
||||
|
||||
/*
|
||||
Load the data from the CSV file. This is the contents of the file:
|
||||
|
||||
Apples,Pears,Oranges,Bananas,Plums
|
||||
John,8,4,6,5
|
||||
Jane,3,4,2,3
|
||||
Joe,86,76,79,77
|
||||
Janet,3,16,13,15
|
||||
|
||||
*/
|
||||
//$.get('file:///home/andrea/workspace/moquette/tools_scripts/perf_1000.csv', function(data) {
|
||||
$.get('perf_tmp.csv', function(data) {
|
||||
// Split the lines
|
||||
var lines = data.split('\n');
|
||||
var series = {
|
||||
name: 'Bira',
|
||||
//data: [1, 2, 4, 5, 6]
|
||||
data: [/*[100,1], [200, 2], [300, 4], [400, 5], [500, 6]*/]
|
||||
};
|
||||
$.each(lines, function(lineNo, line) {
|
||||
var items = line.split(',');
|
||||
if (lineNo > 0) {
|
||||
var tick = parseFloat(items[0]);
|
||||
var value = parseFloat(items[1]);
|
||||
if (!isNaN(tick)) {
|
||||
series.data.push([tick, value]);
|
||||
}
|
||||
}
|
||||
|
||||
// header line containes categories
|
||||
/*if (lineNo == 0) {
|
||||
$.each(items, function(itemNo, item) {
|
||||
if (itemNo > 0) options.xAxis.categories.push(item);
|
||||
});
|
||||
}*/
|
||||
|
||||
// the rest of the lines contain data with their name in the first position
|
||||
/*else {
|
||||
$.each(items, function(itemNo, item) {
|
||||
if (itemNo == 0) {
|
||||
series.name = item;
|
||||
} else {
|
||||
series.data.push(parseFloat(item));
|
||||
});
|
||||
|
||||
//options.series.push(series);
|
||||
|
||||
}*/
|
||||
|
||||
});
|
||||
options.series.push(series);
|
||||
var chart = new Highcharts.Chart(options);
|
||||
});
|
||||
|
||||
|
||||
});
|
||||
</script>
|
||||
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<!-- 3. Add the container -->
|
||||
<div id="container" style="width: 800px; height: 400px; margin: 0 auto"></div>
|
||||
|
||||
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,30 @@
|
||||
@Grab(group='org.eclipse.jetty.aggregate', module='jetty-server', version='8.1.16.v20140903')
|
||||
@Grab(group='javax.servlet', module='javax.servlet-api', version='3.0.1')
|
||||
|
||||
import org.eclipse.jetty.server.Server
|
||||
import org.eclipse.jetty.server.nio.SelectChannelConnector
|
||||
import org.eclipse.jetty.server.handler.ResourceHandler
|
||||
import org.eclipse.jetty.server.handler.HandlerList
|
||||
import org.eclipse.jetty.server.handler.DefaultHandler
|
||||
import org.eclipse.jetty.server.Handler
|
||||
|
||||
Server server = new Server();
|
||||
SelectChannelConnector connector = new SelectChannelConnector();
|
||||
connector.setPort(8080);
|
||||
server.addConnector(connector);
|
||||
|
||||
ResourceHandler resource_handler = new ResourceHandler();
|
||||
resource_handler.setDirectoriesListed(true);
|
||||
//resource_handler.setWelcomeFiles(["index.html"] as new String[0]);
|
||||
|
||||
resource_handler.setResourceBase(".");
|
||||
|
||||
HandlerList handlers = new HandlerList();
|
||||
handlers.addHandler(resource_handler)
|
||||
handlers.addHandler(new DefaultHandler());
|
||||
server.setHandler(handlers);
|
||||
|
||||
server.start();
|
||||
println "Local server started"
|
||||
|
||||
server.join();
|
||||
@@ -0,0 +1,96 @@
|
||||
ms, num
|
||||
2245, 7
|
||||
2246, 14
|
||||
2247, 11
|
||||
2248, 8
|
||||
2249, 8
|
||||
2250, 7
|
||||
2251, 14
|
||||
2252, 10
|
||||
2253, 8
|
||||
2254, 9
|
||||
2255, 8
|
||||
2256, 16
|
||||
2257, 9
|
||||
2258, 8
|
||||
2259, 8
|
||||
2260, 9
|
||||
2261, 16
|
||||
2262, 8
|
||||
2263, 8
|
||||
2264, 8
|
||||
2265, 10
|
||||
2266, 21
|
||||
2267, 19
|
||||
2268, 18
|
||||
2269, 18
|
||||
2270, 20
|
||||
2271, 39
|
||||
2272, 16
|
||||
2273, 18
|
||||
2274, 17
|
||||
2275, 24
|
||||
2276, 26
|
||||
2277, 18
|
||||
2278, 25
|
||||
2279, 17
|
||||
2280, 21
|
||||
2281, 31
|
||||
2282, 10
|
||||
2283, 11
|
||||
2284, 15
|
||||
2285, 10
|
||||
2286, 9
|
||||
2287, 9
|
||||
2288, 13
|
||||
2289, 14
|
||||
2290, 10
|
||||
2291, 17
|
||||
2292, 14
|
||||
2293, 14
|
||||
2294, 16
|
||||
2295, 9
|
||||
2296, 17
|
||||
2297, 9
|
||||
2298, 17
|
||||
2299, 8
|
||||
2300, 16
|
||||
2301, 13
|
||||
2302, 16
|
||||
2303, 15
|
||||
2304, 18
|
||||
2305, 11
|
||||
2306, 16
|
||||
2307, 10
|
||||
2308, 14
|
||||
2309, 12
|
||||
2310, 14
|
||||
2311, 11
|
||||
2312, 15
|
||||
2313, 12
|
||||
2314, 14
|
||||
2315, 9
|
||||
2316, 17
|
||||
2317, 8
|
||||
2318, 15
|
||||
2319, 13
|
||||
2320, 8
|
||||
2321, 18
|
||||
2322, 9
|
||||
2323, 9
|
||||
2324, 14
|
||||
2325, 18
|
||||
2326, 18
|
||||
2327, 19
|
||||
2328, 8
|
||||
2329, 16
|
||||
2330, 11
|
||||
2331, 14
|
||||
2332, 11
|
||||
2333, 17
|
||||
2334, 8
|
||||
2335, 16
|
||||
2336, 10
|
||||
2337, 16
|
||||
2338, 11
|
||||
2339, 15
|
||||
|
Reference in New Issue
Block a user