Skip to content

Instantly share code, notes, and snippets.

app_path: "<%= trinidad_home %>/current"
trinidad_options: "-e production"
jruby_home: "<%= jruby_home %>"
ruby_compat_version: RUBY1_8
trinidad_name: Trinidad
jsvc_path: "/usr/bin/jsvc"
java_home: "/usr/lib/jvm/java-6-openjdk/jre"
output_path: "/etc/init.d"
pid_file: "<%= trinidad_home %>/shared/pids/trinidad.pid"
log_file: "<%= trinidad_home %>/shared/log/trinidad.log"
@jkutner
jkutner / benchmark.rb
Created March 16, 2012 00:31
Trying running these programs on MRI and JRuby!
require 'benchmark'
def factorial_repeat(k, x)
k.times { x.downto(1).inject(:*) }
end
def run(i, k, x)
i.downto(1).map do
Thread.new { factorial_repeat(k, x) }
end.each { |t| t.join }
13:38:03,923 INFO [org.apache.coyote.http11.Http11Protocol] (MSC service thread 1-1) Starting Coyote HTTP/1.1 on http--127.0.0.1-8080
13:38:04,412 INFO [org.jboss.as.mail.extension] (MSC service thread 1-1) JBAS015400: Bound mail session [java:jboss/mail/Default]
13:38:04,646 WARN [org.jboss.as.messaging] (MSC service thread 1-1) JBAS011600: AIO wasn't located on this platform, it will fall back to using pure Java NIO. If your platform is Linux, install LibAIO to enable the AIO journal
13:38:04,822 INFO [org.hornetq.core.server.impl.HornetQServerImpl] (MSC service thread 1-1) live server is starting with configuration HornetQ Configuration (clustered=false,backup=false,sharedStore=true,journalDirectory=/opt/torquebox/jboss/standalone/data/messagingjournal,bindingsDirectory=/opt/torquebox/jboss/standalone/data/messagingbindings,largeMessagesDirectory=/opt/torquebox/jboss/standalone/data/messaginglargemessages,pagingDirectory=/opt/torquebox/jboss/standalone/data/messagingpaging)
13:38:04,826 INFO [org.horn
08:42:21,982 INFO [org.jboss.as.server.deployment] (MSC service thread 1-2) JBAS015876: Starting deployment of "twitalytics-knob.yml"
08:42:23,441 INFO [org.torquebox.core] (MSC service thread 1-2) evaling: /opt/torquebox/jboss/standalone/tmp/vfs/deployment6e66eb28ebd67436/twitalytics.knob-956e8e8043cf7666/config/torquebox.rb
08:42:23,945 ERROR [stderr] (MSC service thread 1-2) STOMP HOSTS: [localhost]
08:42:24,942 ERROR [stderr] (MSC service thread 1-2) webhosts: []
08:42:24,942 ERROR [stderr] (MSC service thread 1-2) stomphosts: [localhost]
08:42:24,943 ERROR [stderr] (MSC service thread 1-2) DEPLOY STANDALONE SESSION MANAGER
08:42:25,181 INFO [org.hornetq.core.server.impl.HornetQServerImpl] (MSC service thread 1-1) trying to deploy queue jms.topic./topics/statuses
08:42:25,184 INFO [org.torquebox.stomp.binding] (MSC service thread 1-2) Advertising STOMP binding: ws://localhost:8675/
08:42:25,232 INFO [org.jboss.as.messaging] (MSC service thread 1-1) JBAS011601: Bound messaging object to jndi name java
14:19:56,006 ERROR [org.jboss.msc.service.fail] (MSC service thread 1-3) MSC00001: Failed to start service jboss.deployment.unit."twitalytics-knob.yml".ha-singleton.coordinator: org.jboss.msc.service.StartException in service jboss.deployment.unit."twitalytics-knob.yml".ha-singleton.coordinator: java.lang.IllegalArgumentException: failed to start server socket
at org.projectodd.polyglot.hasingleton.HASingletonCoordinatorService.start(HASingletonCoordinatorService.java:52)
at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1811) [jboss-msc-1.0.2.GA.jar:1.0.2.GA]
at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1746) [jboss-msc-1.0.2.GA.jar:1.0.2.GA]
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) [classes.jar:1.6.0_29]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) [classes.jar:1.6.0_29]
at java.lang.Thread.run(Thread.java:680) [classes.jar:1.6.0_
@jkutner
jkutner / commands.sh
Created March 29, 2012 19:16
TorqueBox Clustering
$ torquebox run --clustered
$ JBOSS_OPTS="-Djboss.node.name=node2 \
-Djboss.server.data.dir=/tmp/node2 \
-Djboss.socket.binding.port-offset=100" \
torquebox run --clustered

Two Applications, One Trinidad Server

One of the advantages of running Ruby on the JVM is that we can deploy multiple applications to the same webserver. Using one JRuby webserver means that there is only one process to manage, monitor, start and stop. Your sysadmins will thank you.

But having mutliple application on one virtual machine also means we can configure them to share resources, thus reducing the overhead required for a production server. In this post, we'll walk through an example of deploying two applications to one Trinidad server.

Trinidad is a light-weight JRuby web server that runs Rails and Rack applications in an embedded Apache Tomcat container. Let's install it by running this command:

$ gem install trinidad -v 1.3.4
@jkutner
jkutner / config.ru
Created March 30, 2012 19:12
Deploying Two Applications to One Trinidad Server
require 'rubygems'
require 'sinatra'
require 'active_record'
get '/' do
ActiveRecord::Base.establish_connection(
:adapter => "jdbcpostgresql",
:jndi => "java:/comp/env/jdbc/trinidad"
)
$LOAD_PATH << $APP_LOAD_PATH #set the load path from the APP_LOAD_PATH binding
if $RACK_ENV == 'production'
ENV['GEM_PATH'] = "#{File.join($RULE_SERVER_HOME, 'vendor/jruby/1.8')}:#{File.join($TORQUEBOX_HOME, 'jruby/lib/ruby/gems/1.8')}"
ENV['GEM_HOME'] = File.join($RULE_SERVER_HOME, 'vendor/jruby/1.8')
else
puts 'Using global GEM_HOME directory.'
end
require 'rubygems'
TorqueBox.configure do
job DeleteOldStatuses do
cron "0 0/5 * * * ?"
singleton true
config do
max_age 30.days.ago
end
end
end