FreeRTOS / iot-reference-esp32

MIT License
75 stars 45 forks source link

Set MQTT connect and receive timeout. #104

Closed kvp1703 closed 1 week ago

kvp1703 commented 1 month ago

Setting connect and receive timeouts for faster OTA through newly introduced APIs.

kar-rahul-aws commented 1 month ago

Hi @kvp1703 Thanks for raising the PR. Are we facing any compilation issue or seeing performance drop without this code addition? Just wanted to understand the use case for making this change .

Thanks.

aggarg commented 3 weeks ago

@kvp1703 Would you please respond to the question from @AniruddhaKanhere ?

avsheth commented 1 week ago

Hi Aniruddha, Apologies for the delayed response.

As you pointed out, Agent is designed to work with non-blocking socket, however, earlier, Espressif's transport layer had recv socket in blocking mode with timeout of 1 second. And this timeout was applicable to all network ops, i.e. connect, recv and send. We added new set of APIs in the recent esp-aws-iot upgrade, to independently set timeouts for each of them, since it was observed that connect, at times, takes longer than a second on slower network, whereas coreMQTT Agent works best with smaller recv timeout.

This change reduced recv wait time from 1 second to 100ms, resulting in better OTA performance. It can be set to 0 as well to have a true non-blocking behaviour. Timeout APIs also allow dynamically changing timeouts based on application's requirement.

Hope this helps.