Your SlideShare is downloading. ×
Migrate to JRuby
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×

Introducing the official SlideShare app

Stunning, full-screen experience for iPhone and Android

Text the download link to your phone

Standard text messaging rates apply

Migrate to JRuby

242
views

Published on

My Talk on Ruby Conf China 2013, experience about how we migrate Ruby on Rails project to JRuby in Groupon Payments.

My Talk on Ruby Conf China 2013, experience about how we migrate Ruby on Rails project to JRuby in Groupon Payments.

Published in: Technology

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
242
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
1
Comments
0
Likes
0
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. Migrate to JRuby What We Learned
  • 2. ian yang @doitian
  • 3. Agenda • Background • How to Migrate • What We Learned
  • 4. Background
  • 5. Breadcrumb Payments
  • 6. The Codebase • 4 Ruby on Rails applications • Ruby 1.9.2 and Rails 3.2.1
  • 7. Why JRuby? • Multithreading • Memory Leak • Easy integration of libraries on JVM
  • 8. How to Migrate
  • 9. Choose a Deploy Strategy
  • 10. Archive File Capistrano Scheduler Background Jobs Clustering Warbler ✔ Trinidad ✔ ✔ ✔ ✔ TorqueBox ✔ ✔ ✔ ✔ ✔
  • 11. Archive File Capistrano Scheduler Background Jobs Clustering Warbler ✔ Trinidad ✔ ✔ ✔ ✔ TorqueBox ✔ ✔ ✔ ✔ ✔
  • 12. JRuby-Lint https://github.com/jruby/jruby-lint
  • 13. What We Learned
  • 14. Gems Alternatives
  • 15. Wiki: C Extension Alternatives https://github.com/jruby/jruby/wiki/C-ExtensionAlternatives
  • 16. Lock Compatible Version
  • 17. gem 'rubyzip', '<1.0.0'
  • 18. *nix to JVM
  • 19. • Cannot trap all signals • No Kernel#fork
  • 20. Kernel#fork → Thread.new
  • 21. Thread-safety
  • 22. Avoid Sharing Mutable State Between Threads
  • 23. Global Variable Class Variable Class Instance Variable
  • 24. Lazy Initialization → Preload
  • 25. class Cvv ✘ def self.redis @@redis ||= Redis.new(...) end end
  • 26. class Cvv def self.redis @@redis end def self.redis=(r) @@redis = r end end ✔ ! # config/initializers/cvv.rb Cvv.redis = Redis.new(...)
  • 27. Thread Local Storage
  • 28. class Processor class_attribute :skip ✘ ! def execute do_something unless self.class.skip end end
  • 29. ✔ class Processor def self.skip Thread.current['Processor.skip'] end def self.skip=(s) Thread.current['Processor.skip'] = s end end
  • 30. Atomic Variable
  • 31. class Airlock class_variable :enabled end ✘
  • 32. # gem 'atomic'! ✔ class Airlock! @@enabled = Atomic.new(false)! def self.enabled! @@enabled.value! end! def self.enabled=(e)! @@enabled.update { e }! end! end
  • 33. Locks require 'thread'! mutex = Mutex.new! ! Thread.new do! mutex.synchronize do! ...! end! end
  • 34. Reference: Concurrency in JRuby https://github.com/jruby/jruby/wiki/Concurrency-injruby
  • 35. Reference: Ruby Mutithreading http://www.tutorialspoint.com/ruby/ ruby_multithreading.htm
  • 36. Resque
  • 37. • Jobs run in the same process • Free the resources • No Fork
  • 38. OpenSSL
  • 39. Full OpenSSL Support gem 'jruby-openssl'
  • 40. Different Cryptography Implementations https://github.com/jruby/jruby/issues/931
  • 41. Cryptography Adapter • Use OpenSSL in CRuby • Use JCE directly in JRuby (java_import)
  • 42. Tuning
  • 43. TorqueBox + JBoss
  • 44. Connection Pool Size
  • 45. Thread Pool Size
  • 46. JVM Memory
  • 47. How To? • Benchmark • Monitoring
  • 48. References
  • 49. Deploying with JRuby
  • 50. JRuby Wiki https://github.com/jruby/jruby/wiki