0

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();
            }
RANJITH M
  • 1
  • 2
  • 1.Can you check the "[Cloud-to-device communications guidance](https://learn.microsoft.com/en-us/azure/iot-hub/iot-hub-devguide-c2d-guidance)" so make sure your case must need direct method that for communications that require immediate confirmation of the result. Direct methods are often used for interactive control of devices such as turning on a fan. 2. How much time happens 1000 messages, one second? – Rita Han Aug 16 '18 at 06:44
  • Thanks Rita Han. – RANJITH M Aug 16 '18 at 07:37
  • We cant go with Cloud To Device Message approach because of threshold limitation. So we have only option to go with Direct Method.We are doing 100 to 150 message / sec – RANJITH M Aug 16 '18 at 07:39

1 Answers1

0

At last we found the solution.The Azure Service Client object was not properly closed and disposed.We have closed and disposed Service Client object explicitly after successful direct method call.

  //closes the service client connection
  await _serviceClient.InvokeDeviceMethodAsync(methodInfo.DeviceId, methodInvocation);
 _serviceClient.CloseAsync().Wait();
 _serviceClient.Dispose();
RANJITH M
  • 1
  • 2
  • @Thanks for sharing. You can [accept this answer](https://stackoverflow.com/help/someone-answers) and we can close this issue. – Rita Han Aug 17 '18 at 02:41