the good the bad the ugly
play

The Good, The Bad & The Ugly (Clojure & JRuby) Allen - PowerPoint PPT Presentation

The Good, The Bad & The Ugly (Clojure & JRuby) Allen Rohner @arohner @circleci Clojure/West 2012 Monday, March 19, 12 Who Am I Using Clojure in production since 2008 Author of Scriptjure, a DSL for writing javascript, two


  1. The Good, The Bad & The Ugly (Clojure & JRuby) Allen Rohner @arohner @circleci Clojure/West 2012 Monday, March 19, 12

  2. Who Am I • Using Clojure in production since 2008 • Author of Scriptjure, a DSL for writing javascript, two years before ClojureScript • Commits in Clojure core, contrib, ring, compojure, noir, lein, swank-clojure, pallet... Monday, March 19, 12

  3. Circle • Founder • CircleCI.com • Easy Continuous Integration for web apps Monday, March 19, 12

  4. When this talk was accepted.... Monday, March 19, 12

  5. TL;DR Monday, March 19, 12

  6. It Is NOT about: • “Ruby sucks” • “JRuby sucks” Monday, March 19, 12

  7. It Is NOT about: • “Ruby sucks” • “JRuby sucks” Monday, March 19, 12

  8. It IS about Ruby != Clojure Monday, March 19, 12

  9. My Biases • 2006-2009: Rails 1.x • 2008-2012: Clojure • Expert in Clojure, Intermediate in Ruby Monday, March 19, 12

  10. My History Monday, March 19, 12

  11. How did we get into this mess? Monday, March 19, 12

  12. Architecture Trinidad JRuby Clojure Mongo Monday, March 19, 12

  13. The Good Monday, March 19, 12

  14. Calling just works (require ‘foo.bar) foo = JRClj.new(“foo.bar”) (foo.bar/baz 3) foo.baz(3) (-> (r/module “Foo”) (r/class “Bar”) Foo::Bar.baz(3) (r/send :baz 3)) Monday, March 19, 12

  15. Fork Me • https://github.com/kyleburton/jrclj • https://github.com/circleci/cljr Monday, March 19, 12

  16. The Clojure REPL makes Ruby better Monday, March 19, 12

  17. Individual tests • (r/rspec “specs/controllers/foo.rb”) • (r/rspec “-e” “that one test”)* Monday, March 19, 12

  18. Fine-grained reloading • (r/eval “load ./foo.rb”) Monday, March 19, 12

  19. Clojure Concurrency from JRuby • Worker.send_email() • concurrency with no queues Monday, March 19, 12

  20. Runtimes! • (r/new-runtime) • (def server (r/rails-server)) Monday, March 19, 12

  21. JRuby Runtimes The JVM Ruby 1 Ruby 2 Ruby 3 Monday, March 19, 12

  22. Combining WARs • Warbler • lein war • Deploy both on tomcat/jetty • (Not tested) Monday, March 19, 12

  23. JRuby • Impressive technology • awesome maintainers Monday, March 19, 12

  24. The Bad Monday, March 19, 12

  25. But... • Stuck on 1.6.5, couldn’t upgrade or downgrade due to different bugs Monday, March 19, 12

  26. 1.9 • 1.9 support not finished • Encoding • SSL Monday, March 19, 12

  27. Complexity Self- kLOC Java hosted Clojure 51 28 (1.3.0) JRuby 291 600 (1.6.5) Monday, March 19, 12

  28. Gems • Often not tested against JRuby • ExecJS • Some just can’t work in JRuby • FFI Monday, March 19, 12

  29. Slow Startup • Ruby likes to restart, early & often • helpers, rack middleware Monday, March 19, 12

  30. Slow Startup • 1:03 macbook pro • 1:45 macbook air • 3:00 ec2 m1.small Monday, March 19, 12

  31. Slow Startup Matters • need to RSpec all the time • Spork & Guard didn’t work • rake tasks (generate, etc) • rake assets:precompile (8m) Monday, March 19, 12

  32. Dilemma: • slow restart • strangeness caused by Ruby code not expecting to reload • Restart often, just in case Monday, March 19, 12

  33. Setup • Paul lost 2 days Monday, March 19, 12

  34. CRuby in Dev, JRuby in production Doesn’t work! Monday, March 19, 12

  35. Different Views • Clojure likes one big process, lots of threads • Ruby prefers lots of small processes • Multithreaded JRubyOnRails: works in theory, not in practice. Weird classloading bugs, unsupported gems. Monday, March 19, 12

  36. Duplication • DB connections • DB models • Test data Monday, March 19, 12

  37. Classpath • Different depending on whether you ran ‘rails console’ or ‘lein repl’ • => different behavior • Can be fixed, but it’s one more headache • If you didn’t understand that, yes Monday, March 19, 12

  38. Rails Env • DB connection • Email policy • Class reloading • error reporting • Airbrake Monday, March 19, 12

  39. Clojure Environment • Clojure leaves that to you • * (yes there’s Noir’s env, but it’s minor compared to what Rails does) Monday, March 19, 12

  40. Testing • Rails loves to mock • Clojure prefers pure fns Monday, March 19, 12

  41. Rails Testing Env • FactoryGirl returning fake objects • DB Cleared between tests • But who told Clojure? • Are you both talking to the same DB? Monday, March 19, 12

  42. The Ugly Monday, March 19, 12

  43. Naming • project.git-url => project[“git-url”] • (mongo/update! :project {:git_url git-url})) Monday, March 19, 12

  44. Symbols vs. Keywords • Wrappers • Clojure :foo != Ruby :foo Monday, March 19, 12

  45. • Rails code, calls Clojure • Clojure calls back into Rails • But might not be the same runtime • might not have the same classpath • might not be talking to the same DB • might not be the same ruby version Monday, March 19, 12

  46. Monday, March 19, 12

  47. Lessons Learned Monday, March 19, 12

  48. Complexity is Multiplicative Monday, March 19, 12

  49. Rails Magic The closer you are to the ‘standard’ environment, the better things work Monday, March 19, 12

  50. • Rails 3 (ok) • using Mongo/Mongoid (not bad) • and JRuby (hrm...) • and Clojure (OMGWTF) Monday, March 19, 12

  51. Avoid Mixing Paradigms (In the same process) Monday, March 19, 12

  52. Don’t duplicate Models Monday, March 19, 12

  53. Don’t overestimate the value of code reuse Monday, March 19, 12

  54. Understanding Devise + OmniAuth > Writing Oauth2 login in Clojure Monday, March 19, 12

  55. Yes, you will write more code But you’ll understand it! Monday, March 19, 12

  56. Yes, you will read Clojure source But it’s simpler! Monday, March 19, 12

  57. The Future • Clojure REST API • Fat Javascript Client • Knockout JS • Sammy JS • HamlCoffee • Clojurescript? Monday, March 19, 12

  58. • https://github.com/circleci/mongofinil • https://github.com/edgecase/dieter Monday, March 19, 12

  59. Questions? @circleci circleci.com Monday, March 19, 12

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend