sil*_*ent 5 azure .net-core azure-functions azure-iot-edge
目前有两个主要选项可以在 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" };
}
}
Run Code Online (Sandbox Code Playgroud)
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"
}
}
Run Code Online (Sandbox Code Playgroud)
结果:
// .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
Run Code Online (Sandbox Code Playgroud)
为了科学起见,我也使用预编译函数 (.DLL) 进行了测试,在 v2 (.NET Core) 和 v1 (.NET Full Framework) 运行时。
.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
Run Code Online (Sandbox Code Playgroud)
天啊。如果您实际上处理一些 IO 而不仅仅是从内存中返回 16 个字节,事情看起来可能会有所不同。但是它就是这样啊。如果您不需要函数为您提供的额外好处,请使用原始 dotnet。
由于除了性能方面之外我没有得到更多答案,这是我最后的看法:
对于任何其他自定义模块,我很可能会去构建您自己的东西。如前所述,从模板开始,编写自己的模块非常简单。
希望对其他人也有帮助!(这不是微软的官方答案;))
您可以在我的 github 存储库中找到不同触发边缘函数的一些示例:https://github.com/sebader/azureiotedge/tree/master/edge-functions
| 归档时间: |
|
| 查看次数: |
572 次 |
| 最近记录: |