2

I have a python script that is currently connecting to my mysql database every 60 seconds, checking something, then closing the connection, so every minute I am doing this open/close of the connection. Is it more expensive for me to do this, or to just leave the connection open since I'm executing my code so frequently?

What are the upsides and downsides of keeping the connection open for maybe 8 hours at a time, or opening and closing it 480 times over the course of those eight hours?

3
  • See this thread Commented Feb 1, 2017 at 18:54
  • Ideally you keep a connection pool, it saves a lot of overhead. Once a minute won't kill you, but once every request might if you're getting hundreds of requests per second. Commented Feb 1, 2017 at 19:01
  • For a continuous job, I'd rather keep my connection opened. Commented Feb 1, 2017 at 19:27

1 Answer 1

0

Even if it is more expensive, it is better doing it the way you have it because you're holding a connection for a shorter period to allow other connections to come in.

It will be more resilient to database restarts as well.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.