SlideShare a Scribd company logo
Why Jruby
By Chris Ochs
Background
• Social games built using rails
• Needed to integrate with existing java libraries
• Deployment with mongrel was starting to hurt
• First jruby/rails based game did ≈300,000,000 requests per day
• Generated over a billion requests per day to nosql database
• Non standard rails 3.0 app. No Activerecord. Json views
Concurrency Concurrency Concurrency
• Concurrency is 90% why to use jruby
• Ruby GIL effectively means peak cpu utilization 1.5 – 2 cores
• No atomics in ruby, no work on lock free algorithms
• Ruby thread primitives are not enough. Don’t use them in jruby
• Java.util.concurrent makes threading easy (and performant)
• Really good debugging/performance/stress testing tools available in
java
What kind of concurrency to expect
• Using ruby primitives limits you. Using mutex/synchronize you will
cap out very quickly and see a lot of threads blocking.
• With java.util.concurrent up to hundreds of threads before blocking
becomes an issue.
• Real world apps will usually eat up all cpu/io before hitting context
switching due to lots of threads.
• Real world non trivial rails app handled 750 requests per second using
80 threads.
Ruby world is still not thread safe
• Lots of gems are not thread safe. Usually a jruby specific alternative.
• Rails *might* be thread safe by 4.0
• Many misunderstandings around thread safety of system level calls
• Several layers of IO buffering can happen
• Hard learned lesson from java. If the vm doesn’t make any
guarantees, assume it’s not thread safe
• Things are steadily improving. Rails of all places is leading the way
(but still has a ways to go)
Effective use of jruby
• Lots of jruby gems that are thin wrappers around java libraries
• Loading random java library and calling from jruby usually just works
• Many places where the java library is better designed.
• Leverage what java does better, but avoid writing java
• Learn to use java.util.concurrent
• Learn to use thread & heap dumps
• Stay away from rails for now
Must use tools
• Thread & heap dumps changed my life. Makes debugging
performance and memory related issues easy
• Visualvm is your friend. Works remotely. Connect to any running
server to get memory stats, thread dumps, etc..
• You can instrument apps with JMX to get real time
performance/memory info. Or you can get at it directly in jruby and
log via regular logs.
Java libraries I like
• Netty.io. The java version of eventmachine
• Spymemcached. Because Dalli has a giant mutex around network
calls
• Rjack. Collections of jruby wrappers for common java libraries
• Java logging. Rjack SLF4J + Logback my favorite
• Akka. Actor framework for concurrency
• Guard-jruby-rspec. Makes rspec about as fast as under Cruby
• Apache camel
Rants
• Ruby (rails mostly) community spread a lot of bad information
• Many of us simply didn’t know better, so we bought into it
• Processes are not better then threads.
• Thread safe code is not hard if you have the right tools
• Please stop making ruby code thread safe by wrapping everything in a
mutex. If you can’t write a proper thread pool, use Thread.local
instead. I don’t care if you think it’s ugly, at least it’s usable.

More Related Content

PPTX
Unleash and Empower Your Engineers
PDF
9 anti-patterns for node.js teams
PDF
Server-Side JavaScript with Nashorn
PDF
Grand Central Dispatch and multi-threading [iCONdev 2014]
ZIP
Introduction to Google App Engine
PPTX
Intro to nodejs
PPTX
Keeping MongoDB Data Safe
PPTX
Search and analyze your data with elasticsearch
Unleash and Empower Your Engineers
9 anti-patterns for node.js teams
Server-Side JavaScript with Nashorn
Grand Central Dispatch and multi-threading [iCONdev 2014]
Introduction to Google App Engine
Intro to nodejs
Keeping MongoDB Data Safe
Search and analyze your data with elasticsearch

What's hot (15)

PPTX
Nashorn: JavaScript that doesn’t suck (ILJUG)
PPTX
Tampering with JavaScript
PPTX
How to Keep Your Data Safe in MongoDB
ZIP
Ruby on the JVM
PPTX
Introduction to NodeJS
PPTX
Actors Set the Stage for Project Orleans
PDF
Conquering AngularJS Limitations
PPTX
Building a production ready meteor app
PPTX
Scaling a MeteorJS SaaS app on AWS
PPTX
Put Your Thinking CAP On
PDF
An introduction to node3
PDF
Horizontally Scaling Node.js and WebSockets
PDF
Xen_and_Rails_deployment
PPTX
PHP Indonesia - Nodejs Web Development
PPT
Introduction to Django-Celery and Supervisor
Nashorn: JavaScript that doesn’t suck (ILJUG)
Tampering with JavaScript
How to Keep Your Data Safe in MongoDB
Ruby on the JVM
Introduction to NodeJS
Actors Set the Stage for Project Orleans
Conquering AngularJS Limitations
Building a production ready meteor app
Scaling a MeteorJS SaaS app on AWS
Put Your Thinking CAP On
An introduction to node3
Horizontally Scaling Node.js and WebSockets
Xen_and_Rails_deployment
PHP Indonesia - Nodejs Web Development
Introduction to Django-Celery and Supervisor
Ad

