7

A Linux box sends measurements to AWS-RDBMS. A python script opens and closes the connection only long enough to upload data to the database (sessions is closed immediately after update). The alternative is that the box opens up an indefinite session to the database and update the RDBMS: not sure what problems would be with this if the internet connection failed and unsure of the degree of the connection's 'persistence' when faced with unstable internet connection. At scale, there could be hundreds of measurement boxes uploading data to the RDBMS.

What is the best practice with regard to python IoT session connection duration? Is it best practice to close the session after transmitting the data? Maybe define an idle time that starts after data is transmitted: if the idle time reaches more than a predefined amount of time then close the channel. Bonus for any explanation of the why behind the best practice.

Perhaps this question is dependent on the platform? i.e. RDBMS vs AWS Greengrass?

  • 2
    It might help you to get more specific answers if you explain exactly what you're looking for when you say best practices — it's not always clear what 'best practices' actually means. Do you have a specific concern about your setup (e.g. "will this perform well?") that you could edit to include? – Aurora0001 Jan 6 '18 at 10:53
  • With this sort of question, it always helps to give a bit more context around why you are asking the question. As it stands, it's rather out-of-context (and on any other stack might look rather like a homework question - although I'm not suggesting it actually is this time) – Sean Houlihane Jan 9 '18 at 10:09
  • I appreciate the comments to add more detail / context: any 'nudges' in the form of specific questions would be appreciated and would accelerate shaping the question. – gatorback Jan 9 '18 at 15:41
  • I'm voting to close this question as off-topic because it's just another generic socket coding question, with the two alternatives well explained on hundreds, if not thousands, of web sites, including many answers on S.O – Mawg says reinstate Monica Jan 15 '18 at 7:24
2

The variables which IoT bring to the party here are, at a minimum, scale and energy. You might also consider security/resilience as being subject to different constraints compared with how this question might have been answered 5 years ago. The 'root' question on SO is already 7 years old and not hugely popular.

The frequency of transactions and the cost of setting up an authenticated connection is probably the primary driver, both in terms of data bandwidth and energy costs.

Is there an cost to leaving the connection open? How much more effort will you need to manage a 'mostly persistent' connection compared to the more trivial 'open-use-close'? Which approach will result in resource contention fastest (assuming your product is planned to scale massively)?

Are you likely to migrate your code/protocol further to the edge of the network (or migrate the cloud functionality closer to the edge) in the future? These potential migrations might change your constraints, or you might prefer to defer the potential software investment.

| improve this answer | |
1

Although you are using the session for IOT, this is *not an IOT question, just a general sockets question, and, as such, there are many, many, many answers on Google and on Stack Overflow.

Basically, there is no "correct" answer, you just need to consider your situation.

Generally speaking, it is easier to implement "close after every transaction", as you don't need as much "ooops, my currently open session just closed unexpectedly" code. That is the approach that I always take, and have seen most often used in industry.

However, if you need to send frequent packets (size is not important, just the frequency), then the overhead of closing & reopening after every packet can lead to performance issues.

You pays your money, you takes your pick :-)

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.