Monday September 08, 2008
TOTD #44: JDBC Connection Pooling for Rails on GlassFish v3
TOTD
#9 explained how to configure JDBC connection pooling for
Rails application deployed on GlassFish v2. There are several
benefits of using using the JDBC connection pools:
| ~/samples/jruby >~/tools/jruby-1.1.3/bin/jruby -S
rails
jndi_rails2 -d mysql ~/samples/jruby/jndi_rails2 >~/tools/jruby-1.1.3/bin/jruby script/generate scaffold runner miles:float minutes:integer ~/samples/jruby/jndi_rails2 >~/tools/jruby-1.1.3/bin/jruby -S rake db:create ~/samples/jruby/jndi_rails2 >~/tools/jruby-1.1.3/bin/jruby -S rake db:migrate |
| ~/samples/jruby/jndi_rails2 >~/tools/jruby-1.1.3/bin/jruby -S gem install activerecord-jdbcmysql-adapter |
| ~/samples/jruby/jndi_rails2 >sudo cp ~/tools/mysql-connector-java-5.1.6/mysql-connector-java-5.1.6-bin.jar /System/Library/Frameworks/JavaVM.framework/Versions/1.6/Home/lib/ext |
| ~/tools/glassfish/v3/b23/glassfishv3-prelude/glassfish >java -Xmx512m -DJRUBY_HOME=/Users/arungupta/tools/jruby-1.1.3 -jar modules/glassfish-10.0-SNAPSHOT.jar |
| ~/samples/jruby/jndi_rails2 >~/tools/glassfish/v3/b23/glassfishv3-prelude/glassfish/bin/asadmin create-jdbc-connection-pool --datasourceclassname com.mysql.jdbc.jdbc2.optional.MysqlConnectionPoolDataSource --restype javax.sql.DataSource --property "User=duke:Password=duke:URL=jdbc\:mysql\://localhost/jndi_rails2_production" jdbc/jndi_rails2_pool |
| ~/samples/jruby/jndi_rails2 >~/tools/glassfish/v3/b23/glassfishv3-prelude/glassfish/bin/asadmin create-jdbc-resource --connectionpoolid jdbc/jndi_rails2_pool jdbc/jndi_rails2 |
| ~/samples/jruby >~/tools/glassfish/v3/b23/glassfishv3-prelude/glassfish/bin/asadmin ping-connection-pool jdbc/jndi_rails2_pool |
|
development: adapter: jdbc jndi: jdbc/jndi_rails2 driver: com.mysql.jdbc.Driver |
| ~/samples/jruby >~/tools/glassfish/v3/b22/glassfishv3-prelude/glassfish/bin/asadmin deploy jndi_rails2 |
Posted by Arun Gupta in web2.0 | Comments[11]
|
|
|
|
|
Today's Page Hits: 2475
Total # blog entries: 1002
As I understand it, Warbler spins up Rails runtimes to serve requests. Each runtime grabs a database connection as it starts and holds onto it indefinitely.
Doesn't that make a connection pool unnecessary for most Rails apps?
Posted by Dick Davies on September 09, 2008 at 01:57 AM PDT #
Hi Arun!
The JDBC password in in domain.xml. It is safer than having it in database.yml?
Posted by Alexis MP on September 09, 2008 at 05:08 AM PDT #
@Alexis MP : it's one less thing to have to worry about 'svn ignore'ing, and JNDI names make it easier to re-use the same WAR in dev. and production environments.
Pool has several benefits to letting each runtime handle it's own connection : montoring, setting custom properties on the driver, etc.
I just don't think Rails can free up connections yet - although there is built-in pooling on its way : http://ryandaigle.com/articles/2008/9/7/what-s-new-in-edge-rails-connection-pools
Posted by Dick Davies on September 09, 2008 at 05:37 AM PDT #
when rails will have build in connection pool (link in Dick Davie comment), what would be the best way? to use built in feature or to use method that is described in this post?
Posted by Artiom on September 10, 2008 at 12:43 AM PDT #
very goog!
Posted by 一卡多号 on September 10, 2008 at 06:07 AM PDT #
Alexis, Specifying db password in domain.xml is better (by being central) than being distributed as part of the config file in each application.
Artiom, There will probably be little difference in terms of performance or functionality. JNDI connection pools might be slightly faster, and are bound to be more sophisticated. I think the answer will continue to be the same reasons you would use a JNDI pool -- manageability and security (i.e. no database passwords in your application config files).
Posted by Arun Gupta on September 10, 2008 at 05:51 PM PDT #
@Arun
thanks
Posted by Artiom on September 10, 2008 at 11:59 PM PDT #
Posted by Vivek Pandey's Blog on November 06, 2008 at 06:29 PM PST #
Is there any way without using Warbler, wouldn't Goldspike do it as well?
Posted by Flüge on December 03, 2008 at 04:33 AM PST #
Goldspike is the old way of doing it and now pretty much everybody either uses Warbler or you can always deploy directly on GlassFish v3 prelude as explained at:
http://blogs.sun.com/arungupta/entry/screencast_26_develop_run_debug
Posted by Arun Gupta on December 03, 2008 at 05:56 AM PST #
Very good
Posted by moveis on August 09, 2009 at 11:11 AM PDT #