Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

订阅高并发topic场景会存在内存泄漏 #1947

Open
colincodefirst opened this issue Mar 11, 2024 · 4 comments
Open

订阅高并发topic场景会存在内存泄漏 #1947

colincodefirst opened this issue Mar 11, 2024 · 4 comments
Labels
bug Something isn't working

Comments

@colincodefirst
Copy link

Verification

screenshot-20240311-131946

@colincodefirst colincodefirst added the bug Something isn't working label Mar 11, 2024
@colincodefirst
Copy link
Author

colincodefirst commented Mar 11, 2024

screenshot-20240311-134723

// See https://aka.ms/new-console-template for more information
using MQTTnet;
using MQTTnet.Client;

Console.WriteLine("Hello, World!");

var mqttFactory = new MqttFactory();
var mqttClient = mqttFactory.CreateMqttClient();

var mqttClientOptions = new MqttClientOptionsBuilder()
     .WithTcpServer("10.132.105.8")
     .WithClientId("ebb46a457522466882bdb6d316fa29f3")
     .Build();

// Setup message handling before connecting so that queued messages
// are also handled properly. When there is no event handler attached all
// received messages get lost.
mqttClient.ApplicationMessageReceivedAsync += e =>
{
    Console.WriteLine("Received application message.");
    Thread.Sleep(500);
    return Task.CompletedTask;
};

await mqttClient.ConnectAsync(mqttClientOptions, CancellationToken.None);

var mqttSubscribeOptions = mqttFactory.CreateSubscribeOptionsBuilder()
.WithTopicFilter(
    f =>
    {
        f.WithTopic("/iothub/#");
    })
.Build();

await mqttClient.SubscribeAsync(mqttSubscribeOptions, CancellationToken.None);

Console.ReadLine();

topic: /iothub/a
这个主题一秒钟有100条数据包

@SeppPenner
Copy link
Collaborator

Google Translate: 'Das Abonnieren von Themenszenarien mit hoher Parallelität kann zu Speicherverlusten führen'

@MD-V
Copy link
Contributor

MD-V commented Mar 13, 2024

@colincodefirst First I would suggest to replace Thread.Sleep(500); with await Task.Delay(TimeSpan.FromMilliseconds(500));
Does this change anything?

@SeppPenner
Copy link
Collaborator

@colincodefirst First I would suggest to replace Thread.Sleep(500); with await Task.Delay(TimeSpan.FromMilliseconds(500)); Does this change anything?

I agree, the rest of the code looks good for me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants