Skip to content

Instantly share code, notes, and snippets.

@drch-
Created April 11, 2012 20:25
Show Gist options
  • Save drch-/2362208 to your computer and use it in GitHub Desktop.
Save drch-/2362208 to your computer and use it in GitHub Desktop.
//hitMe / hitUs : sends the server the current timestamp and the number of calls to make back to the client. hitMe: just the callign client, hitUs: all clients on the hub.
//stepOne / stepAll : increments a counter
//doneOne / doneAll : prints # of messages and total duration.
$(function () {
function log(message) {
var $newMessage = $("<li/>", { text: message });
$("#messages").prepend($newMessage);
return $newMessage;
};
var bench = $.connection.hubBench,
countOne = 0,
countAll = 0;
bench.stepOne = function (ndx) {
delete idSet[ndx + ""];
++countOne;
};
bench.doneOne = function (start, expected) {
var duration = new Date().getTime() - start;
var $msg = log(countOne + " in " + duration + "ms");
var theCount = countOne;
countOne = 0;
if (expected != theCount) {
$msg.css('color', 'red');
console.log(idSet);
}
else {
$("#hitme").trigger('click');
}
};
bench.stepAll = function (ndx) {
delete idSet[ndx + ""];
++countAll;
};
bench.doneAll = function (start, expected, numConnections) {
var duration = new Date().getTime() - start;
var $msg = log(countAll + " in " + duration + "ms. " + numConnections + " connections");
if (expected != countAll) {
$msg.css('color', 'red');
}
countAll = 0;
};
$.connection.hub.start(options, function () { log("connected"); });
var idSet;
function initSet(numCalls) {
idSet = {};
for (var i = 0; i < numCalls; i++) {
idSet[i + ""] = i;
}
}
//benchmark messages to just me
$("#hitme").click(function () {
var numCalls = parseInt($("#clientCalls").val());
initSet(numCalls);
var now = new Date().getTime();
bench.hitMe(now, numCalls, $.connection.hub.id);
});
//benchmark messages to all clients
$("#hitus").click(function () {
var numCalls = parseInt($("#clientCalls").val());
var now = new Date().getTime();
bench.hitUs(now, numCalls);
});
});
Connetion: Waitng for messages from 5176. HubBench.stepOne, HubBench.doneOne, HubBench.stepAll, HubBench.doneAll, HubBench.558794dc-526c-46f2-a0f3-d1f646401c37, HubBench.558794dc-526c-46f2-a0f3-d1f646401c37.__SIGNALRCOMMAND__, SignalR.Hubs.HubDispatcher, 558794dc-526c-46f2-a0f3-d1f646401c37, 558794dc-526c-46f2-a0f3-d1f646401c37.__SIGNALRCOMMAND__
MessageBus: Connection waiting for new messages from id 5176
MessageBus: Saving message 5177 with eventKey HubBench.558794dc-526c-46f2-a0f3-d1f646401c37 to cache on AppDomain 3. Payload {"Hub":"HubBench","Method":"stepOne","Args":[0,"de89c512-5c41-420c-a4c5-19d1412d8da9"]}
MessageBus: Saving message 5178 with eventKey HubBench.558794dc-526c-46f2-a0f3-d1f646401c37 to cache on AppDomain 3. Payload {"Hub":"HubBench","Method":"stepOne","Args":[1,"de89c512-5c41-420c-a4c5-19d1412d8da9"]}
MessageBus: Saving message 5179 with eventKey HubBench.558794dc-526c-46f2-a0f3-d1f646401c37 to cache on AppDomain 3. Payload {"Hub":"HubBench","Method":"stepOne","Args":[2,"de89c512-5c41-420c-a4c5-19d1412d8da9"]}
MessageBus: Sending message 5178 with eventKey HubBench.558794dc-526c-46f2-a0f3-d1f646401c37 to 1 waiting connections
MessageBus: Sending message 5179 with eventKey HubBench.558794dc-526c-46f2-a0f3-d1f646401c37 to 1 waiting connections
MessageBus: Sending message 5177 with eventKey HubBench.558794dc-526c-46f2-a0f3-d1f646401c37 to 1 waiting connections
MessageBus: Saving message 5180 with eventKey HubBench.558794dc-526c-46f2-a0f3-d1f646401c37 to cache on AppDomain 3. Payload {"Hub":"HubBench","Method":"stepOne","Args":[3,"de89c512-5c41-420c-a4c5-19d1412d8da9"]}
Connection: Connection 558794dc-526c-46f2-a0f3-d1f646401c37 received 1 messages, last id 5178. Payload [{"Id":5178,"SignalKey":"HubBench.558794dc-526c-46f2-a0f3-d1f646401c37","Value":{"Value":{"Hub":"HubBench","Method":"stepOne","Args":[1,"de89c512-5c41-420c-a4c5-19d1412d8da9"]}},"Created":"2012-04-11T12:53:42.4736328-07:00","Expired":false}]
MessageBus: Sending message 5180 with eventKey HubBench.558794dc-526c-46f2-a0f3-d1f646401c37 to 0 waiting connections
MessageBus: Saving message 5181 with eventKey HubBench.558794dc-526c-46f2-a0f3-d1f646401c37 to cache on AppDomain 3. Payload {"Hub":"HubBench","Method":"stepOne","Args":[4,"de89c512-5c41-420c-a4c5-19d1412d8da9"]}
Connetion: Waitng for messages from 5178. HubBench.stepOne, HubBench.doneOne, HubBench.stepAll, HubBench.doneAll, HubBench.558794dc-526c-46f2-a0f3-d1f646401c37, HubBench.558794dc-526c-46f2-a0f3-d1f646401c37.__SIGNALRCOMMAND__, SignalR.Hubs.HubDispatcher, 558794dc-526c-46f2-a0f3-d1f646401c37, 558794dc-526c-46f2-a0f3-d1f646401c37.__SIGNALRCOMMAND__
MessageBus: Sending message 5181 with eventKey HubBench.558794dc-526c-46f2-a0f3-d1f646401c37 to 0 waiting connections
MessageBus: Saving message 5182 with eventKey HubBench.558794dc-526c-46f2-a0f3-d1f646401c37 to cache on AppDomain 3. Payload {"Hub":"HubBench","Method":"stepOne","Args":[5,"de89c512-5c41-420c-a4c5-19d1412d8da9"]}
MessageBus: Sending message 5182 with eventKey HubBench.558794dc-526c-46f2-a0f3-d1f646401c37 to 0 waiting connections
MessageBus: Saving message 5183 with eventKey HubBench.558794dc-526c-46f2-a0f3-d1f646401c37 to cache on AppDomain 3. Payload {"Hub":"HubBench","Method":"stepOne","Args":[6,"de89c512-5c41-420c-a4c5-19d1412d8da9"]}
MessageBus: Saving message 5184 with eventKey HubBench.558794dc-526c-46f2-a0f3-d1f646401c37 to cache on AppDomain 3. Payload {"Hub":"HubBench","Method":"stepOne","Args":[7,"de89c512-5c41-420c-a4c5-19d1412d8da9"]}
MessageBus: Sending message 5184 with eventKey HubBench.558794dc-526c-46f2-a0f3-d1f646401c37 to 0 waiting connections
MessageBus: Sending message 5183 with eventKey HubBench.558794dc-526c-46f2-a0f3-d1f646401c37 to 0 waiting connections
MessageBus: Saving message 5185 with eventKey HubBench.558794dc-526c-46f2-a0f3-d1f646401c37 to cache on AppDomain 3. Payload {"Hub":"HubBench","Method":"stepOne","Args":[8,"de89c512-5c41-420c-a4c5-19d1412d8da9"]}
MessageBus: Sending message 5185 with eventKey HubBench.558794dc-526c-46f2-a0f3-d1f646401c37 to 0 waiting connections
MessageBus: Saving message 5186 with eventKey HubBench.558794dc-526c-46f2-a0f3-d1f646401c37 to cache on AppDomain 3. Payload {"Hub":"HubBench","Method":"stepOne","Args":[9,"de89c512-5c41-420c-a4c5-19d1412d8da9"]}
MessageBus: Sending message 5186 with eventKey HubBench.558794dc-526c-46f2-a0f3-d1f646401c37 to 0 waiting connections
MessageBus: Saving message 5187 with eventKey HubBench.558794dc-526c-46f2-a0f3-d1f646401c37 to cache on AppDomain 3. Payload {"Hub":"HubBench","Method":"doneOne","Args":[1334174022453,10]}
MessageBus: Sending message 5187 with eventKey HubBench.558794dc-526c-46f2-a0f3-d1f646401c37 to 0 waiting connections
MessageBus: Connection getting messages from cache from id 5178
Connection: Connection 558794dc-526c-46f2-a0f3-d1f646401c37 received 9 messages, last id 5187. Payload [{"Id":5179,"SignalKey":"HubBench.558794dc-526c-46f2-a0f3-d1f646401c37","Value":{"Value":{"Hub":"HubBench","Method":"stepOne","Args":[2,"de89c512-5c41-420c-a4c5-19d1412d8da9"]}},"Created":"2012-04-11T12:53:42.4736328-07:00","Expired":false},{"Id":5180,"SignalKey":"HubBench.558794dc-526c-46f2-a0f3-d1f646401c37","Value":{"Value":{"Hub":"HubBench","Method":"stepOne","Args":[3,"de89c512-5c41-420c-a4c5-19d1412d8da9"]}},"Created":"2012-04-11T12:53:42.4892578-07:00","Expired":false},{"Id":5181,"SignalKey":"HubBench.558794dc-526c-46f2-a0f3-d1f646401c37","Value":{"Value":{"Hub":"HubBench","Method":"stepOne","Args":[4,"de89c512-5c41-420c-a4c5-19d1412d8da9"]}},"Created":"2012-04-11T12:53:42.5048828-07:00","Expired":false},{"Id":5182,"SignalKey":"HubBench.558794dc-526c-46f2-a0f3-d1f646401c37","Value":{"Value":{"Hub":"HubBench","Method":"stepOne","Args":[5,"de89c512-5c41-420c-a4c5-19d1412d8da9"]}},"Created":"2012-04-11T12:53:42.5048828-07:00","Expired":false},{"Id":5183,"SignalKey":"HubBench.558794dc-526c-46f2-a0f3-d1f646401c37","Value":{"Value":{"Hub":"HubBench","Method":"stepOne","Args":[6,"de89c512-5c41-420c-a4c5-19d1412d8da9"]}},"Created":"2012-04-11T12:53:42.5205078-07:00","Expired":false},{"Id":5184,"SignalKey":"HubBench.558794dc-526c-46f2-a0f3-d1f646401c37","Value":{"Value":{"Hub":"HubBench","Method":"stepOne","Args":[7,"de89c512-5c41-420c-a4c5-19d1412d8da9"]}},"Created":"2012-04-11T12:53:42.5205078-07:00","Expired":false},{"Id":5185,"SignalKey":"HubBench.558794dc-526c-46f2-a0f3-d1f646401c37","Value":{"Value":{"Hub":"HubBench","Method":"stepOne","Args":[8,"de89c512-5c41-420c-a4c5-19d1412d8da9"]}},"Created":"2012-04-11T12:53:42.5205078-07:00","Expired":false},{"Id":5186,"SignalKey":"HubBench.558794dc-526c-46f2-a0f3-d1f646401c37","Value":{"Value":{"Hub":"HubBench","Method":"stepOne","Args":[9,"de89c512-5c41-420c-a4c5-19d1412d8da9"]}},"Created":"2012-04-11T12:53:42.5205078-07:00","Expired":false},{"Id":5187,"SignalKey":"HubBench.558794dc-526c-46f2-a0f3-d1f646401c37","Value":{"Value":{"Hub":"HubBench","Method":"doneOne","Args":[1334174022453,10]}},"Created":"2012-04-11T12:53:42.5361328-07:00","Expired":false}]
Connetion: Waitng for messages from 5187. HubBench.stepOne, HubBench.doneOne, HubBench.stepAll, HubBench.doneAll, HubBench.558794dc-526c-46f2-a0f3-d1f646401c37, HubBench.558794dc-526c-46f2-a0f3-d1f646401c37.__SIGNALRCOMMAND__, SignalR.Hubs.HubDispatcher, 558794dc-526c-46f2-a0f3-d1f646401c37, 558794dc-526c-46f2-a0f3-d1f646401c37.__SIGNALRCOMMAND__
MessageBus: Connection waiting for new messages from id 5187
GET /signalr/connect?transport=serverSentEvents&connectionId=c16e4129-7f26-4d97-9aab-f875547bfe9b&connectionData=%5B%7B%22name%22%3A%22HubBench%22%2C%22methods%22%3A%5B%22stepOne%22%2C%22doneOne%22%2C%22stepAll%22%2C%22doneAll%22%5D%7D%5D HTTP/1.1
Host: localhost:40476
Connection: keep-alive
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.152 Safari/535.19
Accept: text/event-stream
Cache-Control: no-cache
Referer: http://localhost:40476/Hubs/Benchmark/index.htm
Accept-Encoding: gzip,deflate,sdch
Accept-Language: en-GB,en-US;q=0.8,en;q=0.6
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3
HTTP/1.1 200 OK
Cache-Control: no-cache
Pragma: no-cache
Transfer-Encoding: chunked
Content-Type: text/event-stream; charset=utf-8
Expires: -1
Server: Microsoft-IIS/7.5
X-AspNet-Version: 4.0.30319
X-SourceFiles: =?UTF-8?B?Qzpcc3R1ZmZcc2lnbmFsclxTaWduYWxSXHNhbXBsZXNcU2lnbmFsUi5Ib3N0aW5nLkFzcE5ldC5TYW1wbGVzXHNpZ25hbHJcY29ubmVjdA==?=
X-Powered-By: ASP.NET
Date: Wed, 11 Apr 2012 20:19:18 GMT
------------------------------------------------------------------
GET /signalr/connect?transport=longPolling&connectionId=c16e4129-7f26-4d97-9aab-f875547bfe9b&connectionData=%5B%7B%22name%22%3A%22HubBench%22%2C%22methods%22%3A%5B%22stepOne%22%2C%22doneOne%22%2C%22stepAll%22%2C%22doneAll%22%5D%7D%5D HTTP/1.1
Host: localhost:40476
Connection: keep-alive
X-Requested-With: XMLHttpRequest
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.152 Safari/535.19
Accept: application/json, text/javascript, */*; q=0.01
Referer: http://localhost:40476/Hubs/Benchmark/index.htm
Accept-Encoding: gzip,deflate,sdch
Accept-Language: en-GB,en-US;q=0.8,en;q=0.6
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3
HTTP/1.1 200 OK
Cache-Control: private
Content-Type: application/json; charset=utf-8
Server: Microsoft-IIS/7.5
X-AspNet-Version: 4.0.30319
X-SourceFiles: =?UTF-8?B?Qzpcc3R1ZmZcc2lnbmFsclxTaWduYWxSXHNhbXBsZXNcU2lnbmFsUi5Ib3N0aW5nLkFzcE5ldC5TYW1wbGVzXHNpZ25hbHJcY29ubmVjdA==?=
X-Powered-By: ASP.NET
Date: Wed, 11 Apr 2012 20:19:23 GMT
Content-Length: 190
{"MessageId":"5","Messages":[{"Hub":"HubBench","Method":"stepOne","Args":[1,"6e5e54d7-a67c-49aa-adf8-6518dd9f1866"]}],"Disconnect":false,"TimedOut":false,"TransportData":{"LongPollDelay":0}}
------------------------------------------------------------------
POST /signalr/send?transport=longPolling&connectionId=c16e4129-7f26-4d97-9aab-f875547bfe9b HTTP/1.1
Host: localhost:40476
Connection: keep-alive
Content-Length: 189
Origin: http://localhost:40476
X-Requested-With: XMLHttpRequest
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.152 Safari/535.19
Content-Type: application/x-www-form-urlencoded
Accept: application/json, text/javascript, */*; q=0.01
Referer: http://localhost:40476/Hubs/Benchmark/index.htm
Accept-Encoding: gzip,deflate,sdch
Accept-Language: en-GB,en-US;q=0.8,en;q=0.6
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3
data=%7B%22hub%22%3A%22HubBench%22%2C%22action%22%3A%22HitMe%22%2C%22data%22%3A%5B1334175562924%2C10%2C%22c16e4129-7f26-4d97-9aab-f875547bfe9b%22%5D%2C%22state%22%3A%7B%7D%2C%22id%22%3A0%7D
HTTP/1.1 200 OK
Cache-Control: private
Content-Type: application/json; charset=utf-8
Server: Microsoft-IIS/7.5
X-AspNet-Version: 4.0.30319
X-SourceFiles: =?UTF-8?B?Qzpcc3R1ZmZcc2lnbmFsclxTaWduYWxSXHNhbXBsZXNcU2lnbmFsUi5Ib3N0aW5nLkFzcE5ldC5TYW1wbGVzXHNpZ25hbHJcc2VuZA==?=
X-Powered-By: ASP.NET
Date: Wed, 11 Apr 2012 20:19:23 GMT
Content-Length: 66
{"State":{},"Result":null,"Id":"0","Error":null,"StackTrace":null}
------------------------------------------------------------------
GET /signalr?transport=longPolling&connectionId=c16e4129-7f26-4d97-9aab-f875547bfe9b&connectionData=%5B%7B%22name%22%3A%22HubBench%22%2C%22methods%22%3A%5B%22stepOne%22%2C%22doneOne%22%2C%22stepAll%22%2C%22doneAll%22%5D%7D%5D&messageId=5 HTTP/1.1
Host: localhost:40476
Connection: keep-alive
X-Requested-With: XMLHttpRequest
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.152 Safari/535.19
Accept: application/json, text/javascript, */*; q=0.01
Referer: http://localhost:40476/Hubs/Benchmark/index.htm
Accept-Encoding: gzip,deflate,sdch
Accept-Language: en-GB,en-US;q=0.8,en;q=0.6
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3
HTTP/1.1 200 OK
Cache-Control: private
Content-Type: application/json; charset=utf-8
Server: Microsoft-IIS/7.5
X-AspNet-Version: 4.0.30319
X-SourceFiles: =?UTF-8?B?Qzpcc3R1ZmZcc2lnbmFsclxTaWduYWxSXHNhbXBsZXNcU2lnbmFsUi5Ib3N0aW5nLkFzcE5ldC5TYW1wbGVzXHNpZ25hbHI=?=
X-Powered-By: ASP.NET
Date: Wed, 11 Apr 2012 20:19:23 GMT
Content-Length: 871
{"MessageId":"14","Messages":[{"Hub":"HubBench","Method":"stepOne","Args":[2,"6e5e54d7-a67c-49aa-adf8-6518dd9f1866"]},{"Hub":"HubBench","Method":"stepOne","Args":[3,"6e5e54d7-a67c-49aa-adf8-6518dd9f1866"]},{"Hub":"HubBench","Method":"stepOne","Args":[4,"6e5e54d7-a67c-49aa-adf8-6518dd9f1866"]},{"Hub":"HubBench","Method":"stepOne","Args":[5,"6e5e54d7-a67c-49aa-adf8-6518dd9f1866"]},{"Hub":"HubBench","Method":"stepOne","Args":[6,"6e5e54d7-a67c-49aa-adf8-6518dd9f1866"]},{"Hub":"HubBench","Method":"stepOne","Args":[7,"6e5e54d7-a67c-49aa-adf8-6518dd9f1866"]},{"Hub":"HubBench","Method":"stepOne","Args":[8,"6e5e54d7-a67c-49aa-adf8-6518dd9f1866"]},{"Hub":"HubBench","Method":"stepOne","Args":[9,"6e5e54d7-a67c-49aa-adf8-6518dd9f1866"]},{"Hub":"HubBench","Method":"doneOne","Args":[1334175562924,10]}],"Disconnect":false,"TimedOut":false,"TransportData":{"LongPollDelay":0}}
------------------------------------------------------------------
GET /signalr?transport=longPolling&connectionId=c16e4129-7f26-4d97-9aab-f875547bfe9b&connectionData=%5B%7B%22name%22%3A%22HubBench%22%2C%22methods%22%3A%5B%22stepOne%22%2C%22doneOne%22%2C%22stepAll%22%2C%22doneAll%22%5D%7D%5D&messageId=14 HTTP/1.1
Host: localhost:40476
Connection: keep-alive
X-Requested-With: XMLHttpRequest
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.152 Safari/535.19
Accept: application/json, text/javascript, */*; q=0.01
Referer: http://localhost:40476/Hubs/Benchmark/index.htm
Accept-Encoding: gzip,deflate,sdch
Accept-Language: en-GB,en-US;q=0.8,en;q=0.6
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3
------------------------------------------------------------------
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using SignalR.Hubs;
namespace SignalR.Samples.Hubs.Benchmark
{
public class HubBench : Hub, IConnected, IDisconnect
{
public static int Connections;
public void HitMe(long start, int clientCalls, string connectionId)
{
var tasks = new List<Task>();
for (int i = 0; i < clientCalls; i++)
{
tasks.Add(Clients[connectionId].stepOne());
}
Task.WaitAll(tasks.ToArray());
Clients[connectionId].doneOne(start, clientCalls).Wait();
}
public void HitUs(long start, int clientCalls)
{
for (int i = 0; i < clientCalls; i++)
{
Clients.stepAll().Wait();
}
Clients.doneAll(start, clientCalls, Connections).Wait();
}
public Task Connect()
{
Interlocked.Increment(ref HubBench.Connections);
return null;
}
public Task Disconnect()
{
Interlocked.Decrement(ref HubBench.Connections);
return null;
}
public Task Reconnect(IEnumerable<string> groups)
{
return null;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment