Max connections

Discussion regarding Joomla! Performance issues.

Moderator: General Support Moderators

Forum rules
Forum Rules
Absolute Beginner's Guide to Joomla! <-- please read before posting, this means YOU.
Security and Performance FAQs
Forum Post Assistant - If you are serious about wanting help, you will use this tool to help you post.
Locked
frblondin
Joomla! Apprentice
Joomla! Apprentice
Posts: 14
Joined: Wed Sep 28, 2005 7:02 am

Max connections

Post by frblondin » Fri Dec 16, 2005 9:45 am

Hi all,

My host only allows 3 mysql connections. When there are a lot of connected users the mysql_connect throws an error and the user gets the temporary down screen. If he presses F5 it works again.

Why isn't there a loop in each database adapters that tries n times to connect and then throws an error at the end of the loop ?

For example I modified the __construct method of the mysql.php file (not tested):

Code: Select all

function __construct( $host='localhost', $user, $pass, $db='', $table_prefix='') {
		// perform a number of fatality checks, then die gracefully
		if (!function_exists( 'mysql_connect' )) {
			$this->_errorNum = 1;
			return;
		}
		$i = 0;
		$connected = false;
		// try 5 times when there is a connection attempt error (max. connections number can be reached for example)
		while ($i < 5 && !$connected) {
			if (phpversion() < '4.2.0') {
				if (!($connected = $this->_resource = @mysql_connect( $host, $user, $pass ))) {
					$this->_errorNum = 2;
				}
			} else {
				if (!($connected = $this->_resource = @mysql_connect( $host, $user, $pass, true ))) { // true forces a new connection even if the same username and password
					$this->_errorNum = 2;
				}
			}
			if ($connected && $db != '' && !mysql_select_db( $db, $this->_resource )) {
				$this->_errorNum = 3;
				$connected = false;
			}
			if (!$connected) {
				sleep(1);
			}
			$i++;
		}
		if (!$connected) {
			return;
		}

		parent::__construct($host, $user, $pass, $db, $table_prefix);
	}
Thanks
Thomas
Last edited by frblondin on Tue Dec 20, 2005 8:09 am, edited 1 time in total.

User avatar
RobS
Joomla! Ace
Joomla! Ace
Posts: 1366
Joined: Mon Dec 05, 2005 10:17 am
Location: New Orleans, LA, USA
Contact:

Re: Max connections

Post by RobS » Sat Dec 17, 2005 6:01 pm

Not sure about this, but, you may want to investigate using Persistent connections with MySQL.  I can't remember off the top of my head exactly, but, I think they are kind of intended to help with these type of situations. 

I believe they are designed to reduce the amount of overhead that it takes to start new connections for each request, etc.  By reusing the same open connections over and over again.  However, if there are errors in the code, and something locks and cannot free the connection, you will have problems pretty quickly.

Not sure if this will help, or hurt.  But, it might be worth a shot.  If it doesn't help, change hosts, I think 3 simultaneous connections is pretty lame unless you have a really really budget account. 

Good Luck,
Rob
Rob Schley - Open Source Matters
Webimagery - http://www.webimagery.net/ - Professional Consulting Services
JXtended - http://www.jxtended.com/ - Free and Commercial Joomla! Extensions

frblondin
Joomla! Apprentice
Joomla! Apprentice
Posts: 14
Joined: Wed Sep 28, 2005 7:02 am

Re : Max connections

Post by frblondin » Mon Dec 19, 2005 8:05 am

Thanks Rob

Message from my webhost:
The first method is to use PHP as a CGI "wrapper". When run this way, an instance of the PHP interpreter is created and destroyed for every page request (for a PHP page) to your web server. Because it is destroyed after every request, any resources that it acquires (such as a link to an SQL database server) are closed when it is destroyed. In this case, you do not gain anything from trying to use persistent connections -- they simply don't persist.
The mysql_pconnect is useless for me...

I can't see any drawback if I use my modification described above. It could be included into the core for each adapter?

Thomas

User avatar
spacemonkey
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 182
Joined: Fri Aug 12, 2005 7:50 pm
Location: Turin, Italy
Contact:

Re: Max connections

Post by spacemonkey » Mon Dec 19, 2005 6:01 pm

Hey Thomas,

We actually had to take out the persistent connections (back in the Mambo days) because of underpowered mass hosts, for this exact reason! hehe

So I wager going back in this direction is also a bad idea.

As for your changes, you are wanting to add more weight to a database class in order to accomodate poor hosting providers. I think the solution to that is by only using good hosting providers  :)

For only three simultaneous connections, and PHP as CGI (that means no chance at decent performance), if you are paying more than $0 for your hosting you are paying too much.

Sounds to me like you are having two problems:
1) there are only three connections open to the database at any time (that's horrific IMHO)
2) it is taking the scripts too long to execute, and those connections are not being freed up fast enough

Your fix may take care of your exact problem, but it's not something that is mainstream enough to be added to the core. We're actually refactoring and trying to improve performance, and making the database class bigger kinda goes against that strategy at the moment  ;)

frblondin
Joomla! Apprentice
Joomla! Apprentice
Posts: 14
Joined: Wed Sep 28, 2005 7:02 am

Re : Max connections

Post by frblondin » Mon Dec 19, 2005 7:29 pm

