Ruby on Rails
JRuby Everywhere! Server, Client, and Embedded

Summarized using AI

JRuby Everywhere! Server, Client, and Embedded

Thomas E Enebo • November 11, 2016 • Cincinnati, OH

In the talk titled "JRuby Everywhere! Server, Client, and Embedded" delivered by Thomas Enebo at RubyConf 2016, the focus is on deploying JRuby across various platforms, highlighting its capabilities and advantages. JRuby, a Ruby implementation on the Java Virtual Machine (JVM), extends Ruby's functionality beyond server-side applications, enabling client-side development and embedded systems without heavy reliance on C extensions.

The key points discussed include:

- JRuby’s Capabilities: JRuby runs on the JVM, unlocking extensive libraries and optimizations unavailable in C Ruby. It improves performance, allowing applications to handle multiple concurrent requests efficiently, often surpassing C Ruby performance benchmarks.

- Current Status of JRuby: The latest version, JRuby 9.1.6, was released recently with continued support for legacy versions and ongoing development toward compatibility with Ruby 2.4. Notably, the unification of Fixnum and Bignum into Integer in Ruby 2.4 is acknowledged as a significant change.

- Integration with Java: JRuby allows seamless integration with the Java ecosystem, providing the ability to script Java classes as Ruby objects and access libraries that would typically require Java expertise. A practical example shared involves developing a plugin for Minecraft using JRuby, showcasing its ease of use and flexibility.

- Support for Rails: JRuby has long supported Rails applications, with ongoing efforts to ensure compatibility with Rails 5, especially regarding Active Record. The discussion addresses the evolving complexities of adapting database support and maintaining high performance across multiple database formats.

- Embedded Systems: The talk emphasizes the feasibility of deploying JRuby on embedded systems such as Raspberry Pi, making it suitable for various applications with effective memory management and setup processes.

- Deployment Strategies: Various deployment options such as Docker and executable JAR files are highlighted for running JRuby applications smoothly across different environments, emphasizing the importance of keeping setups simple and efficient.

In conclusion, the speakers encourage the Ruby community to further explore JRuby's potential in various domains from server deployments to embedded systems. Feedback and collaboration from developers are welcomed as they aim to enhance JRuby's capabilities and usability.

Ultimately, JRuby stands out due to its performance, interoperability with Java, and versatility across platforms, making it a compelling option for developers looking to leverage the strengths of both Ruby and Java.

JRuby Everywhere! Server, Client, and Embedded
Thomas E Enebo • November 11, 2016 • Cincinnati, OH

RubyConf 2016 - JRuby Everywhere! Server, Client, and Embedded by Thomas Enebo

Ruby has seen its heaviest on servers; Client-side Ruby has been limited to experiments and toys, and Ruby C extensions complicate embedded use. But there's a better way: JRuby. Using frameworks like JRubyFX and Shoes 4, among many GUI and graphics libraries, JRuby makes client-side development fast and powerful. With an embedded JVM, JRuby runs your app on mid-level embedded devices without compiling a line of code. And JRuby is still the best way to power up your Rails 5 app. Come learn how to use JRuby everwhere!

RubyConf 2016

