目前有两个主要选项可以在 Azure IoT Edge 上创建基于代码的自定义模块:
- 自定义模块(目前是 .NET Core,很快还有 Python 等)
- Azure Functions(目前仅 .NET Core)
所以现在我的问题是,当我想在 .NET Core (C#) 中编写自定义代码时,使用其中一个有什么好处?
函数所需的样板代码要少得多,但是性能之类的呢?
目前有两个主要选项可以在 Azure IoT Edge 上创建基于代码的自定义模块:
所以现在我的问题是,当我想在 .NET Core (C#) 中编写自定义代码时,使用其中一个有什么好处?
函数所需的样板代码要少得多,但是性能之类的呢?
我不知道。让我们板凳!...在 Windows 上,因为那是我得心应手的。CPU是酷睿i7-3770K。
.NET Core Web API(v2.1.3,中间件是任何dotnet new webapi
连接)—
public class ValuesController : Controller
{
public IEnumerable<string> Get()
{
return new string[] { "value1", "value2" };
}
}
Azure Functions 脚本宿主 (v2.0.11587.0) —
// run.csx
public static IEnumerable<string> Run(HttpRequest req)
{
return new string[] { "value1", "value2" };
}
// host.json
// Default "consoleLevel" is verbose which blocks on flushing stdout,
// performance suffered unnecessarily so i switched to "error".
{
"tracing": {
"consoleLevel": "error",
"fileLoggingMode": "debugOnly"
}
}
结果:
// .NET Core Web API
C:\lab\bomb>bombardier-windows-amd64.exe -n 654321 http://127.0.0.1:5000/api/values
Bombarding http://127.0.0.1:5000/api/values with 654321 requests using 125 connections
654321 / 654321 [===================================] 100.00% 23s
Done!
Statistics Avg Stdev Max
Reqs/sec 27744.21 6713.91 124074.44
Latency 4.45ms 200.44us 46.97ms
HTTP codes:
1xx - 0, 2xx - 654321, 3xx - 0, 4xx - 0, 5xx - 0
others - 0
Throughput: 6.69MB/s
// Functions script host with .csx
C:\lab\bomb>bombardier-windows-amd64.exe -n 654321 http://127.0.0.1:7071/api/HttpTrigger
Bombarding http://127.0.0.1:7071/api/HttpTrigger with 654321 requests using 125 connections
654321 / 654321 [===================================] 100.00% 5m31s
Done!
Statistics Avg Stdev Max
Reqs/sec 1976.64 181.69 4213.32
Latency 63.23ms 20.74ms 2.12s
HTTP codes:
1xx - 0, 2xx - 654321, 3xx - 0, 4xx - 0, 5xx - 0
others - 0
Throughput: 492.23KB/s
为了科学,我也在 v2 (.NET Core) 和 v1 (.NET Full Framework) 运行时上使用预编译函数 (.DLL) 进行了测试运行。
.NET Core Web API (v2.1.3): 27744 requests/sec
Functions script host (v2.0.11587.0) .csx: 1976 requests/sec
Functions script host (v2.0.11587.0) precompiled DLL: 2062 requests/sec
Functions script host (v1.0.11535.0) precompiled DLL: 4734 requests/sec
YMMV。如果您实际上处理一些 IO 而不只是从内存中返回 16 个字节,事情可能看起来会有所不同。但是它就是这样啊。如果您不需要 Functions 提供的额外好处,请使用原始 dotnet。
因为除了性能方面我没有得到任何答案,这是我最后的看法:
对于任何其他自定义模块,我很可能会去构建你自己的东西。如前所述,从模板开始,编写自己的模块非常简单。
希望对其他人也有帮助!(这不是微软的官方回答;))
您可以在我的 github 存储库中找到一些不同触发边缘函数的示例:https ://github.com/sebader/azureiotedge/tree/master/edge-functions