Anzeige
Anzeige

Más contenido relacionado

Presentaciones para ti(20)

Anzeige

Migrate to JRuby

  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
Anzeige