We are working one project which required high volume of message/command exchanged between device to device.
We are using Cloud Service Worker role for processing commands and send to relevant devices using Cloud to Device Direct Method.
The worker role configuration is A2V2-2 Core with 4 GB RAM.There is no problem with worker role capacity.The CPU and Memory all in control.
For less no of message/command processing its working fine(Eg 500 Messages).But when no of messages increase we are facing performance issue(Eg 1000 Messages).We are targeting <5 Sec latency.When we try to log in Worker Role VM and found that the no of TCP connections keep increasing and its causing slowness while sending message/commands to devices.
The following line of code which we are using to send messages using Direct Method.Looking better way to dispose Service client object after each direct method call.
var methodInvocation = new CloudToDeviceMethod(methodInfo.MethodName) { ResponseTimeout = TimeSpan.FromSeconds(methodInfo.ResponseTimeout) };
//set the payload
methodInvocation.SetPayloadJson(methodInfo.Payload);
//invokes direct method
var response = _serviceClient.InvokeDeviceMethodAsync(methodInfo.DeviceId, methodInvocation);
if (_serviceClient != null)
{
//closes the service client connection
_serviceClient.CloseAsync();
_serviceClient.Dispose();
}