繁体   English   中英

使用Cloud Service-Worker角色的Azure云到设备直接消息

[英]Azure Cloud to Device direct message using Cloud Service-Worker Role

我们正在开展一个项目,需要在设备之间交换大量消息/命令。

我们正在使用Cloud Service Worker角色来处理命令,并使用Cloud to Device Direct方法将其发送到相关设备。

辅助角色配置为具有4 GB RAM的A2V2-2内核。辅助角色容量没有问题。CPU和内存均处于控制状态。

对于较少的消息/命令处理,它的工作正常(例如500条消息)。但是,当没有消息增加时,我们将面临性能问题(例如1000条消息)。我们的目标是<5秒延迟。当我们尝试登录工作者角色时虚拟机,发现在向设备发送消息/命令时,TCP连接数一直在增加,并导致速度变慢。

下面的代码行用于使用直接方法发送消息。寻找更好的方法来在每次直接方法调用后处理Service客户端对象。

 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();
            }

最后我们找到了解决方案.Azure Service Client对象未正确关闭和处置。成功直接方法调用后,我们已明确关闭并处置Service Client对象。

  //closes the service client connection
  await _serviceClient.InvokeDeviceMethodAsync(methodInfo.DeviceId, methodInvocation);
 _serviceClient.CloseAsync().Wait();
 _serviceClient.Dispose();

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM