paul B
paul B

Reputation: 206

max_user_connections and ajax

Certain pages on my site are populated via numerous ajax calls, often 20+ ajax calls running asynchronously. The problem I'm having is that each call is creating a new mysql_connection, causing me to receive the 'max_user_connections' error, which I'm told is capped off at 20. I've tried turning async off, but as the JQuery documentation states, this will often freeze up the page. I have considered turning this into 1 ajax call and letting php perform the loop, but the idea was to display each element as it becomes available (some of the data is gathered from external sources, thus the timing can vary)

Is this something that can be fixed with mysql_pconnect?

Upvotes: 0

Views: 379

Answers (2)

symcbean
symcbean

Reputation: 48357

Is this something that can be fixed with mysql_pconnect?

No - you need to either:

1) increase the number of connections mysql will handle (not recommended - not a scalable solution without replication)

2) improve the speed of the ajax call handler (e.g. query tuning, database/opcode/http level caching)

3) decrease the frequency of the ajax calls - e.g. by skiping the call if the last one occurred within 500msec

Upvotes: 1

Shamit Verma
Shamit Verma

Reputation: 3827

20+ Ajax calls are a concern even in absence of MySQL issue. Browser would not make these 20 calls simultaneously since it caps max http connection (to a single domian) to 2,4 or 8.

I would combine these requests and bring number of Ajax calls down to 6 - 8. As you mentioned, rest of calls get data from external sources. Do these calls talk to MySQL as well?
In addition, these things might help:

  1. Can you cache some of things (E.g. username , user full name) in http session
  2. Can you cache some data out of MySQL into memcached or even a file ? When data becomes available, cache can be updated.

Upvotes: 0

Related Questions