如何使模块之间的 Iot Edge 消息路由在 arm32 上工作 (Raspberry Pi)

How to make Iot Edge message routing between modules work on arm32 (Raspberry Pi)

我使用 Visual Studio 代码通过 View -> Command Palette...-> AzureIotEdge:NewIoTEdgeSolution 使用 C# 模块 模块模板。这会生成一个具有两个模块的 Iot Edge 解决方案:tempSensor 使用虚拟遥测数据创建消息,SampleModule 应该接收这些消息,打印它们并然后将它们传递给 IotHub。

我为 arm32 构建解决方案并将其部署到 Rasperry Pi(运行ning 最新 Raspbian)。然后,模块在设备上显示为 运行ning,但如果我监视 d2c 消息,则有 none 到达 IoT 中心。

如果我 运行 sudo iotedge 在设备上记录 tempSensor -f,我可以看到正在生成消息。

如果我 运行 sudo iotedge logs SampleModule -f 我只看到 IoT Hub 模块客户端已初始化。 已记录在 Init() 方法中。没有来自 PipeMessage 方法的日志记录,似乎根本无法达到。

如果我为 amd64 构建解决方案并将其部署到虚拟机,一切都按预期工作。

有没有办法让它在 Raspberry Pi 运行ning Raspian 上运行?

顺便说一下:我也尝试了 Azure Functions C# 模块模板。结果相同:在 amd64 上可以,但在 arm32 上不行。

更新: 这是 edgeAgent:

的日志记录
            █████╗ ███████╗██╗   ██╗██████╗ ███████╗
       ██╔══██╗╚══███╔╝██║   ██║██╔══██╗██╔════╝
       ███████║  ███╔╝ ██║   ██║██████╔╝█████╗
       ██╔══██║ ███╔╝  ██║   ██║██╔══██╗██╔══╝
       ██║  ██║███████╗╚██████╔╝██║  ██║███████╗
       ╚═╝  ╚═╝╚══════╝ ╚═════╝ ╚═╝  ╚═╝╚══════╝

 ██╗ ██████╗ ████████╗    ███████╗██████╗  ██████╗ ███████╗
 ██║██╔═══██╗╚══██╔══╝    ██╔════╝██╔══██╗██╔════╝ ██╔════╝
 ██║██║   ██║   ██║       █████╗  ██║  ██║██║  ███╗█████╗
 ██║██║   ██║   ██║       ██╔══╝  ██║  ██║██║   ██║██╔══╝
 ██║╚██████╔╝   ██║       ███████╗██████╔╝╚██████╔╝███████╗
 ╚═╝ ╚═════╝    ╚═╝       ╚══════╝╚═════╝  ╚═════╝ ╚══════╝

