Different Bytes Received under windows and linux when running same .NET 6 application connected to SQL Server

86 Views Asked by At

During the analysis of some Prometheus metrics I found an interesting difference in the received network traffic whether an .NET 6 application runs under Linux (Ubuntu 22.04.3 LTS) or Windows (Windows Server 2019 Standard) fetching data from a Microsoft SQL Server.

When the application runs under windows it seems as if the bytes transferred in the response from the SQL Server are not included in the prometheus metric system_net_sockets_bytes_received. In an example test I had a value of 2.566 bytes here. If I compile the same application to Linux and do the same test, this metric has 91.470.730 bytes.

Has someone an explanation for this? I could not find any information for this behaviour in the web. The SQL Server tells me in sys.dm_exec_connections that both connections use TCP (column net_transport).

Here some code snippets to recreate the scenario. I use the nuget packages prometheus-net (8.0.1), prometheus-net.AspNetCore (8.0.1) and 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();

Test-Logic:

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");
}
0

There are 0 best solutions below