Trinidad 0.8, gem extensions and database pooling 0

Posted by david

I think, the release of the latest version of JRuby-Rack was the perfect moment to do a new release of Trinidad and some new features. If this is the first time you bump into Trinidad, it's a Rack compatible server build on top of Apache Tomcat and release as a rubygem.

One of my main concerns about the project was that I wanted to build a lightweight gem and until now you had to download more than 5Mb with each release. The first step to avoid this was to split the gem in two, the main gem, trinidad, is now 12Kb, while the jars gem, trinidad_jars is just 3Mb, thus if I don't change the jars you'll just need to download 12Kb with each new release.

The second step is to stop adding features to the main gem. With each new feature that I wanted to implement more jar files were required and added to the package. Now Trinidad includes a little extensions api that allows to release features as little gems out of the core, you can find more details on the api into the wiki. So, from now I'll try to release new features as extensions and leave the core as tiny as possible.

The first extension that I've written adds support for database connection pooling through Tomcat and JNDI. The project is also hosted on github, and the installation and configuration are pretty straightforward.

Finally, an extra point. Of course, the coolest new feature is the Rails 3 support due to JRuby-rack already supports it, and, as you'll probably know, Rails 3 routes allow to split your application in several ones and route between each other. Just remember that Trinidad also allows you to run all those distributed applications within the same container with just a few configuration lines.

All in all, if you find a bug or you'd like to see other new features, please don't hesitate filing an issue in the project's tracker.

Have fun.

Loading several Rails applications into a single Tomcat container with Trinidad 0

Posted by david

Sometimes you meet that kind of people that complain about the lack of any feature in an open source project but they don't do anything to solve the problem. Last releases of Trinidad try the solve one of that complaints, so that people have one excuse less to use it :)

The goal of the project was pretty simple, allow to run a Rails application under Apache Tomcat without generating a war file in a more familiar "rails way". But that guy complained because he wanted to run several applications into the same instance of Tomcat, and actually he was partially right, Tomcat is a powerful application server and it can run several applications at once, thus, why don't allow to Trinidad to run several Rails applications?

After a few changes in its architecture, Trinidad allows to run as many Rails applications as Tomcat can support into the same instance. We just need add the application's context and their system path to the Trinidad's configuration file and run Trinidad with the option to read that file.

For instance, if we want to load three applications we had to add this nodes to the yaml file:


---
  :web_apps:
    :default:                                         # context path is '/'
      :web_app_dir: 'rails_apps/mock'
    :mock1:                                         # context path is '/mock1'
      :web_app_dir: 'rails_apps/mock1'
    :mock2:
      :web_app_dir: 'rails_apps/mock2'
      :context_path: '/mock2'

and run Trinidad with the configuration option:


$ jruby -S trinidad --config

That's it. Hope it will useful. Btw all the configuration options can be found in the Trinidad's wiki.

Rails load balancing with Apache and Trinidad 1

Posted by david

I just released a new version of Trinidad with two major features. The first one is that it supports ssl connections adding a simple starting option:


  $ trinidad --ssl

The second one is also related with connections, but this one is about AJP, a protocol designed to increase tomcat's performance, if you already have worked with tomcat or jboss I'm sure you already know it.

But what I'd like to show you is one of its main adventages, how to create a really stable load balancer with Apache httpd and Trinidad thanks to ajp.

First we have to ensure all the apache modules that we need are loaded:


  $ sudo a2enmod proxy_ajp proxy_balancer

After that, we have to configure our virtual host to proxy the connections through ajp, this is an actually basic configuration, there are a lot of resources about mod_proxy_balancer on internet:


<Proxy balancer://trini>
  BalancerMember ajp://127.0.0.1:8009
  BalancerMember ajp://127.0.0.1:8099
</Proxy>

ProxyPass / balancer://trini/

Notice that I'm using my development machine and that's why the two balancer members have the same ip but different port.

Finally, we have to run two different instances of Trinidad with the ajp option enabled, with the ports we specified in the balancer configuration (8009 is the default one), and different http ports due to I'm running it in my machine:



$ trinidad --port 3001 --ajp
$ trinidad --port 3002 --ajp 8099

That's it, quite straightforward.

By the way, I've also set up a google group where you can ask doubts or discuss about the development itself, and, as always, if you find a bug or have a new cool functionality you can add it to the issue tracker.