2018-12-21 07:08:27.323 +00:00 [INF] - Edge agent attempting to connect to IoT Hub via Amqp_Tcp_Only...
2018-12-21 07:08:31.986 +00:00 [INF] - Created persistent store at /tmp/edgeAgent
2018-12-21 07:08:34.193 +00:00 [INF] - Edge agent connected to IoT Hub via Amqp_Tcp_Only.
2018-12-21 07:08:37.624 +00:00 [INF] - Plan execution started for deployment 8
2018-12-21 07:08:37.654 +00:00 [INF] - Executing command: "Stop module SampleModule"
2018-12-21 07:08:37.766 +00:00 [INF] - Executing command: "Remove module SampleModule"
2018-12-21 07:08:37.964 +00:00 [INF] - Executing command: "Saving SampleModule to store"
2018-12-21 07:08:38.141 +00:00 [INF] - Executing command: "Command Group: (
  [Create module SampleModule2]
  [Start module SampleModule2]
)"
2018-12-21 07:08:38.152 +00:00 [INF] - Executing command: "Create module SampleModule2"
2018-12-21 07:08:42.678 +00:00 [INF] - Executing command: "Start module SampleModule2"
2018-12-21 07:08:45.749 +00:00 [INF] - Executing command: "Command Group: (
  [Stop module tempSensor]
  [Start module tempSensor]
  [Saving tempSensor to store]
)"
2018-12-21 07:08:45.750 +00:00 [INF] - Executing command: "Stop module tempSensor"
2018-12-21 07:08:45.759 +00:00 [INF] - Executing command: "Start module tempSensor"
2018-12-21 07:08:48.423 +00:00 [INF] - Executing command: "Saving tempSensor to store"
2018-12-21 07:08:48.491 +00:00 [INF] - Executing command: "Command Group: (
  [Stop module edgeHub]
  [Start module edgeHub]
  [Saving edgeHub to store]
)"
2018-12-21 07:08:48.491 +00:00 [INF] - Executing command: "Stop module edgeHub"
2018-12-21 07:08:48.501 +00:00 [INF] - Executing command: "Start module edgeHub"
2018-12-21 07:08:51.895 +00:00 [INF] - Executing command: "Saving edgeHub to store"
2018-12-21 07:08:51.900 +00:00 [INF] - Plan execution ended for deployment 8
2018-12-21 07:08:52.743 +00:00 [INF] - Updated reported properties
2018-12-21 07:08:57.811 +00:00 [INF] - HealthRestartPlanner is clearing restart stats for module 'tempSensor' as it has been running healthy for 00:10:00.
2018-12-21 07:08:57.814 +00:00 [INF] - HealthRestartPlanner is clearing restart stats for module 'edgeHub' as it has been running healthy for 00:10:00.
2018-12-21 07:08:57.815 +00:00 [INF] - Plan execution started for deployment 8
2018-12-21 07:08:57.818 +00:00 [INF] - Executing command: "Saving tempSensor to store"
2018-12-21 07:08:57.819 +00:00 [INF] - Executing command: "Saving edgeHub to store"
2018-12-21 07:08:57.820 +00:00 [INF] - Plan execution ended for deployment 8
2018-12-21 07:08:58.038 +00:00 [INF] - Updated reported properties
2018-12-21 07:09:03.239 +00:00 [INF] - Updated reported properties

这里是 edgeHub 的一些日志记录(还有很多,但似乎都是相同的例外):

