main website home
  • About this blog

    This blog features updates, opinions, and technical notes from Caucho engineers about Caucho products, the enterprise Java industry, and PHP. Caucho Technology is the creator of the Resin Application Server and the Quercus PHP in Java engine. A leader in Java performance since 1998, Caucho is a Sun JavaEE licensee with over 9000 customers worldwide.
  • Tags

    ajaxworld bam candi cdi cloud cluster comet configuration deploy devoxx eclipse ejb embedded flash flex google app engine hessian hmtp ioc java ee 6 javaone javazone jms messaging newsletter nyjug osgi php pomegranate quercus resin resin 4.0 REST servlet sfjug silicon valley code camp spring testing training tssjs watchdog webbeans web profile websockets wordpress
  • Meta

    • Register
    • Log in
    • Entries RSS
    • Comments RSS
    • WordPress.org
« BAM! Flash! (and Hessian)
Caucho at TSSJS »

Load balanced database connection pools

You might have used Resin’s built-in database connection pooling, but did you know that Resin can also load balance across multiple database servers in the backend transparently? It’s as simple as adding more database drivers to your database pool. What’s more, Resin supports database server failover and even failover pools!

For example, say you’ve got two database servers that are mirrored in the backend. You can have Resin use round-robin load balancing to switch new connections between the two servers using the following:

<web-app xmlns="http://caucho.com/ns/resin">
<database jndi-name="jdbc/test">
    <!-- primary server -->
    <driver type="com.mysql.jdbc.jdbc2.optional.MysqlConnectionPoolDataSource">
      <url>jdbc:mysql://192.168.1.34.5:3306/test</url>
      <user>test_user</user>
      <password>test_password</password>
    </driver> 

    <!-- secondary server -->
    <driver type="com.mysql.jdbc.jdbc2.optional.MysqlConnectionPoolDataSource">
      <url>jdbc:mysql://192.168.1.34.6:3306/test</url>
      <user>test_user</user>
      <password>test_password</password>
    </driver>
</database>
</web-app>

Now imagine that you’ve got a primary server and a backup that you don’t want to use until the primary fails. You can use the <backup-driver> tag to specify that:

<web-app xmlns="http://caucho.com/ns/resin">
<database jndi-name="jdbc/test">
    <!-- primary server -->
    <driver type="com.mysql.jdbc.jdbc2.optional.MysqlConnectionPoolDataSource">
      <url>jdbc:mysql://192.168.1.34.5:3306/test</url>
      <user>test_user</user>
      <password>test_password</password>
    </driver> 

    <!-- backup server -->
    <backup-driver type="com.mysql.jdbc.jdbc2.optional.MysqlConnectionPoolDataSource">
      <url>jdbc:mysql://192.168.1.34.6:3306/test</url>
      <user>test_user</user>
      <password>test_password</password>
    </driver>
</database>
</web-app>

If you’ve got multiple <drivers> and a single <backup-driver>, the drivers will be load balanced in a round robin fashion until they all fail, then the backup will be used. If you have multiple backups, they are also balanced using round robin once all the primary drivers have failed. The order that they appear in the configuration determines the order in which they are load balanced. You can find the in depth documentation of the <driver> and <backup-driver> tags here: Database tag configuration.

If you have a fancy database driver that does load balancing, you probably don’t want to use it in conjunction with this feature. Check you driver documentation for details.

Tags: database, resin

This entry was posted on Friday, March 13th, 2009 at 4:30 pm and is filed under Engineering. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

Leave a Reply

You must be logged in to post a comment.


Caucho Technology is proudly powered by WordPress and Quercus®
Entries (RSS) and Comments (RSS).

  • HOME |
  • CONTACT US |
  • DOCUMENTATION |
  • BLOG |
  • WIKI 4 |
  • WIKI 3 |
  • Resin: Java Application Server
Copyright (c) 1998-2012 Caucho Technology, Inc. All rights reserved.
caucho® , resin® and quercus® are registered trademarks of Caucho Technology, Inc.
resin® is a cloud optimized, java® application server that supports the java ee webprofile ®