- Install it with Ruby Managers like asdf or rvm
- every time you run a command use jruby -S before
Memory Analysis
MRI Ruby (3 processes):
- Total: ~458MB (225.9 + 202.6 + 29.4)
- Multiple Ruby processes
JRuby (2 processes):
- Total: ~1,140MB (977.3 + 162.6)
- Java processes (JRuby runs on JVM)
Why JRuby Uses More Memory
- JVM Overhead:
- Java Virtual Machine baseline: ~100-200MB
- JIT compilation cache
- Garbage collection overhead
- JRuby Architecture:
- Compiles Ruby to Java bytecode
- Maintains both Ruby and Java object representations
- Thread-safe collections (more memory per object)
- Different Process Model:
- MRI: Multiple processes, shared memory
- JRuby: Fewer processes, more memory per process
Optimizing JRuby Memory for Heroku
You can tune Puma configuration for JRuby. Let me check your current Puma config:
⏺ Read(config/puma.rb) ⎿ Read 35 lines (ctrl+r to
⏺ Good! Your Puma config is already optimized for JRuby:
- No workers (line 24 commented out) - JRuby uses threads, not processes
- Thread-based concurrency - More efficient for JRuby
For Heroku Production
Memory recommendations:
- 512MB dyno: Reduce RAILS_MAX_THREADS to 3-4
- 1GB dyno: Keep current settings (5 threads)
- 2GB dyno: Can increase to 8-10 threads
JRuby vs MRI Trade-offs
JRuby Advantages:
- ✅ True threading (no GIL)
- ✅ Better performance under load
- ✅ JVM ecosystem access
JRuby Trade-offs:
- ❌ Higher memory usage (~2-3x)
- ❌ Slower startup time
- ❌ Higher baseline memory
For production, monitor with: heroku logs --tail | grep "sample#memory"
Your current memory usage (1.1GB) is normal for JRuby development! 📊
I'm currently using eco dynos in heroku, can they use jruby?
⏺ Eco dynos have very limited resources that make JRuby challenging:
Eco Dyno Specs
- Memory: 512MB RAM
- CPU: Shared CPU resources
- Sleep: Apps sleep after 30 minutes of inactivity
JRuby Memory Reality Check
Your development JRuby is using ~1.1GB, but:
- Development uses 2-4x more memory than production
- Production JRuby typically needs 300-600MB minimum
- JVM baseline alone: ~150-200MB
Can Eco Handle JRuby?
Technically possible but risky:
- ✅ JRuby can run in 512MB with aggressive tuning
- ❌ Very tight memory constraints
- ❌ Risk of memory-related crashes
- ❌ Performance degradation under load
Recommendations
Option 1: Optimize for Eco (risky)
heroku config:set JAVA_OPTS="-Xmx350m -Xms350m" heroku config:set RAILS_MAX_THREADS=2
Option 2: Upgrade to Basic ($7/month)
- 1GB RAM - Much safer for JRuby
- No sleep - Always available
- Better performance
Option 3: Stick with MRI Ruby on Eco
- Your MRI version (~458MB) fits comfortably
- Save JRuby migration for when you upgrade dynos
My Recommendation
For Eco dynos, stick with MRI Ruby for now. JRuby's benefits (threading, performance) aren't worth the memory constraints on Eco.
Migrate to JRuby when you're ready for Basic+ dynos!