Reputation:

Connection Pooling In apache(Web sever)

I want to implement connection pooling in my web application.please suugest how can i implement that.

Upvotes: 0

Views: 1557

Answers (2)

Hartmut Behrens
Hartmut Behrens

Reputation: 175

While i do not have a definitive answer (and am also looking it), i can suggest the following (for a perl backend):

  • if you are using mod_perl2, then have a look at Apache::DBI (http://metacpan.org/pod/Apache::DBI). It has some drawbacks, which are listed on the page.
  • if you are using the perl DBI to connect to your database, then instead of using the connect() method call, use the connect_cached() method call.

Upvotes: 0

MarkR
MarkR

Reputation: 63538

I'd say that you have two problems:

  • You don't know whether you need connection pooling or not

and

  • If you find it's needed, you don't know how to implement it.

I'd initially work on the assumption that you DON'T need it, reusing connections is a (possibly premature) optimisation.

However, if you find that you really do need it, then how you do it will depend on the nature of your application-server.

  • If your application is "in-process" with Apache, you really have no option other than one-connection-per-process (or thread)
  • If your app is "out of process", e.g. connecting to Tomcat via mod_jk, then you can do what you like within the app server (Tomcat) which may include pooling connections to be used across multiple threads as appropriate.

Compelling reasons for using a new connection each time are:

  • No unwanted side effects from old connection state left by previous requests
  • You only connect when needed - less risk of blowing your database connections
  • Predictable performance - you can measure the time taken for the request, including creating the connection

The only compelling reason for reusing connections is the connection overhead time itself.

Some databases are relatively slow creating connections (Oracle) - others are much faster (MySQL). Some databases can be tuned to keep a pool of threads internally which they reuse (MySQL) which makes connecting even faster.

Upvotes: 2

Related Questions