00:00:14.730 Hello, everyone. I'm Charles Nutter, and this is Tom. Today, we're going to talk about JRuby deployment across various platforms.
00:00:21.520 As for who we are, we've both been JRuby co-leads for about 10 years now. Tom’s experience stretches even longer. We have been working full time on JRuby for about a decade. Currently, we work for Red Hat; earlier, we worked at Sun Microsystems and Engine Yard for a few years.
00:00:38.739 Now, we've settled into Red Hat, which sponsors our work. We enjoy traveling to conferences and connecting with all of you, sharing drinks and ideas. If you have a beer recommendation, please let us know.
00:00:50.740 JRuby is essentially Ruby, but with greater capabilities. It runs on the JVM, providing access to a wide range of libraries. We have versions compatible with Ruby 1.8, 1.9, and 2.3, but we're primarily focusing on the current versions, 2.3 and 2.4.
00:01:02.470 Built on the Java platform, JRuby addresses many issues typical of C Ruby applications, such as garbage collection and threading. In fact, JRuby often executes Ruby applications faster than C Ruby, sometimes significantly so.
00:01:20.320 For instance, if you want to handle five or ten concurrent requests in C Ruby, you typically need multiple C Ruby instances for failover, probably requiring even more instances. However, with JRuby, you can run an application efficiently within a single JRuby process, achieving substantial throughput and performance sometimes equivalent to dozens of C Ruby implementations.
00:01:39.850 This benchmark we used years ago remains valid. It compares Ruby 2.0 running a red-black tree implementation, which took approximately two and a half seconds for that benchmark. It builds a tree, manipulates it, and walks through it multiple times. While Ruby has C extensions for performance, as Chris Seaton pointed out in his talk, this is usually how people enhance the performance of a Ruby application—by extracting slow parts to C and integrating them back into Ruby.
00:02:16.360 Nonetheless, JRuby shows real magic by running the identical Ruby implementation of the red-black tree on the JVM. With JVM optimizations, we achieve almost double the performance compared to C Ruby using C extensions. As more optimizing Ruby implementations like JRuby and JRuby Truffle emerge, there’s less need to rely on C extensions.
00:02:58.350 Now, let me hand it over to Tom, who will discuss JRuby's current status.
00:03:10.080 Yes, we released JRuby 9.1.6 on Wednesday, coinciding with the conference in Ohio. This point release included many socket fixes and numerous other minor updates. We support two branches on JRuby: the legacy JRuby 1.7 branch and the master branch tracking the latest of JRuby 9k.
00:03:38.760 We maintain support for Ruby 1.8 and 1.9, and our master branch supports the latest versions of Ruby. We plan to release another point release towards the end of the year and aim for Ruby 2.4 support concurrent with the C Ruby release.
00:04:13.410 On the JRuby 1.7 branch, we intend to discontinue maintenance by the year's end, but we anticipate another point release. An interesting issue we encountered is the unification of Fixnum and Bignum into Integer in Ruby 2.4. While most people's code will remain unaffected, there is a possibility of breakage for specific use cases where precision is crucial.
00:04:41.400 Frameworks like Rails have already updated for these changes, so they should work seamlessly in both versions 2.3 and 2.4. We believe that any other database adapters which might be impacted will also adapt accordingly.
00:05:00.750 If we face any issues relating to this change, we can always create a maintenance branch, but we hope that will not be necessary. This change is, admittedly, quite significant as two classes are merging into one.
00:05:32.580 Has anyone experienced any issues related to these changes while trying out Ruby 2.4? Yes? Curious to see what actual impacts will be, but I suspect it may not be too significant. Moving on, we want to eliminate JRuby 1.7 as maintenance is becoming increasingly challenging.
00:05:50.900 More users working with JRuby 1.9 are encountering difficulties with gems since Ruby 2.0 has been around for some time now. However, if you have a compelling reason not to upgrade to JRuby 9k, we would like to understand your situation. We aim to make the transition as smooth as possible.
00:06:16.139 If you search for "JRuby 1.7 EOL," you will find a GitHub issue where we attempt to gather all challenges users face while blocking their upgrade to JRuby 9k. The JRuby 9.2 release will depend on resolving those issues so anyone stuck can make the upgrade.
00:06:54.540 A significant advantage of JRuby is its ability to interact with the Java ecosystem. You can easily script Java classes and Java objects as if they were Ruby objects, with no need for compilation or type declarations.
00:07:06.649 We provide various shortcuts to bridge the gap between Java and Ruby, which make integration seamless. The abundance of Java libraries allows JRuby to handle tasks that might not have native Ruby equivalents. For example, if you're dealing with an e-commerce API that only has Java bindings, JRuby can call those APIs directly without needing to write a separate server.
00:07:40.759 Let me give you an example: I’ve created a library called Plugin that allows you to write plugins using Ruby syntax for Minecraft, a game written in Java. For instance, with my plugin called Egg Madness, you can set how many entities spawn when you throw an egg. Every time I throw an egg, 120 chickens emerge.
00:08:18.050 This example demonstrates how easy it is to utilize the Java API while writing in Ruby. You don't have to understand Java; let me walk you through the code. We define a class called Chickens that implements a Java interface called Listener. This registration allows the Java code to listen for specific events, in this case, the Player Egg Throw event.
00:09:02.930 We modify this event to ensure that it always hatches something, in this case, 120 chicks. Afterward, we return a message to the player. If I were to write this in Ruby, I would create a class called Chickens, include the Listener interface, and define a method to handle the event. We can simplify some methods and attributes to keep the Ruby-style intact.
00:09:50.900 Now, we have something that looks idiomatic in Ruby. In my library, I created a method that specifies the event to handle, and by passing a block, you can define the event's behavior. What's fascinating is that this method dynamically generates the class during runtime, which Ruby supports but is impossible in Java.
00:10:39.950 Let’s talk about Rails 5 support. JRuby has supported Rails for years, successfully running it since 2006. Over the past decade, we’ve seen hundreds—if not thousands—of applications leveraging Rails on JRuby, and its performance keeps improving.
00:11:09.500 Regarding Rails 5, while JRuby 9.0 focused on specific improvements, we couldn’t devote much time to Rails 5 support. Currently, Rails 5 works in most cases, as the existing JRuby database adapters are compatible with Rails applications.
00:11:59.029 However, Active Record, being the most complex part of Rails, has undergone significant changes which our existing adapter has not kept pace with. We aim to ensure it passes 100% of all Rails tests and integrates into Rails continuous integration.
00:12:32.830 Active Record JDBC supports several databases including SQLite, MySQL, and PostgreSQL. We still provide Oracle and various embedded databases support. JRuby offers flexibility, allowing users to leverage Java database drivers, which doesn't require additional extensions as in C Ruby.
00:13:02.220 While providing extensive database support, we're reevaluating how many databases we truly need to maintain due to the complexities and size of the codebase. The initial aim of creating one active record JDBC version across multiple Rails versions created difficulties over time. Rebooting our library means we can significantly reduce code duplication.
00:13:29.100 Changes in integration and API over Rails versions made maintaining compatibility harder. By focusing on the latest features in Rails 5, we intend to create streamlined adapters. For active record JDBC 5.1, we will ensure it works seamlessly without interfering with users reporting issues.
00:14:16.170 With our exploration of new database adapters, we found that 75% of the existing code is compatible with Rails. We aim to discard unnecessary code and base our library largely on the Rails version's code base, reducing maintenance complexity.
00:14:56.060 Our latest work on the Sequel adapter has been remarkably successful; it's currently passing nearly 100% of active record tests. Codifying our process should allow us to replicate success swiftly with MySQL and PostgreSQL adapters.
00:15:50.760 We’re also keeping Oracle support viable through the Oracle-enhanced adapter instead of maintaining our own. Thus, it makes sense to evaluate which embedded databases among them we should continue to support.
00:16:37.410 For those running JRuby with Microsoft SQL Server, it's important to note that it can be challenging, but we are re-evaluating the viability of other database supports including in-memory databases. The majority of services, such as Redis and Memcached, have libraries that work perfectly with JRuby for a consistent user experience.
00:17:26.230 For example, libraries like ZeroMQ work seamlessly in JRuby, achieving similar performance to C Ruby. As we increase native support, we have the option to leverage additional Java libraries to enhance performance further.
00:18:04.090 Many cloud environments support JRuby deployments, particularly Heroku. You can push your application to the cloud easily, which is a significant advantage of using JRuby as opposed to traditional Ruby.
00:18:41.350 When searching for deployment strategies, it’s crucial to consider both Ruby and Java environments. Tools like TorqueBox that Red Hat has designed allow JRuby applications to run on Java servers and easily handle the complexities surrounding supportive services and component management.
00:19:30.750 Container options are also effective; for instance, deploying via Docker will enable user to run JRuby applications while offering a reliable, simple setup. Here's a tip: start with your preferred JDK and bundle JRuby to run comfortably within that environment.
00:20:15.740 The executable jar files, such as via Warbler or TorqueBox, allow for complete JRuby applications to run seamlessly across JVMs without requiring extensive server configurations, which is very advantageous for rapid deployments.
00:21:03.440 For existing applications or in transitioning between frameworks, tools like Heroku make JRuby much more applicable in various environments, including cloud solutions. Additionally, a significant portion of libraries for distributed systems work flawlessly across Ruby and JRuby.
00:21:57.790 Lastly, keeping your application simple and employing the right services makes JRuby an optimal choice for many projects. The JRubyFX, a gem built on the JavaFX library, allows quick creation of GUI applications using the same robust frameworks.
00:22:49.410 JavaFX is a powerful GUI library providing various controls and customization options, plus opportunities for creating dynamic visual experiences.
00:23:09.290 Before diving deeper, I want to clarify that JRubyFX applications can be compiled into a JAR file, allowing display everywhere JVM is supported, simple and efficient.
00:23:45.660 Importantly, JRubyFX supports both DSL and FXML. The DSL is efficient for straightforward applications, while FXML offers a markup-based approach for complex UI designs. You can interact with controls via a Ruby-written controller.
00:24:31.410 Through the JRubyFX interface, you can also create dynamic and complicated UIs while leveraging JavaFX capabilities like custom controls, event handling, and rich graphical representations.
00:25:23.700 Switching gears, it's worth discussing how JRuby can work on embedded platforms. We see an increase in embedded systems with sufficient RAM capabilities, such as the Raspberry Pi, running JRuby applications without a hitch.
00:26:05.420 Indeed, many embedded devices now have the specifications to handle JVM and JRuby, enabling the development of various applications with ease. Setup is straightforward, installing JRuby via RVM or traditional downloading methods.
00:27:02.770 Using the Raspberry Pi as an embedded environment showcases not only installation ease but functionality akin to desktop environments. You can easily implement GUIs or backend processes using JRuby methods.
00:27:53.580 The memory consumption of JRuby is often higher than C Ruby in certain uses, but overall advances in hardware capabilities for embedded systems make this less of a concern over time. The benefits of utilizing JRuby within a familiar environment offer excellent performance and seamless deployment for various developers.
00:28:41.140 As we concluded, if there are questions about performance, scalability, or use cases for JRuby on embedded environments, don’t hesitate to reach out. Let's keep the conversation open about advancing JRuby's usability.
00:29:13.790 Now we look forward to your questions, especially about JRuby 9k features, benchmarks, and any specific issues you might want to clarify. Thank you all for joining us today!
00:29:49.080 We're excited about the potential of JRuby and look forward to the future advancements in the JRuby community. Remember, feedback is valuable, and we welcome any insights or recommendations you might have.
00:30:20.959 Thank you again for your time, and let’s keep improving JRuby together!
Explore all talks recorded at RubyConf 2016
+82