Apache & # 8594; multiple MySQL connections and one connection

I was thinking why Apache starts a new connection to MySQL server for every page request? Why doesn't it just close the ONE connection at any time and send all sql queries over that one connection (obviously with a client id attached to each req)?

It cuts down on handshake time overhead and a couple of other benefits I see.

It's like plugging in your computer every time you want to use it. Why go to a power outlet every time you can just leave it plugged in?

+2


source to share


3 answers


reason: easier.

to reuse connections you need to design and implement a connection pool. this adds another almost layer of code that needs to be developed, maintained, etc.



plus pooled connections invite a whole class of bugs that you must observe when developing your application. for example, if you define a custom variable, but the next user of that connection omits the code path that is maintained based on whether the variable exists or not, then that user is running the wrong code. other issues include: temporary tables, transaction locks, session variables, etc., it all becomes very difficult to duplicate as it depends on the subsequent actions of two different users who do not appear to have any connections to each other.

Also, the mysql connection overhead is tiny. in my experience, pooling increases the number of users that a server can support very much.

+2


source


MySQL

does not support multiple sessions over one connection.

Oracle

for example allows this, and you can configure Apache

mutliplex to allow multiple logical sessions over a single connection TCP

.

This is a limitation of languages MySQL

, not Apache

or script.



There are modules that can do session concatenation:

  • Provide multiple connections
  • Choose a free connection on demand
  • Create additional connections if no free connection is available.
+2


source


+1


source







All Articles