Skip to content

AWS IoT Core - MQTT Subscribing Topic

0

Hello, I have 300 sensors and would like to get data from them simultaneously. I create a thread for the data coming from 20 or 30 sensors and create a client in this thread. Data comes from these 300 sensors simultaneously. And i have 300 topics of these 300 sensors. I can only read data from 130-140 different topics. Similarly, when I listen to only 100 topics, I can get 40 data. When I listen to 50 topics, I can get data from 25 topics. What is the reason for this? Can you help me please?

asked 2 years ago629 views

2 Answers
1
Accepted Answer

I create a thread for the data coming from 20 or 30 sensors and create a client in this thread.

So each thread of your application makes an independent connection to AWS IoT Core (using a unique client ID), and subscribes to 20 or 30 topics? If so, I don't immediately see a problem with quotas or limits. However, what's the message size? Each connection to the AWS IoT Core MQTT broker is limited to 100 messages per second or 512KB/s total throughput.

Full list of limits here: https://docs.aws.amazon.com/general/latest/gr/iot-core.html#message-broker-limits

You can check the IoT CloudWatch metrics to see if you're being throttled:

https://docs.aws.amazon.com/iot/latest/developerguide/metrics_dimensions.html#message-broker-metrics https://iotatlas.net/en/best_practices/aws/data_ingest/#monitor-your-iot-application-for-performance-and-to-detect-potential-issues-1

What client software are you using?

Unless your application has a genuine need to consume messages in near real time, it's generally not advisable for the application to connect directly to the AWS IoT Core MQTT broker. In general you are better advised to use the rules engine to subscribe to all topics, and route all the messages to a stream (like Kinesis data Streams) or queue (like SQS). And have your application consume from that stream or queue.

https://iotatlas.net/en/best_practices/aws/data_ingest/#decouple-ingest-from-processing-with-queues-and-streams-1

Data comes from these 300 sensors simultaneously.

Is this really necessary? If your workload will grow far beyond 300 sensors, I recommend that you re-consider this design, as it could be difficult to scale.

AWS
EXPERT

answered 2 years ago

EXPERT

reviewed 2 years ago

  • Thank you so much for your response. Yes, each thread makes an independent connection with unique client ID but i can not get the data from all topics which i subscribed.

    Also my message size about 400 chars in a string.

    I checked the Cloudwatch but there is nothing.

    The sensors send the message via C programming language. And i am trying to get data in Python. Could it be that 15-20 threads in Python do not capture messages? What do you think? Thanks in advance

  • OK the 400 byte message should mean you're not anywhere near 512KB/s. And if you're correct that there's no throttles recorded in the CloudWatch metrics, then it seems something else is going on.

    And i am trying to get data in Python. Could it be that 15-20 threads in Python do not capture messages? What do you think?

    Is the Python MQTT client library you're using thread safe? If you go down to just one thread (with 20-30 subscriptions), do you get all the data you'd expect for that many subscriptions?

    As mentioned, I think you should use AWS IoT Core rule engine anyway.

1

The issue you're experiencing with AWS IoT Core and MQTT subscriptions is likely related to scaling and performance limitations. There are several factors that could be contributing to this problem:

  1. Connection limits: AWS IoT Core has limits on the number of concurrent connections per account. If you're creating multiple clients, you might be hitting these limits.

  2. Subscription limits: There are limits on the number of subscriptions per connection. You may be exceeding these limits when trying to subscribe to many topics simultaneously.

  3. Message throughput: AWS IoT Core has limits on the number of messages that can be published or received per second per connection. With 300 sensors sending data simultaneously, you might be exceeding these throughput limits.

  4. Fan-in scenario: Your setup appears to be creating a significant fan-in scenario, where a single device (or client) is subscribing to a large number of topics that are being published to by many devices. This pattern is generally discouraged as it can lead to hitting per-device limits, particularly throughput limits per connection per second.

  5. Wildcard usage: If you're using wildcard subscriptions (like '#' or '+') to subscribe to multiple topics, this could be impacting performance and potentially causing unintended consequences.

To address these issues and improve your setup, consider the following recommendations:

  1. Use multiple connections: Instead of subscribing to all topics from a single client, distribute the subscriptions across multiple clients.

  2. Implement a hierarchical topic structure: Design your topic structure to allow for more efficient subscriptions using single-level wildcards ('+') rather than subscribing to individual topics for each sensor.

  3. Use AWS IoT Rules: Instead of having devices subscribe directly to many topics, consider using AWS IoT Rules to process incoming messages and route them to other AWS services or to specific devices that need the data.

  4. Optimize message frequency: If possible, reduce the frequency of messages from your sensors or batch messages to reduce the overall number of MQTT publishes.

  5. Monitor your AWS IoT Core metrics: Keep an eye on your account's metrics to ensure you're not hitting service limits.

  6. Consider using AWS IoT Basic Ingest: For telemetry data, this feature can help handle high volumes of incoming messages more efficiently.

By implementing these changes, you should be able to improve the scalability and reliability of your IoT system, allowing you to effectively manage data from all 300 sensors.

Sources
MQTT design best practices - Designing MQTT Topics for AWS IoT Core
MQTT topics - AWS IoT Core

answered 2 years ago

EXPERT

reviewed 2 years ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.