Question

I have an iphone app that has been submitted that makes a lot of calls to the database to grab data. The data is pretty small. I have heard a lot about the my.cnf file and specifically max_connections and max_user_connections.
Here is what seems like the most important part of the my.cnf file for tweaking:

# * Fine Tuning
#
key_buffer      = 16M
max_allowed_packet  = 16M
thread_stack        = 192K
thread_cache_size       = 8
# This replaces the startup script and checks MyISAM tables if needed
# the first time they are touched
myisam-recover         = BACKUP
#max_connections        = 100
#table_cache            = 64
#thread_concurrency     = 10
#
# * Query Cache Configuration
#
query_cache_limit   = 1M
query_cache_size        = 16M
#

As you can see by default max connections is commented out. Does this mean there is no limit to the amount of connections? Also what happens when a user tries to use my app and max connections has been reached? Do they get an error immediately or does it wait to find a connection? How does this differ from max_user_connections? Sorry for all the questions, I don't know a whole lot about server configuration. Server is a linode 512.

Was it helpful?

Solution

The max_connections setting determines the maximum number of client connections. If all connections are used up, the next client that connects will receive the error Too many connections. The default value is 100, so if you have this option commented out, it will be 100.

The setting max_user_connections is the maximum number of connections per user. So if you set it to 10, user Bob could only have 10 connections before receiving the same error as above, whereas max_connections is the total for everybody. The setting max_user_connections defaults to the same value as max_connections if no value is specified.

When you receive the error, you will want to handle it gracefully. You can either try to reconnect, or give the user a friendly error message like, "System busy. Try again later."

On our production server, we have max_connections set to 1024. Your mileage may vary. If the queries are light weight, you may be able to increase the number. I'm guessing that 1024 might be a good place to start. Just ensure that your application server handles the error gracefully and adjust the number as you go.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top