Recent

Author Topic: How often can I query MySQL database from my program?  (Read 695 times)

Awesome Programmer

  • Sr. Member
  • ****
  • Posts: 451
  • Programming is FUN only when it works :)
    • Cool Technology
How often can I query MySQL database from my program?
« on: June 19, 2020, 08:57:18 pm »
Hi, I wrote a simple program in Lazarus that queries a remote MySQL database repeatedly over and over again every 10 seconds. After letting it run for about an hour, I noticed that the values I was receiving didn't match the current values in the database and at times the connection to the database from Lazarus program would completely disconnect. I don't understand.

Is this because of too many cached threads in the memory overloading the MySQL Server?
Could it be memory leak?
Do I have to clear the cache every time?
Or should I wait longer before initiating another MySQL Query?

Any hints or clues or help will be extremely appreciated. Thank you.

eljo

  • Sr. Member
  • ****
  • Posts: 468
Re: How often can I query MySQL database from my program?
« Reply #1 on: June 19, 2020, 09:40:13 pm »
Hi, I wrote a simple program in Lazarus that queries a remote MySQL database repeatedly over and over again every 10 seconds. After letting it run for about an hour, I noticed that the values I was receiving didn't match the current values in the database and at times the connection to the database from Lazarus program would completely disconnect. I don't understand.

Is this because of too many cached threads in the memory overloading the MySQL Server?
Could it be memory leak?
Do I have to clear the cache every time?
Or should I wait longer before initiating another MySQL Query?

Any hints or clues or help will be extremely appreciated. Thank you.
Sorry what you describe is a bit out of the normal behavior. 
As far as I know there is no limit on how many times or how often a query can be executed.

In some situations, depending on the transaction isolation level and the time the query is open you might get values that are out of sync with the database but that should never happen in a newly executed query unless you are using a single transaction for all your queries in which case try to use different transaction for each query.

In any case please provide a small sample application that demonstrates the problem so we can analyse  and see where is the problem.

winni

  • Hero Member
  • *****
  • Posts: 3197
Re: How often can I query MySQL database from my program?
« Reply #2 on: June 19, 2020, 11:28:12 pm »
Hi!

Just  give it a try:

I would close  lets say all 10 minutes  the database an reopen it again.
So the cache will be refreshed.

But really: that's not what a database is for.
Save your value in a simple file???

Winni

 

TinyPortal © 2005-2018