You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

.NET 6程序连接SQL Server时Windows与Linux接收字节数差异问询

.NET 6程序跨平台SQL Server网络流量Prometheus指标差异问题

在分析Prometheus指标时发现,运行于Linux(Ubuntu 22.04.3 LTS)和Windows Server 2019 Standard的.NET 6程序,从Microsoft SQL Server获取数据时,接收网络流量的指标统计存在显著差异:

  • Windows环境下,Prometheus指标system_net_sockets_bytes_received未计入SQL Server响应的传输字节,测试值仅2566字节
  • Linux环境下,该指标值为91470730字节

通过SQL Server的sys.dm_exec_connections查询确认,两个环境下程序均使用TCP连接,但目前未找到相关资料解释该现象。


复现依赖

使用的NuGet包版本:

  • prometheus-net(8.0.1)
  • prometheus-net.AspNetCore(8.0.1)
  • System.Data.SqlClient(4.7.0)

复现代码片段

Program.cs

using Prometheus;

var builder = WebApplication.CreateBuilder(args);

// Add services to the container.
builder.Services.AddRazorPages();

var app = builder.Build();

// Configure the HTTP request pipeline.
if (!app.Environment.IsDevelopment())
{
    app.UseExceptionHandler("/Error");
}
app.UseStaticFiles();

app.UseHttpMetrics();

app.UseRouting();

app.UseAuthorization();

app.MapRazorPages();

app.UseEndpoints(endpoints =>
{
    endpoints.MapControllers();
    endpoints.MapMetrics();
});

app.Run();

测试逻辑

public void TestReceviedBytes()
{
    SqlConnection conn = new SqlConnection("YOUR CONNECTION STRING");
    conn.Open();

    for (int i = 0; i < 100000; i++)
    {
        SqlCommand command = new SqlCommand(@"YOUR SELECT COMMAND", conn);

        using (SqlDataReader reader = command.ExecuteReader())
        {
            if (reader.Read())
            {
                Console.WriteLine(String.Format("{0}", reader["Id"]));
            }
            Console.WriteLine($"Fetched run {i}");
        }
    }

    conn.Close();
    Console.WriteLine("Done");
}

内容的提问来源于stack exchange,提问作者Mboe5000

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.08 11:29:59