Thanks spacemonkey,

I know that 3 simultaneous connections is very low but I don't understand why such a solution could not be included into the core (not only because this solution was my suggestion  :P ). If you buy a software with a poor hardware you accept to be waiting and to get timeouts. You don't accept to get random errors.

You can consider this solution as a timeout: try to connect during 5 seconds and raise an error if no database connection is available. I can of course modify the devs for each new release for my websites but I think I'm not the only one running Joomla on a host such as mine/

My point of view: "drive Joomla in a ferrari or you'll have random bugs" sounds bad  ???

Hope you understand,
Thomas

User avatar
spacemonkey
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 182
Joined: Fri Aug 12, 2005 7:50 pm
Location: Turin, Italy
Contact:

Re: Max connections

Post by spacemonkey » Mon Dec 19, 2005 8:15 pm

frblondin wrote: My point of view: "drive Joomla in a ferrari or you'll have random bugs" sounds bad  ???
No you got it all wrong, here is the correct way of looking at it:  "Drive Joomla on the street and it is a lot nicer than in the river."  :laugh:

I understand your point. However, for those hosts that have performance problems (but no connection limits), your fix only slows down each load of the $database class. So this makes the problems worse for those folks.

I'm trying to find balance between performance issues and error checking. The logical choice would be to accomodate the most common scenario - and the 3-connection-limit is news to me.

Is this a common problem out there, or is this just with a few isolated hosts?

User avatar
Websmurf
Joomla! Hero
Joomla! Hero
Posts: 2230
Joined: Fri Aug 19, 2005 2:23 pm
Location: The Netherlands
Contact:

Re: Max connections

Post by Websmurf » Tue Dec 20, 2005 10:18 am

All hosting parties i've met and worked with do not limit per account, there is only a server wide limit which should be more than enough most of the times.
Adam van Dongen - Developer

- Blocklist, ODT Indexer, EasyFAQ, Easy Guestbook, Easy Gallery, YaNC & Redirect -
http://www.joomla-addons.org - http://www.bandhosting.nl

User avatar
Elpie
Joomla! Guru
Joomla! Guru
Posts: 903
Joined: Wed Aug 17, 2005 11:26 pm
Contact:

Re: Max connections

Post by Elpie » Tue Dec 20, 2005 12:43 pm

spacemonkey wrote: The logical choice would be to accomodate the most common scenario - and the 3-connection-limit is news to me.
Is this a common problem out there, or is this just with a few isolated hosts?
I've never heard of it before and doubt a 3-connection limit would be used by many hosts. Can't see how they can stay in business, unless their business is of the "sign 'em up, oversell like crazy and dont care if they leave" kind. 

OTOH, I don't know of many hosts that allow persistant connections anymore - way too many problems!
For Mambo assistance: http://forum.mambo-foundation.org
Open Source Research & Best Practice: http://osprojects.info

rebe_kini
Joomla! Fledgling
Joomla! Fledgling
Posts: 1
Joined: Fri May 19, 2006 5:54 pm

Re: Max connections

Post by rebe_kini » Fri May 19, 2006 6:00 pm

Here is a possible solution. It allows more than one MySql user to login to make an SQL query.

This was to fix a MySQL query limit problem.

It should help get thoughts started on a final solution for those with this problem. :)

http://forum.powweb.com/showthread.php?t=28309

cartika
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 108
Joined: Fri Aug 19, 2005 1:09 am
Contact:

Re: Max connections

Post by cartika » Mon May 22, 2006 5:13 am

We actually had to take out the persistent connections (back in the Mambo days) because of underpowered mass hosts, for this exact reason! hehe
p_connect is just that - it leaves connections active and not usable by anyone/anything else until the server is rebooted.  A shared environment, even a clustered environment with dedicated mysql resource servers can only accomodate x number of connections.  By disabling p_connect, you allow that connection pool to be shared and allow for some sites to use more then their fair share during that sites peak periods, then allows another site to use those same connections during its peak period.

However, none of this will help if the host has oversold their environment to a point where they need to limit connections to 3 in order to stay stable - that simply isnt acceptable - and at the very least, it doesnt meet the minimum required amount to host applications.
My point of view: "drive Joomla in a ferrari or you'll have random bugs" sounds bad  Huh
I wouldn't say that was accurate - however, you cannot drive Joomla (or any other production application) in a pinto - because any collision, even a small one, could result in an explosion.

May I recommend a taurus or a honda or something  :laugh:
www.cartika.com
High Availability, Load Balanced Joomla Hosting
HAL is Here!!

User avatar
mojito
Joomla! Guru
Joomla! Guru
Posts: 755
Joined: Wed Sep 07, 2005 10:18 pm
Location: London
Contact:

Re: Max connections

Post by mojito » Wed Mar 13, 2013 3:44 pm

We hava busy site and found running no matter how many cons joomla was taking, and we saw a lot of sleeping connections- so creating the need for new ones as they couldnt be replaced. So for us it was better to prevent persistant cons. This has so far given us better performance. We are running jomsocial and 2.5 Joomla with about 450 online members at a time.
:-[
I am a freelance SEO (https://cambs.eu) web designer and developer working with Wordpress and Joomla since Mambo.


Locked

Return to “Performance - 1.0.x”