2018-12-21 07:28:23.450 +00:00 [WRN] - Error sending messages to module bewaPi1/SampleModule2
System.OutOfMemoryException: Exception of type 'System.OutOfMemoryException' was thrown.
   at DotNetty.Buffers.HeapArena.NewChunk(Int32 pageSize, Int32 maxOrder, Int32 pageShifts, Int32 chunkSize)
   at DotNetty.Buffers.PoolArena`1.AllocateNormal(PooledByteBuffer`1 buf, Int32 reqCapacity, Int32 normCapacity)
   at DotNetty.Buffers.PoolArena`1.Allocate(PoolThreadCache`1 cache, PooledByteBuffer`1 buf, Int32 reqCapacity)
   at DotNetty.Buffers.PooledByteBufferAllocator.NewHeapBuffer(Int32 initialCapacity, Int32 maxCapacity)
   at DotNetty.Buffers.AbstractByteBufferAllocator.Buffer(Int32 initialCapacity, Int32 maxCapacity)
   at Microsoft.Azure.Devices.Edge.Hub.Mqtt.ByteBufferConverter.ToByteBuffer(Byte[] bytes) in /home/vsts/work/1/s/edge-hub/src/Microsoft.Azure.Devices.Edge.Hub.Mqtt/ByteBufferConverter.cs:line 39
   at Microsoft.Azure.Devices.Edge.Hub.Mqtt.ProtocolGatewayMessageConverter.FromMessage(IMessage message) in /home/vsts/work/1/s/edge-hub/src/Microsoft.Azure.Devices.Edge.Hub.Mqtt/ProtocolGatewayMessageConverter.cs:line 101
   at Microsoft.Azure.Devices.Edge.Hub.Mqtt.DeviceProxy.SendMessageAsync(IMessage message, String input) in /home/vsts/work/1/s/edge-hub/src/Microsoft.Azure.Devices.Edge.Hub.Mqtt/DeviceProxy.cs:line 73
   at Microsoft.Azure.Devices.Edge.Hub.Core.Device.DeviceMessageHandler.SendMessageAsync(IMessage message, String input) in /home/vsts/work/1/s/edge-hub/src/Microsoft.Azure.Devices.Edge.Hub.Core/device/DeviceMessageHandler.cs:line 256
   at Microsoft.Azure.Devices.Edge.Hub.Core.Routing.ModuleEndpoint.ModuleMessageProcessor.<>c__DisplayClass5_2.<<ProcessAsync>b__0>d.MoveNext() in /home/vsts/work/1/s/edge-hub/src/Microsoft.Azure.Devices.Edge.Hub.Core/routing/ModuleEndpoint.cs:line 98
2018-12-21 07:28:28.517 +00:00 [WRN] - Non retryable exception occurred while sending message.
System.OutOfMemoryException: Exception of type 'System.OutOfMemoryException' was thrown.
   at DotNetty.Buffers.HeapArena.NewChunk(Int32 pageSize, Int32 maxOrder, Int32 pageShifts, Int32 chunkSize)
   at DotNetty.Buffers.PoolArena`1.AllocateNormal(PooledByteBuffer`1 buf, Int32 reqCapacity, Int32 normCapacity)
   at DotNetty.Buffers.PoolArena`1.Allocate(PoolThreadCache`1 cache, PooledByteBuffer`1 buf, Int32 reqCapacity)
   at DotNetty.Buffers.PooledByteBufferAllocator.NewHeapBuffer(Int32 initialCapacity, Int32 maxCapacity)
   at DotNetty.Buffers.AbstractByteBufferAllocator.Buffer(Int32 initialCapacity, Int32 maxCapacity)
   at Microsoft.Azure.Devices.Edge.Hub.Mqtt.ByteBufferConverter.ToByteBuffer(Byte[] bytes) in /home/vsts/work/1/s/edge-hub/src/Microsoft.Azure.Devices.Edge.Hub.Mqtt/ByteBufferConverter.cs:line 39
   at Microsoft.Azure.Devices.Edge.Hub.Mqtt.ProtocolGatewayMessageConverter.FromMessage(IMessage message) in /home/vsts/work/1/s/edge-hub/src/Microsoft.Azure.Devices.Edge.Hub.Mqtt/ProtocolGatewayMessageConverter.cs:line 101
   at Microsoft.Azure.Devices.Edge.Hub.Mqtt.DeviceProxy.SendMessageAsync(IMessage message, String input) in /home/vsts/work/1/s/edge-hub/src/Microsoft.Azure.Devices.Edge.Hub.Mqtt/DeviceProxy.cs:line 73
   at Microsoft.Azure.Devices.Edge.Hub.Core.Device.DeviceMessageHandler.SendMessageAsync(IMessage message, String input) in /home/vsts/work/1/s/edge-hub/src/Microsoft.Azure.Devices.Edge.Hub.Core/device/DeviceMessageHandler.cs:line 256
   at Microsoft.Azure.Devices.Edge.Hub.Core.Routing.ModuleEndpoint.ModuleMessageProcessor.<>c__DisplayClass5_2.<<ProcessAsync>b__0>d.MoveNext() in /home/vsts/work/1/s/edge-hub/src/Microsoft.Azure.Devices.Edge.Hub.Core/routing/ModuleEndpoint.cs:line 98
2018-12-21 07:28:28.521 +00:00 [WRN] - Error sending messages to module bewaPi1/SampleModule2
System.OutOfMemoryException: Exception of type 'System.OutOfMemoryException' was thrown.
   at DotNetty.Buffers.HeapArena.NewChunk(Int32 pageSize, Int32 maxOrder, Int32 pageShifts, Int32 chunkSize)
   at DotNetty.Buffers.PoolArena`1.AllocateNormal(PooledByteBuffer`1 buf, Int32 reqCapacity, Int32 normCapacity)
   at DotNetty.Buffers.PoolArena`1.Allocate(PoolThreadCache`1 cache, PooledByteBuffer`1 buf, Int32 reqCapacity)
   at DotNetty.Buffers.PooledByteBufferAllocator.NewHeapBuffer(Int32 initialCapacity, Int32 maxCapacity)
   at DotNetty.Buffers.AbstractByteBufferAllocator.Buffer(Int32 initialCapacity, Int32 maxCapacity)
   at Microsoft.Azure.Devices.Edge.Hub.Mqtt.ByteBufferConverter.ToByteBuffer(Byte[] bytes) in /home/vsts/work/1/s/edge-hub/src/Microsoft.Azure.Devices.Edge.Hub.Mqtt/ByteBufferConverter.cs:line 39
   at Microsoft.Azure.Devices.Edge.Hub.Mqtt.ProtocolGatewayMessageConverter.FromMessage(IMessage message) in /home/vsts/work/1/s/edge-hub/src/Microsoft.Azure.Devices.Edge.Hub.Mqtt/ProtocolGatewayMessageConverter.cs:line 101
   at Microsoft.Azure.Devices.Edge.Hub.Mqtt.DeviceProxy.SendMessageAsync(IMessage message, String input) in /home/vsts/work/1/s/edge-hub/src/Microsoft.Azure.Devices.Edge.Hub.Mqtt/DeviceProxy.cs:line 73
   at Microsoft.Azure.Devices.Edge.Hub.Core.Device.DeviceMessageHandler.SendMessageAsync(IMessage message, String input) in /home/vsts/work/1/s/edge-hub/src/Microsoft.Azure.Devices.Edge.Hub.Core/device/DeviceMessageHandler.cs:line 256
   at Microsoft.Azure.Devices.Edge.Hub.Core.Routing.ModuleEndpoint.ModuleMessageProcessor.<>c__DisplayClass5_2.<<ProcessAsync>b__0>d.MoveNext() in /home/vsts/work/1/s/edge-hub/src/Microsoft.Azure.Devices.Edge.Hub.Core/routing/ModuleEndpoint.cs:line 98
2018-12-21 07:28:33.666 +00:00 [WRN] - Non retryable exception occurred while sending message.
System.OutOfMemoryException: Exception of type 'System.OutOfMemoryException' was thrown.
   at DotNetty.Buffers.HeapArena.NewChunk(Int32 pageSize, Int32 maxOrder, Int32 pageShifts, Int32 chunkSize)
   at DotNetty.Buffers.PoolArena`1.AllocateNormal(PooledByteBuffer`1 buf, Int32 reqCapacity, Int32 normCapacity)
   at DotNetty.Buffers.PoolArena`1.Allocate(PoolThreadCache`1 cache, PooledByteBuffer`1 buf, Int32 reqCapacity)
   at DotNetty.Buffers.PooledByteBufferAllocator.NewHeapBuffer(Int32 initialCapacity, Int32 maxCapacity)
   at DotNetty.Buffers.AbstractByteBufferAllocator.Buffer(Int32 initialCapacity, Int32 maxCapacity)
   at Microsoft.Azure.Devices.Edge.Hub.Mqtt.ByteBufferConverter.ToByteBuffer(Byte[] bytes) in /home/vsts/work/1/s/edge-hub/src/Microsoft.Azure.Devices.Edge.Hub.Mqtt/ByteBufferConverter.cs:line 39
   at Microsoft.Azure.Devices.Edge.Hub.Mqtt.ProtocolGatewayMessageConverter.FromMessage(IMessage message) in /home/vsts/work/1/s/edge-hub/src/Microsoft.Azure.Devices.Edge.Hub.Mqtt/ProtocolGatewayMessageConverter.cs:line 101
   at Microsoft.Azure.Devices.Edge.Hub.Mqtt.DeviceProxy.SendMessageAsync(IMessage message, String input) in /home/vsts/work/1/s/edge-hub/src/Microsoft.Azure.Devices.Edge.Hub.Mqtt/DeviceProxy.cs:line 73
   at Microsoft.Azure.Devices.Edge.Hub.Core.Device.DeviceMessageHandler.SendMessageAsync(IMessage message, String input) in /home/vsts/work/1/s/edge-hub/src/Microsoft.Azure.Devices.Edge.Hub.Core/device/DeviceMessageHandler.cs:line 256
   at Microsoft.Azure.Devices.Edge.Hub.Core.Routing.ModuleEndpoint.ModuleMessageProcessor.<>c__DisplayClass5_2.<<ProcessAsync>b__0>d.MoveNext() in /home/vsts/work/1/s/edge-hub/src/Microsoft.Azure.Devices.Edge.Hub.Core/routing/ModuleEndpoint.cs:line 98
2018-12-21 07:28:33.669 +00:00 [WRN] - Error sending messages to module bewaPi1/SampleModule2
System.OutOfMemoryException: Exception of type 'System.OutOfMemoryException' was thrown.
   at DotNetty.Buffers.HeapArena.NewChunk(Int32 pageSize, Int32 maxOrder, Int32 pageShifts, Int32 chunkSize)
   at DotNetty.Buffers.PoolArena`1.AllocateNormal(PooledByteBuffer`1 buf, Int32 reqCapacity, Int32 normCapacity)
   at DotNetty.Buffers.PoolArena`1.Allocate(PoolThreadCache`1 cache, PooledByteBuffer`1 buf, Int32 reqCapacity)
   at DotNetty.Buffers.PooledByteBufferAllocator.NewHeapBuffer(Int32 initialCapacity, Int32 maxCapacity)
   at DotNetty.Buffers.AbstractByteBufferAllocator.Buffer(Int32 initialCapacity, Int32 maxCapacity)
   at Microsoft.Azure.Devices.Edge.Hub.Mqtt.ByteBufferConverter.ToByteBuffer(Byte[] bytes) in /home/vsts/work/1/s/edge-hub/src/Microsoft.Azure.Devices.Edge.Hub.Mqtt/ByteBufferConverter.cs:line 39
   at Microsoft.Azure.Devices.Edge.Hub.Mqtt.ProtocolGatewayMessageConverter.FromMessage(IMessage message) in /home/vsts/work/1/s/edge-hub/src/Microsoft.Azure.Devices.Edge.Hub.Mqtt/ProtocolGatewayMessageConverter.cs:line 101
   at Microsoft.Azure.Devices.Edge.Hub.Mqtt.DeviceProxy.SendMessageAsync(IMessage message, String input) in /home/vsts/work/1/s/edge-hub/src/Microsoft.Azure.Devices.Edge.Hub.Mqtt/DeviceProxy.cs:line 73
   at Microsoft.Azure.Devices.Edge.Hub.Core.Device.DeviceMessageHandler.SendMessageAsync(IMessage message, String input) in /home/vsts/work/1/s/edge-hub/src/Microsoft.Azure.Devices.Edge.Hub.Core/device/DeviceMessageHandler.cs:line 256
   at Microsoft.Azure.Devices.Edge.Hub.Core.Routing.ModuleEndpoint.ModuleMessageProcessor.<>c__DisplayClass5_2.<<ProcessAsync>b__0>d.MoveNext() in /home/vsts/work/1/s/edge-hub/src/Microsoft.Azure.Devices.Edge.Hub.Core/routing/ModuleEndpoint.cs:line 98
2018-12-21 07:28:39.012 +00:00 [WRN] - Non retryable exception occurred while sending message.
System.OutOfMemoryException: Exception of type 'System.OutOfMemoryException' was thrown.
   at DotNetty.Buffers.HeapArena.NewChunk(Int32 pageSize, Int32 maxOrder, Int32 pageShifts, Int32 chunkSize)
   at DotNetty.Buffers.PoolArena`1.AllocateNormal(PooledByteBuffer`1 buf, Int32 reqCapacity, Int32 normCapacity)
   at DotNetty.Buffers.PoolArena`1.Allocate(PoolThreadCache`1 cache, PooledByteBuffer`1 buf, Int32 reqCapacity)
   at DotNetty.Buffers.PooledByteBufferAllocator.NewHeapBuffer(Int32 initialCapacity, Int32 maxCapacity)
   at DotNetty.Buffers.AbstractByteBufferAllocator.Buffer(Int32 initialCapacity, Int32 maxCapacity)
   at Microsoft.Azure.Devices.Edge.Hub.Mqtt.ByteBufferConverter.ToByteBuffer(Byte[] bytes) in /home/vsts/work/1/s/edge-hub/src/Microsoft.Azure.Devices.Edge.Hub.Mqtt/ByteBufferConverter.cs:line 39
   at Microsoft.Azure.Devices.Edge.Hub.Mqtt.ProtocolGatewayMessageConverter.FromMessage(IMessage message) in /home/vsts/work/1/s/edge-hub/src/Microsoft.Azure.Devices.Edge.Hub.Mqtt/ProtocolGatewayMessageConverter.cs:line 101
   at Microsoft.Azure.Devices.Edge.Hub.Mqtt.DeviceProxy.SendMessageAsync(IMessage message, String input) in /home/vsts/work/1/s/edge-hub/src/Microsoft.Azure.Devices.Edge.Hub.Mqtt/DeviceProxy.cs:line 73
   at Microsoft.Azure.Devices.Edge.Hub.Core.Device.DeviceMessageHandler.SendMessageAsync(IMessage message, String input) in /home/vsts/work/1/s/edge-hub/src/Microsoft.Azure.Devices.Edge.Hub.Core/device/DeviceMessageHandler.cs:line 256
   at Microsoft.Azure.Devices.Edge.Hub.Core.Routing.ModuleEndpoint.ModuleMessageProcessor.<>c__DisplayClass5_2.<<ProcessAsync>b__0>d.MoveNext() in /home/vsts/work/1/s/edge-hub/src/Microsoft.Azure.Devices.Edge.Hub.Core/routing/ModuleEndpoint.cs:line 98
2018-12-21 07:28:39.015 +00:00 [WRN] - Error sending messages to module bewaPi1/SampleModule2
System.OutOfMemoryException: Exception of type 'System.OutOfMemoryException' was thrown.
   at DotNetty.Buffers.HeapArena.NewChunk(Int32 pageSize, Int32 maxOrder, Int32 pageShifts, Int32 chunkSize)
   at DotNetty.Buffers.PoolArena`1.AllocateNormal(PooledByteBuffer`1 buf, Int32 reqCapacity, Int32 normCapacity)
   at DotNetty.Buffers.PoolArena`1.Allocate(PoolThreadCache`1 cache, PooledByteBuffer`1 buf, Int32 reqCapacity)
   at DotNetty.Buffers.PooledByteBufferAllocator.NewHeapBuffer(Int32 initialCapacity, Int32 maxCapacity)
   at DotNetty.Buffers.AbstractByteBufferAllocator.Buffer(Int32 initialCapacity, Int32 maxCapacity)
   at Microsoft.Azure.Devices.Edge.Hub.Mqtt.ByteBufferConverter.ToByteBuffer(Byte[] bytes) in /home/vsts/work/1/s/edge-hub/src/Microsoft.Azure.Devices.Edge.Hub.Mqtt/ByteBufferConverter.cs:line 39
   at Microsoft.Azure.Devices.Edge.Hub.Mqtt.ProtocolGatewayMessageConverter.FromMessage(IMessage message) in /home/vsts/work/1/s/edge-hub/src/Microsoft.Azure.Devices.Edge.Hub.Mqtt/ProtocolGatewayMessageConverter.cs:line 101
   at Microsoft.Azure.Devices.Edge.Hub.Mqtt.DeviceProxy.SendMessageAsync(IMessage message, String input) in /home/vsts/work/1/s/edge-hub/src/Microsoft.Azure.Devices.Edge.Hub.Mqtt/DeviceProxy.cs:line 73
   at Microsoft.Azure.Devices.Edge.Hub.Core.Device.DeviceMessageHandler.SendMessageAsync(IMessage message, String input) in /home/vsts/work/1/s/edge-hub/src/Microsoft.Azure.Devices.Edge.Hub.Core/device/DeviceMessageHandler.cs:line 256
   at Microsoft.Azure.Devices.Edge.Hub.Core.Routing.ModuleEndpoint.ModuleMessageProcessor.<>c__DisplayClass5_2.<<ProcessAsync>b__0>d.MoveNext() in /home/vsts/work/1/s/edge-hub/src/Microsoft.Azure.Devices.Edge.Hub.Core/routing/ModuleEndpoint.cs:line 98

所以问题是由System.OutOfMemoryExceptions引起的。但是是什么导致了这些异常?

Update2:这似乎是一个已知问题(参见 here),可以通过设置 OptimizeForPerformance 来解决错误。我会试试这个,看看它是否有效。

问题似乎与 https://docs.microsoft.com/en-us/azure/iot-edge/troubleshoot#stability-issues-on-resource-constrained-devices

请参考 link 并在部署清单中关闭 OptimizeForPerformance。

由于 edgeHub 模块中的 System.OutOfMemoryExceptions,模块之间的消息路由不起作用。问题被描述和讨论 here.

Microsoft 已经实施了一个解决方案,描述为 here

简而言之:如果 运行 IotEdge Solutions on Raspberry Pi 环境变量 OptimizeForPerformance 必须设置为 false.