Sunday, March 24, 2019

Increasing the number of MySQL connections



What is the best way to increase the max connections?




I plan on hitting my DB with a lot of connections (hundreds/thousands per second, they will open and close pretty quick from a multi threaded app). I am running MySQL on Ubuntu.


Answer



First answer is DON'T. In almost all scenarios a high amount of max connections is bad, as you will be wasting a large amount of resources for very little gain. Instead what you should be doing is to create a connection pool and reuse your connections. It will give you way better performance (both in ram and latency), especially if you are doing thousands of transactions per second.



To change the max connections value you use max connections:
http://dev.mysql.com/doc/refman/5.5/en/server-system-variables.html#sysvar_max_connections



Your OS and RAM is likely the limiting factor. Unless you have a huge amount of ram you are unlikely to be able to serve more than a few thousand connections at the same time.



Also, have a look at http://dev.mysql.com/doc/refman/5.5/en/too-many-connections.html



No comments:

Post a Comment

linux - How to SSH to ec2 instance in VPC private subnet via NAT server

I have created a VPC in aws with a public subnet and a private subnet. The private subnet does not have direct access to external network. S...