JRuby at Square

4,281 views

Published on

Published in: Technology
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
4,281
On SlideShare
0
From Embeds
0
Number of Embeds
1,615
Actions
Shares
0
Downloads
0
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

JRuby at Square

  1. 1. Thursday, January 26, 2012
  2. 2. JRuby at Square A report Steve Conover Xavier ShayThursday, January 26, 2012
  3. 3. ContextThursday, January 26, 2012
  4. 4. RailsThursday, January 26, 2012
  5. 5. Rails Rack Java Sinatra Java Rails RubyThursday, January 26, 2012
  6. 6. Java Deployment Rails DevelopmentThursday, January 26, 2012
  7. 7. Java IntegrationThursday, January 26, 2012
  8. 8. Not as immediately useful as we thought it would be.Thursday, January 26, 2012
  9. 9. Integrated with Neo4J libraries.Thursday, January 26, 2012
  10. 10. Shared JVM experience is a win.Thursday, January 26, 2012
  11. 11. Deployment “What do you want our infrastructure to look like in 2 years?” — MatthewThursday, January 26, 2012
  12. 12. “Warbler provides a minimal, flexible, Ruby-like way to bundle up all of your application files for deployment to a Java environment.”Thursday, January 26, 2012
  13. 13. “Trinidad allows you to run a rails or rackup applications within an embedded Apache Tomcat container.”Thursday, January 26, 2012
  14. 14. “Kirk is a wrapper around Jetty that hides all of the insanity and wraps your Rack application in a loving embrace.”Thursday, January 26, 2012
  15. 15. “Also, Kirk is probably the least HTTP retarded ruby rack server out there.”Thursday, January 26, 2012
  16. 16. “Also, Kirk is probably the least RECT rack I OR HTTP retarded ruby NCout there.” serverThursday, January 26, 2012
  17. 17. “Mizuno is a set of Jetty- powered running shoes for JRuby/Rack.”Thursday, January 26, 2012
  18. 18. None of these fit very well.Thursday, January 26, 2012
  19. 19. “Jetpack uses standard ruby- world tools to prepare the app for deployment, and then presents the ruby app to jetty as a Java EE web application.”Thursday, January 26, 2012
  20. 20. Jetpack is stylistically similar to alternatives.Thursday, January 26, 2012
  21. 21. “…its just that this style works and many of the others lead to failure.” — SteveThursday, January 26, 2012
  22. 22. http://github.com/square/jetpackThursday, January 26, 2012
  23. 23. Rolling deploy to n servers coordinated with haproxy.Thursday, January 26, 2012
  24. 24. One process with real threads rocks.Thursday, January 26, 2012
  25. 25. RailsThursday, January 26, 2012
  26. 26. “girl_friday is a Ruby library for performing asynchronous tasks.”Thursday, January 26, 2012
  27. 27. Thread-safe mode is not widely used.Thursday, January 26, 2012
  28. 28. Thread-safe mode is not widely tested.Thursday, January 26, 2012
  29. 29. We learned through high concurrency load testing that Arel had a non-threadsafe design.Thursday, January 26, 2012
  30. 30. cant add a new key into hash during iteration /rails-77dcf76f142b/activesupport/lib/active_support/ dependencies.rb:528:in `[]= https://github.com/rails/rails/issues/3817Thursday, January 26, 2012
  31. 31. DevelopmentThursday, January 26, 2012
  32. 32. > rvm use jruby > time ruby -e ruby -e 1.07s user 0.28s system 95% cpu 1.412 total > rvm use 1.9.3 > time ruby -e ruby -e 0.01s user 0.00s system 63% cpu 0.027 totalThursday, January 26, 2012
  33. 33. #!/bin/bash # script/ci source "$HOME/.rvm/scripts/rvm" function install_ruby_if_needed() { if ! rvm list rubies | grep $1 > /dev/null; then rvm install $1 fi } function switch_ruby() { install_ruby_if_needed $1 && rvm use $1 } function prepare_and_run() { switch_ruby $1 && install_bundler_if_needed && update_gems_if_needed && run_tests } prepare_and_run "1.9.3-p0" && prepare_and_run "jruby-1.6.5"Thursday, January 26, 2012
  34. 34. # Gemfile platforms :ruby do gem mysql2 end platforms :jruby do gem jdbc-mysql gem "jruby-openssl", "~> 0.7" endThursday, January 26, 2012
  35. 35. def normalize_sql_result(result) if jruby? result.map(&:values) else result end endThursday, January 26, 2012
  36. 36. result = if jruby? IO.popen4(cmd) {|_, _, _, _| } $? else pid = Process.spawn(cmd, STDERR => /dev/null) Process.waitpid2(pid)[1] endThursday, January 26, 2012
  37. 37. The cost of cross-ruby compatibility is low.Thursday, January 26, 2012
  38. 38. We have apps in both 1.8 and 1.9.Thursday, January 26, 2012
  39. 39. Java Deployment Rails DevelopmentThursday, January 26, 2012
  40. 40. Final Thoughts “What’s the word for ‘you should probably use it, unless you have a good reason not to?’” — SteveThursday, January 26, 2012
  41. 41. Final Thoughts @sconover @xshayThursday, January 26, 2012

×