Low Performance in Database Server

SYSTEM INFORMATION
OS type and version CentOS Linux 7.9.2009
Webmin version 2.202
Virtualmin version 7.30.4
Webserver version 2.102
Related packages MariaDB version 5.5.68

Hi everyone,

Recently, I am experiencing low database server performance and trying to figure out what the cause may be.
Attached, please find database connections. What concerns for the moment is:

  1. the number of connections with “sleep” mode
  2. Connections from unauthenticated user
    I wonder if these are normal and what else I should possibly look at.
    Thanks in advance,
    Mima

Someone recently found and posted some settings to help with a Wordpress? site. That might give you a start in some useful tuning.

IF you want to try something like that before upgrading your OS of choice. :wink:

(a couple of decades ago the answer was ALWAYS “reindex”. :smiley:

1 Like

But only if they are well designed (table structure even more so).

Does that mean some programing languages don’t handle system calls very well or something else? I have produced some really wakki structures and found some languages seem to cope better than others

No - just that it amazes me just how many seem to take no effort in designing their DB (of any flavor) and seem to believe in one big table (containing everything from images to goodness knows what) with no index.
and just assume an index solves everything!

So that assumes no one understands the sql join comand, and yes a flat table can be awful, but if images are to be included may be this should be a reference to the image rather than the image itself so the html app can just reference it, I thought that was school boy stuff ?

Why do you believe this is concerning?

If they’re all from localhost, it just indicates some web application has invalid credentials. If they’re from another host, you probably shouldn’t have made Mariadb accessible to the internet (the default configuration only listens on localhost and there’s a firewall on a default Virtualmin system that does not open the Mariadb port). But, even if they are from another host, as long as they’re unauthenticated, it means nothing bad happened. They couldn’t login so they couldn’t do anything.

You need to be looking at what’s taking time. You could enable slow query logging and see which specific queries are chewing up resources. Odds are extremely high it’s a web application with one or more poorly constructed queries. You may be able to mitigate it by tuning your Mariadb configuration to suit your application(s).

You can also use something like MySQLTuner (GitHub - major/MySQLTuner-perl: MySQLTuner is a script written in Perl that will assist you with your MySQL configuration and make recommendations for increased performance and stability.) to tune your version of Mariadb for your specific hardware.

Also, make sure it’s not some fundamental underlying problem unrelated to the database. Do you have enough memory? If you’re swapping, you don’t have enough memory (having swap usage is not the same as swapping…look at avail Mem and buff/cache in top…if you have a reasonable amount free there, you’re OK, but if it’s low, it’s probably a sign you’re doing too much for the amount of memory you have). Disk speed? Probably not an issue on modern SSDs, but if you’re on a VM that’s on hardware shared by a lot of others, you might be running into limits.

1 Like

Also, the Mariadb folks have a whole folder of documentation about tuning and optimization: https://mariadb.com/kb/en/optimization-and-tuning/

But, keep in mind that tuning is context dependent. The default config is somewhat conservative (assuming a modest system without a lot of RAM), but just cranking up various caches and buffers may not actually help performance. It may just force the system to go into swap more, if you don’t have a lot of available memory, which would hurt performance.

Also, you can usually figure out which app(s) are causing trouble by looking at which ones are running the most and taking up the most CPU. Just look at top, and see which users are the most demanding. The default sort order is CPU usage, so the hardest working will be first, and the user running it is the domain owner, which allows you to narrow down what app(s) may be demanding.

1 Like

Thanks everyone for your valuable feedback, problem solved!
Optimizing the database improved the system but the main delays were related to php scripts which perform 3x faster now with Opcache.
Thanks again

1 Like

opcache is enabled by default when using PHP-FPM execution mode in Virtualmin. So, what did you change that improved performance? (Or were you using some other execution mode?)