 |
Account Login
|
 |
 |
Latest Articles
|
 |
 |
IRC Channel
|
 |
 |
Associates
|
 |
 |
Associates
|
 |
|
 |
 |
|
 |
07-27-2009, 09:02 AM
|
#1 (permalink)
|
|
The Contributor
Join Date: Mar 2009
Posts: 49
Thanks: 0
|
Maintaining MySQL Connections
I am using an external MySQL database server due to the high load I receive when having MySQL running locally. Both servers are located in the same datacenter, but I found that, whenever the connection from my server to the MySQL database server goes up to about 70++, the MySQL server blocks new connections. I have been trying to use persistent connections but it still opens up a lot of connections to the database server. Is there any suggestion how to maintain the number of connections?
|
|
|
|
07-27-2009, 12:15 PM
|
#3 (permalink)
|
|
The Acquainted
Join Date: Jul 2009
Location: Surrey
Posts: 105
Thanks: 1
|
MySQL by default is usually set to 100 connections, so you will need to up this. Persistent connections will give you more of these problems as the connection will remain open, trying using non-persistent connection if your application can handle it.
|
|
|
|
07-27-2009, 12:27 PM
|
#4 (permalink)
|
|
The Contributor
Join Date: Mar 2009
Posts: 49
Thanks: 0
|
But if I am to use non-persistent connections, it will definitely exceed the limit the external server set on (15 connections, not under my control). Since there will be more than 15 users going to be accessing the site at 1 time, what am I supposed to do?
|
|
|
|
07-27-2009, 01:04 PM
|
#5 (permalink)
|
|
The Acquainted
Join Date: Jul 2009
Location: Surrey
Posts: 105
Thanks: 1
|
Quite the opposite, if you use non-persistent connections, you can have many more people on the website at once as it will use the connection then drop it, which will allow someone else to open a connection.
15 persistent connections will only allow 15 users.
15 non-persistent connections will allow many more than 15 users.
NB: Glad I am not using my ruby on rails app on that connection, it pools 5 connections per user for speed :). So I would only be allowed 3 users :s
|
|
|
|
07-27-2009, 01:06 PM
|
#6 (permalink)
|
|
The Contributor
Join Date: Mar 2009
Posts: 49
Thanks: 0
|
Ok, I will be using non-persistent connection for a while, then I will report back what's the situation.
EDIT: I forgot to mention, my script uses Ajax call every single second from each user to get some stats, it won't be accessing the database but it certainly do connect to the database since I include the whole header together with the part connecting to the database. In this case, does any suggestion change?
|
|
|
|
07-27-2009, 01:28 PM
|
#7 (permalink)
|
|
The Contributor
Join Date: Mar 2009
Posts: 49
Thanks: 0
|
Ok, it doesn't work at all. It connects more than 50 connections at a time, are there anymore solutions? I tried setting max connection in php.ini but still didn't work.
|
|
|
|
07-27-2009, 02:13 PM
|
#8 (permalink)
|
|
Super Moderator
Join Date: Sep 2007
Location: Near you.
Posts: 791
Thanks: 241
|
LINK1
LINK2
Take a look at does links should be some more, information.
on the problem you are having.
and also you could try to google, "setting max connection + mysql" it did give me some info :)
-Cf
|
|
|
|
07-27-2009, 02:29 PM
|
#9 (permalink)
|
|
The Prestige
Join Date: Oct 2007
Location: Manchester, UK
Posts: 854
Thanks: 32
|
Quote:
Originally Posted by TheOnly92
Ok, it doesn't work at all. It connects more than 50 connections at a time, are there anymore solutions? I tried setting max connection in php.ini but still didn't work.
|
Did you edit your mysql config (typically called my.cnf in /etc), you can't edit mysql server settings via php.ini
you will need to add something like:
Code:
[mysqld]
set-variable = max_connections=200
of course you will need to restart mysql for this change to be effective.
You could also set it to 0, then mysql wont limit it at all, however this probably isn't a good idea.
__________________
mysql> SELECT * FROM `users` WHERE `users`.`clue` > 0;
Empty set (0.00 sec)
|
|
|
|
07-28-2009, 08:00 AM
|
#10 (permalink)
|
|
The Contributor
Join Date: Mar 2009
Posts: 49
Thanks: 0
|
First, I wish to state that the MySQL server is out of my control, I can't make any changes to it. Second, I hope to solve this problem by PHP.
By the way, please note that the external MySQL server is a shared hosting server. It blocks connection when the connection number reaches 50.
|
|
|
|
07-28-2009, 08:59 AM
|
#11 (permalink)
|
|
The Prestige
Join Date: Oct 2007
Location: Manchester, UK
Posts: 854
Thanks: 32
|
Then I doubt you will be able to do anything about it, unfortunately. To my knowlege you cannot set MySQL server variables via PHP.
__________________
mysql> SELECT * FROM `users` WHERE `users`.`clue` > 0;
Empty set (0.00 sec)
|
|
|
|
07-28-2009, 10:27 AM
|
#12 (permalink)
|
|
The Acquainted
Join Date: Jul 2009
Location: Surrey
Posts: 105
Thanks: 1
|
Quote:
Originally Posted by TheOnly92
First, I wish to state that the MySQL server is out of my control, I can't make any changes to it. Second, I hope to solve this problem by PHP.
By the way, please note that the external MySQL server is a shared hosting server. It blocks connection when the connection number reaches 50.
|
Unfortunately, you are s**t out of luck, you can not override this with php! As it would be a security risk. You could try and be clever by queuing the connections - but it wouldnt be easy.
|
|
|
|
07-28-2009, 10:31 AM
|
#13 (permalink)
|
|
The Prestige
Join Date: Oct 2007
Location: Manchester, UK
Posts: 854
Thanks: 32
|
Quote:
Originally Posted by JaoudeStudios
Unfortunately, you are s**t out of luck, you can not override this with php! As it would be a security risk. You could try and be clever by queuing the connections - but it wouldnt be easy.
|
Indeed! This is where shared hosting becomes inadequate you will have to think about getting your own server (be it a dedicated box or even a VPS) if you want to tweak server settings.
__________________
mysql> SELECT * FROM `users` WHERE `users`.`clue` > 0;
Empty set (0.00 sec)
|
|
|
|
07-28-2009, 11:47 AM
|
#14 (permalink)
|
|
The Contributor
Join Date: Mar 2009
Posts: 49
Thanks: 0
|
Some budget problems prevent me to get a vps...
|
|
|
|
07-28-2009, 12:19 PM
|
#15 (permalink)
|
|
The Contributor
Join Date: Mar 2009
Posts: 49
Thanks: 0
|
Ok, I will be using iptables method to solve this problem anyway. Thanks for all the help.
|
|
|
|
07-28-2009, 12:43 PM
|
#16 (permalink)
|
|
The Acquainted
Join Date: Jul 2009
Location: Surrey
Posts: 105
Thanks: 1
|
Quote:
Originally Posted by TheOnly92
Some budget problems prevent me to get a vps...
|
Check out rapidswitch.com, I remember their VPS being very cheap! I have a Dedicated box with them and so far they are pretty good.
|
|
|
|
|
The Following User Says Thank You to JaoudeStudios For This Useful Post:
|
|
07-28-2009, 12:59 PM
|
#17 (permalink)
|
|
The Prestige
Join Date: Oct 2007
Location: Manchester, UK
Posts: 854
Thanks: 32
|
They are quite reasonable, the dedi's arnt too bad either.
__________________
mysql> SELECT * FROM `users` WHERE `users`.`clue` > 0;
Empty set (0.00 sec)
|
|
|
|
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|