private static MemoryHost RunMemoryHost()
{
var host = new MemoryHost();
host.MapConnection<StressConnection>("/echo");
string payload = GetPayload();
MeasureStats((MessageBus)host.DependencyResolver.Resolve<IMessageBus>());
Action<PersistentResponse> handler = (r) =>
{
Interlocked.Add(ref _received, r.TotalCount);
Interlocked.Add(ref _avgLastReceivedCount, r.TotalCount);
};
LongPollingTransport.SendingResponse += handler;
ForeverFrameTransport.SendingResponse += handler;
for (int i = 0; i < _clients; i++)
{
ThreadPool.QueueUserWorkItem(state =>
{
Interlocked.Increment(ref _clientsRunning);
string connectionId = state.ToString();
//LongPollingLoop(host, connectionId);
ProcessRequest(host, "serverSentEvents", connectionId);
}, i);
}
for (var i = 1; i <= _senders; i++)
{
ThreadPool.QueueUserWorkItem(_ =>
{
var context = host.ConnectionManager.GetConnectionContext<StressConnection>();
StartSendLoop(i.ToString(), (source, key, value) => context.Connection.Broadcast(value), payload);
});
}
return host;
}