So there’s this thing and it’s called JRuby and it’s like Ruby but it’s not Ruby. The talk was given by Charles Nutter and Thomas Enebo. This session was really interesting, at least the first part. I’ve never used JRuby before and didn’t really have a sense of what it was. The second part of the talk went into some more specific features and functions that will be added for the new release – that part was less interesting to me because I had never used JRuby before and therefore what I should be looking forward to in future releases didn’t really matter to me, but the first part of the talk was all an introduction to JRuby, what it is, what it does, and how it works. This, combined with some additional time and explanation with Conrad, really opened my eyes to the variety of different things going on in the Ruby world that are related to Ruby but not exactly Ruby.
TL;DR: JRuby does a lot of interesting things and I learned terms like JVM, jit, bytecode, and concurrency.
So, what is JRuby? JRuby is Ruby on the JVM (Java Virtual Machine). It is ruby implementation written partially in Java. It isn’t yet compatible with Ruby 2 but will be soon. JRuby is a different version of ruby entirely so you can use RVM to toggle between versions. Having Ruby on the JVM means that everything in the JVM is available to you. Essentially, this is really useful and cool because having the JVM available means that you can utilize Java libraries in your ruby code.
They then talked about garbage collection (more on that later) and jit runtime. Jit is a compilation called just in time compilation. In jit, when you run the compiler, you get an intermediate file (called bytecode) but the file isn’t optimized. So when you run Java, it takes the machine code and turns the parts you need into optimized code. Normal Ruby doesn't compile into machine code so JRuby runs like regular ruby but behind the scenes, it does a bunch of more complicated stuff. Traditional compilation happens when you run the compiler and get a binary file, not bytecode. This bytecode helps reduce overhead and they are currently working on improving the optimization even further in newer version of JRuby. The need for optimization comes from the longer setup time. Once the JVM is set up and running, it can be really fast (because it only optimizes pieces of the code as you need them) but it takes some time to get up and running.
They also talked about concurrency and parallelism. Concurrency means that is you have 100 users, then you need 100 way concurrency which is directly related to the amount of spacing (memory) you need at a given time. When you use threading (available in JRuby), it saves the amount of memory you need to use and therefore the amount of money you need to spend. This is also related to parallelism. Threading is not very commonly used in Ruby but to go into a little more explanation threading means instead of running 10 copies of the ruby code, you can run 1 copy of the code with 10 threads of the code. Related this, they talked about the thread-safe gem, hamster gem, and atomic gem. They also talked about shoes which I did some additional research into because it looks cool. Shoes is built using JRuby. It’s basically a gui (graphical user interface) environment which means it’s a way of writing graphical applications in ruby so that you have a user interface and you can so applications and not just web apps.
Now, back to garbage collection for a moment. JRuby has the best garbage collector. So what does that mean and what is garbage collection? Garbage collection runs code in your code. Ruby automatically throws objects away when you’re not using them in order to help with memory. Ruby marks items being used and tosses those that aren’t used… this is called mark and sweep. The JVM has a good garbage collector because of the way it optimizes the code (I think). For more on garbage collection, check out Pat Shaughnessy’s talk once it’s up on Confreaks (I missed it too, but it’s one that I definitely intend to listen to once it’s posted. I heard it was really good).
Finally, this talk about JRuby made me curious about the other stuff I had heard about… like CRuby, MRuby, Rubinius and what use cases were. A frequent use case for JRuby is when it is used to write a JRuby wrapper around Java code. CRuby is another name for MRI which stands for Matz Ruby Interpreter or the main documentation for the Ruby beginners are most familiar with. MRuby is a new version of a ruby-like language. Finally, Rubinious is like PyPy which lets you write python in python. Rubinious lets you write Ruby in Ruby which uses less resources and runs the ruby code faster.
No comments:
Post a Comment