Viewers also liked (15)

PPT
Дистанционное обучение коучингу
PPTX
Presentazione dimasi generale
PPTX
как найти миссию своей жизни
PPSX
Software Automotive DMS Software
PPTX
коучинг- тренинг «Возьми жизнь в свои руки»
PPTX
Глубинная работа с образами в коучинге
PDF
Дистанционное обучение коучингу
PDF
Que quiere decir ser un buen profesional de la educacion para el siglo
PDF
Actividaddeaprendizaje08
PDF
Ashish handicrafts-enterprises
DOCX
Pengenalan analisis data dan statistika
PDF
Quick sort and binary search PDF
PPT
Etika tik, uu hak cipta dan k3
PPTX
spring–mass system
PPSX
National income(Engineering Economics and Management-EEM)
Дистанционное обучение коучингу
Presentazione dimasi generale
как найти миссию своей жизни
Software Automotive DMS Software
коучинг- тренинг «Возьми жизнь в свои руки»
Глубинная работа с образами в коучинге
Дистанционное обучение коучингу
Que quiere decir ser un buen profesional de la educacion para el siglo
Actividaddeaprendizaje08
Ashish handicrafts-enterprises
Pengenalan analisis data dan statistika
Quick sort and binary search PDF
Etika tik, uu hak cipta dan k3
spring–mass system
National income(Engineering Economics and Management-EEM)
Ad

Similar to Seattlerb why jruby (20)

PPTX
Why Play Framework is fast
PDF
Xen and-the-art-of-rails-deployment2640
PDF
Xen and-the-art-of-rails-deployment2640
PDF
Xen and-the-art-of-rails-deployment2640
PDF
Xen and-the-art-of-rails-deployment2640
PDF
Xen and-the-art-of-rails-deployment2640
KEY
Ruby Concurrency Realities
KEY
Modern Java Concurrency (OSCON 2012)
KEY
Introduction to JRuby
PDF
Bringing Concurrency to Ruby - RubyConf India 2014
KEY
Hybrid concurrency patterns
PPTX
Day 8 - jRuby
KEY
Actors and Threads
PPTX
Migrating to Java 11
PDF
Node.js primer
PDF
Java in High Frequency Trading
PDF
JRuby - The Best of Java and Ruby
PPTX
Full stack development using javascript what and why - ajay chandravadiya
PPTX
Concurrency in java
PPTX
U4 JAVA.pptx
Why Play Framework is fast
Xen and-the-art-of-rails-deployment2640
Xen and-the-art-of-rails-deployment2640
Xen and-the-art-of-rails-deployment2640
Xen and-the-art-of-rails-deployment2640
Xen and-the-art-of-rails-deployment2640
Ruby Concurrency Realities
Modern Java Concurrency (OSCON 2012)
Introduction to JRuby
Bringing Concurrency to Ruby - RubyConf India 2014
Hybrid concurrency patterns
Day 8 - jRuby
Actors and Threads
Migrating to Java 11
Node.js primer
Java in High Frequency Trading
JRuby - The Best of Java and Ruby
Full stack development using javascript what and why - ajay chandravadiya
Concurrency in java
U4 JAVA.pptx

Recently uploaded (20)

