Martijn Hiemstra
Martijn Hiemstra

Reputation: 1170

MariaDB max connections

We have a big application that uses 40 microservices (Spring boot) that each have about 5 database connections to a mariadb server. That causes too many connection errors on our mariadb server. Default is 151 however I was thinking of just setting the max connections to 1000 to be on the safe side. I cant find anywhere on the Internet if this is possible or even wise. Our MariaDB is running standalone on a VPS with 8GB memory. It is not running in a docker container or something like that. It is run directly on the VPS.

What is the maximum connections advisable taking into consideration that we might scale up with our microservices?

Upvotes: 2

Views: 15726

Answers (1)

O. Jones
O. Jones

Reputation: 108651

You can scale up your max_connections just fine. Put a line like

max_connections=250

in your MariaDB my.cnf file. But don't just set it to a very high number; each potential connection consumes RAM, and with only 8GiB you need to be a bit careful about that.

If you give this command you'll get a bunch of data about your connections.

SHOW STATUS LIKE '%connect%';

The important ones to watch:

  • Connection_errors_max_connections The number of connection attempts that failed because you ran out of connection slots.
  • Connections The total number of connections ever handled
  • Max_used_connections The largest number of simultaneous connections used.
  • Max_used_connections_time The date and time when the server had its largest number of connections.

The numbers shown are cumulative since the last server boot or the most recent FLUSH STATUS; statement.

Keep an eye on these. If you run short you can always add more. If you have to add many more connections as you scale up, you probably will need to provision your VPS with more RAM. The last two are cool because you can figure out whether you're getting hammered at a particular time of day.

And, in your various microservices be very careful to use connection pools of reasonable maximum size. Don't let your microservices grab more than ten connections unless you run into throughput trouble. You didn't say what client tech you use (nodejs? dotnet? php? Java?) so it's hard to give you specific advice how to do that.

Upvotes: 7

Related Questions