You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I've noticed that ASP net apps that consume MQTT messages also use a lot more memory than console apps that subscribe to the same data.
The memory never seems to be released. Running dotMemory shows that the app uses a lot of unmanaged memory
Which component is your bug related to?
Client, version 4.3.7.1207
Memory consumption of the Producer console app, Consumer console app and Consumer Asp Net 6 app:
Create a console app that pushes data to the bus:
Program.cs:
using System.Text;using System.Text.Json;using MQTTnet;using MQTTnet.Client;varfactory=new MqttFactory();varclient= factory.CreateMqttClient();varoptions=new MqttClientOptionsBuilder().WithClientId("SenderClient").WithTcpServer("localhost",1883).Build();await client.ConnectAsync(options, CancellationToken.None);vardto=new LargeDto
{Id=1,Name="Sample",Data=newbyte[1024*50]};varjsonData= JsonSerializer.Serialize(dto);varmessage=new MqttApplicationMessageBuilder().WithTopic("large/dto").WithPayload(Encoding.UTF8.GetBytes(jsonData)).WithQualityOfServiceLevel(MQTTnet.Protocol.MqttQualityOfServiceLevel.AtMostOnce).Build();while(true){await client.PublishAsync(message, CancellationToken.None);await Task.Delay(1);}await client.DisconnectAsync();publicclassLargeDto{publicintId{get;set;}publicstringName{get;set;}publicbyte[] Data {get;set;}}
Create an ASP Net web API (tested both .Net 6 and .Net 8)
Program.cs:
using WebApplication1;varbuilder= WebApplication.CreateBuilder(args);
builder.Services.AddHostedService<MqttHostedService>();varapp= builder.Build();
app.MapGet("/",()=>"Hello World!");
app.Run();
@xljiulang Thanks for your reply. When forcing the ASP net app to use workstation GC, i see very similar memory usage to the console app, like you said.
When using Server GC though, even when disconnecting to the MQTT server and disposing the client, the memory never seems to be released, even when i force a GC. Not sure if this is related to MQTTNet or if it's just how .Net works in this mode.
I've noticed that ASP net apps that consume MQTT messages also use a lot more memory than console apps that subscribe to the same data.
The memory never seems to be released. Running dotMemory shows that the app uses a lot of unmanaged memory
Which component is your bug related to?
Memory consumption of the Producer console app, Consumer console app and Consumer Asp Net 6 app:
Create a console app that pushes data to the bus:
Program.cs:
Create an ASP Net web API (tested both .Net 6 and .Net 8)
Program.cs:
MqttHostedService.cs
The text was updated successfully, but these errors were encountered: