Run JRuby on Heroku Right Now
Posted by Jennifer
Over a year ago Heroku launched the Cedar stack and the ability to run Java on our platform. Java is known as a powerful language - capable of performing at large scale. Much of this potential comes from the JVM that Java runs on. The JVM is the stable, optimized, cross-platform virtual machine that also powers other languages including Scala and Clojure. Starting today you can leverage the power of the JVM in your Ruby applications without learning a new language, by using JRuby on Heroku.
After a beta process with several large production applications, we are pleased to move JRuby support into general availability immediately. One of these companies Travis CI which provides free CI testing to open source repositories, and a pro plan for private projects, was a JRuby beta tester. Josh Kalderimis of the Travis team had this to say about using JRuby on Heroku:
We love JRuby, everything from the threading support to having the power of the JVM at our finger tips. But what we love most is that we can set up a JRuby app in seconds, the same way as all of our other Heroku apps. Git push and it's live, no matter what the language.
We've been working with the JRuby team to make sure that the experience using the language on Heroku is going to be everything you've come to expect from using our platform. So why should you be interested in running JRuby?
If you're coming from a Java background and want to use a more dynamic language, JRuby allows you to leverage the syntax of Ruby with the the ability to run JVM based libraries. If you're a Ruby developer already on Heroku, the JRuby implementation has several unique features that you can leverage. The most prevalent difference between running code on JRuby and MRI, or cRuby, is JRuby's lack of a Global Virtual Machine Lock. This means you can run multiple threads of JRuby code within the same process. While cRuby does allow you to perform IO and other non-ruby commands in parallel threads, running Ruby code concurrently can only be done in multiple processes. The second difference is the JVM ecosystem. JRuby can use Java libraries such as JDBC based database drivers. Many of these libraries have been heavily optimized and can offer speed upgrades.
JRuby on Heroku lowers the barrier of entry to both learning and running a new language in production. The interface of JRuby with the Heroku platform is the same as our other languages: you push your code to us and we do the rest. You don't need to think about all of the details of running a new language. The result is you get to focus on adding features, not on your how to deploy and keep your systems up.
We have been working with the JRuby community together to make sure the experience is a good one. Charles Nutter, the co-lead of JRuby, is excited about the future of running JRuby on Heroku:
One of the most frequently-requested features for JRuby isn't a JRuby feature at all...it's support for JRuby on Heroku. We're very excited that Heroku now officially supports JRuby, and we're looking forward to working with and supporting Heroku users trying out JRuby on their cloud of choice.
By normalizing the interface to deployment across implementations, we hope to ease the process of trying new intrepreters within the Ruby community. We are excited to see a new class of applications, by running Ruby on the JVM, deployed and supported on Heroku. With all these options, which Ruby should you use in production?
Heroku supports many languages, and we have a long and happy history of supporting Ruby. We are continuing to invest in the exciting future of MRI we are also excited about the ability for you to run your code on the interpreter of your choice. This can open up new possibilities such as taking advantage of different VM optimizations or concurrent Ruby processing.
As you're trying JRuby, remember that it may behave slightly differently than you're used to with MRI. If you're interested in trying JRuby out on an existing Heroku app, you can read more about converting an existing Rails app to use JRuby.
Every app is different and every project has different requirements. Having the ability to quickly and easily run your app in production on multiple Ruby VMs gives you the power to choose.
If you have an existing Rails app you can deploy your existing app on JRuby. If you're just starting from scratch, running JRuby on Heroku is a breeze. All you need to do is specify the version of Ruby you want to run, the engine, and the engine version in your
ruby '1.9.3', engine: 'jruby', engine_version: '1.7.1'
You'll need to run
bundle install with JRuby locally, then commit the results and push to Heroku:
$ git add . $ git commit -m "trying JRuby on Heroku" $ git push heroku master Counting objects: 692, done. Delta compression using up to 4 threads. Compressing objects: 100% (662/662), done. Writing objects: 100% (692/692), 141.01 KiB, done. Total 692 (delta 379), reused 0 (delta 0) -----> Heroku receiving push -----> Ruby/Rails app detected -----> Using Ruby version: ruby-1.9.3-jruby-1.7.1 -----> Installing JVM: openjdk7-latest -----> Installing dependencies using Bundler version 1.2.1 # ...
That should be all you need to do to run JRuby on Heroku. If you're converting an existing Rails application, please read moving an existing Rails app to run on JRuby.
While you're trying JRuby out on Heroku you can also try out Ruby 2.0.0 preview, before it is released in February.
With the release of JRuby on Heroku now you can to run your code on multiple VMs, and leverage concurrent Ruby code in production. You've got a standard interface to deployments and the power to choose the right tool for the right job. Special thanks to all of the customers who tried the JRuby beta, and to the JRuby team for being available for technical support. Give JRuby a try and let us know what you think.