PDF
Accuracy of neural networks in brain wave diagnosis of schizophrenia
PDF
1 - Historical Antecedents, Social Consideration.pdf
PPTX
A Presentation on Touch Screen Technology
PPTX
Programs and apps: productivity, graphics, security and other tools
PDF
Enhancing emotion recognition model for a student engagement use case through...
PPTX
Chapter 5: Probability Theory and Statistics
PDF
DASA ADMISSION 2024_FirstRound_FirstRank_LastRank.pdf
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PDF
Getting Started with Data Integration: FME Form 101
PDF
Univ-Connecticut-ChatGPT-Presentaion.pdf
PDF
Approach and Philosophy of On baking technology
PPTX
OMC Textile Division Presentation 2021.pptx
PDF
WOOl fibre morphology and structure.pdf for textiles
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
Microsoft Solutions Partner Drive Digital Transformation with D365.pdf
PDF
August Patch Tuesday
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PPTX
Tartificialntelligence_presentation.pptx
PPTX
TLE Review Electricity (Electricity).pptx
PPTX
Group 1 Presentation -Planning and Decision Making .pptx
Accuracy of neural networks in brain wave diagnosis of schizophrenia
1 - Historical Antecedents, Social Consideration.pdf
A Presentation on Touch Screen Technology
Programs and apps: productivity, graphics, security and other tools
Enhancing emotion recognition model for a student engagement use case through...
Chapter 5: Probability Theory and Statistics
DASA ADMISSION 2024_FirstRound_FirstRank_LastRank.pdf
Digital-Transformation-Roadmap-for-Companies.pptx
Getting Started with Data Integration: FME Form 101
Univ-Connecticut-ChatGPT-Presentaion.pdf
Approach and Philosophy of On baking technology
OMC Textile Division Presentation 2021.pptx
WOOl fibre morphology and structure.pdf for textiles
Building Integrated photovoltaic BIPV_UPV.pdf
Microsoft Solutions Partner Drive Digital Transformation with D365.pdf
August Patch Tuesday
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
Tartificialntelligence_presentation.pptx
TLE Review Electricity (Electricity).pptx
Group 1 Presentation -Planning and Decision Making .pptx

Seattlerb why jruby

  • 2. Background • Social games built using rails • Needed to integrate with existing java libraries • Deployment with mongrel was starting to hurt • First jruby/rails based game did ≈300,000,000 requests per day • Generated over a billion requests per day to nosql database • Non standard rails 3.0 app. No Activerecord. Json views
  • 3. Concurrency Concurrency Concurrency • Concurrency is 90% why to use jruby • Ruby GIL effectively means peak cpu utilization 1.5 – 2 cores • No atomics in ruby, no work on lock free algorithms • Ruby thread primitives are not enough. Don’t use them in jruby • Java.util.concurrent makes threading easy (and performant) • Really good debugging/performance/stress testing tools available in java
  • 4. What kind of concurrency to expect • Using ruby primitives limits you. Using mutex/synchronize you will cap out very quickly and see a lot of threads blocking. • With java.util.concurrent up to hundreds of threads before blocking becomes an issue. • Real world apps will usually eat up all cpu/io before hitting context switching due to lots of threads. • Real world non trivial rails app handled 750 requests per second using 80 threads.
  • 5. Ruby world is still not thread safe • Lots of gems are not thread safe. Usually a jruby specific alternative. • Rails *might* be thread safe by 4.0 • Many misunderstandings around thread safety of system level calls • Several layers of IO buffering can happen • Hard learned lesson from java. If the vm doesn’t make any guarantees, assume it’s not thread safe • Things are steadily improving. Rails of all places is leading the way (but still has a ways to go)
  • 6. Effective use of jruby • Lots of jruby gems that are thin wrappers around java libraries • Loading random java library and calling from jruby usually just works • Many places where the java library is better designed. • Leverage what java does better, but avoid writing java • Learn to use java.util.concurrent • Learn to use thread & heap dumps • Stay away from rails for now
  • 7. Must use tools • Thread & heap dumps changed my life. Makes debugging performance and memory related issues easy • Visualvm is your friend. Works remotely. Connect to any running server to get memory stats, thread dumps, etc.. • You can instrument apps with JMX to get real time performance/memory info. Or you can get at it directly in jruby and log via regular logs.
  • 8. Java libraries I like • Netty.io. The java version of eventmachine • Spymemcached. Because Dalli has a giant mutex around network calls • Rjack. Collections of jruby wrappers for common java libraries • Java logging. Rjack SLF4J + Logback my favorite • Akka. Actor framework for concurrency • Guard-jruby-rspec. Makes rspec about as fast as under Cruby • Apache camel
  • 9. Rants • Ruby (rails mostly) community spread a lot of bad information • Many of us simply didn’t know better, so we bought into it • Processes are not better then threads. • Thread safe code is not hard if you have the right tools • Please stop making ruby code thread safe by wrapping everything in a mutex. If you can’t write a proper thread pool, use Thread.local instead. I don’t care if you think it’s ugly, at least it’s usable.