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 years before ClojureScript

• Commits in Clojure core, contrib, ring,

compojure, noir, lein, swank-clojure, pallet...

Monday, March 19, 12

Circle • • •

Monday, March 19, 12

Founder CircleCI.com Easy Continuous Integration for web apps

When this talk was accepted....

Monday, March 19, 12

TL;DR Monday, March 19, 12

It Is NOT about:

• “Ruby sucks” “JRuby sucks” • Monday, March 19, 12

It Is NOT about:

• “Ruby sucks” “JRuby sucks” • Monday, March 19, 12

It IS about

Ruby != Clojure

Monday, March 19, 12

My Biases • 2006-2009: Rails 1.x • 2008-2012: Clojure • Expert in Clojure, Intermediate in Ruby

Monday, March 19, 12

My History

Monday, March 19, 12

Monday, March 19, 12

How did we get into this mess?

Architecture Trinidad JRuby Clojure

Mongo

Monday, March 19, 12

The Good Monday, March 19, 12

Calling just works (require ‘foo.bar) (foo.bar/baz 3)

foo = JRClj.new(“foo.bar”) foo.baz(3)

(-> (r/module “Foo”) (r/class “Bar”) (r/send :baz 3))

Foo::Bar.baz(3)

Monday, March 19, 12

Fork Me • https://github.com/kyleburton/jrclj • https://github.com/circleci/cljr

Monday, March 19, 12

The Clojure REPL makes Ruby better

Monday, March 19, 12

Individual tests

• •

Monday, March 19, 12

(r/rspec “specs/controllers/foo.rb”) (r/rspec “-e” “that one test”)*

Fine-grained reloading



Monday, March 19, 12

(r/eval “load ./foo.rb”)

Clojure Concurrency from JRuby • Worker.send_email() • concurrency with no queues

Monday, March 19, 12

Runtimes!

• •

Monday, March 19, 12

(r/new-runtime) (def server (r/rails-server))

JRuby Runtimes The JVM

Ruby 1

Monday, March 19, 12

Ruby 2

Ruby 3

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

JRuby • Impressive technology • awesome maintainers

Monday, March 19, 12

The Bad Monday, March 19, 12

But...

• Stuck on 1.6.5, couldn’t upgrade or downgrade due to different bugs

Monday, March 19, 12

1.9 • 1.9 support not finished • Encoding • SSL

Monday, March 19, 12

Complexity

Monday, March 19, 12

kLOC

Java

Selfhosted

Clojure (1.3.0)

51

28

JRuby (1.6.5)

291

600

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

Slow Startup • Ruby likes to restart, early & often • helpers, rack middleware

Monday, March 19, 12

Slow Startup • 1:03 macbook pro • 1:45 macbook air • 3:00 ec2 m1.small

Monday, March 19, 12

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

Dilemma: • slow restart • strangeness caused by Ruby code not expecting to reload

• Restart often, just in case

Monday, March 19, 12

Setup

• Paul lost 2 days

Monday, March 19, 12

CRuby in Dev, JRuby in production Doesn’t work!

Monday, March 19, 12

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

Duplication • DB connections • DB models • Test data

Monday, March 19, 12

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

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

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

Testing • Rails loves to mock • Clojure prefers pure fns

Monday, March 19, 12

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

The Ugly Monday, March 19, 12

Naming • project.git-url

=>

project[“git-url”]



(mongo/update! :project {:git_url git-url}))

Monday, March 19, 12

Symbols vs. Keywords • Wrappers • Clojure :foo != Ruby :foo

Monday, March 19, 12

• 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

Monday, March 19, 12

Lessons Learned

Monday, March 19, 12

Complexity is Multiplicative

Monday, March 19, 12

Rails Magic The closer you are to the ‘standard’ environment, the better things work

Monday, March 19, 12

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

Avoid Mixing Paradigms (In the same process)

Monday, March 19, 12

Don’t duplicate Models

Monday, March 19, 12

Don’t overestimate the value of code reuse

Monday, March 19, 12

Understanding Devise + OmniAuth

> Writing Oauth2 login in Clojure

Monday, March 19, 12

Yes, you will write more code But you’ll understand it!

Monday, March 19, 12

Yes, you will read Clojure source But it’s simpler!

Monday, March 19, 12

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

• https://github.com/circleci/mongofinil • https://github.com/edgecase/dieter

Monday, March 19, 12

Questions? @circleci circleci.com

Monday, March 19, 12

Clojure & JRuby - GitHub

Clojure likes one big process, lots of threads. • Ruby prefers lots of small ... Duplication. • DB connections. • DB models. • Test data. Monday, March 19, 12 ...

3MB Sizes 0 Downloads 205 Views

Recommend Documents

Clojure and Android - GitHub
Improving the Clojure/Android experience. Closing thoughts. Page 5. Clojure and. Android. Daniel Solano. Gómez. Android and the. Dalvik VM ... Page 10 ...

Clojure for Beginners - GitHub
Preview. Language. Overview. Clojure Basics & .... (clojure.java.io/reader file))]. (doseq [line .... Incremental development via REPL ⇒ less unexpected surprises ...

DevOps for the JVM @tbatchelli aka @disclojure Clojure ... - GitHub
Configure clustered services. • Deploy software. • Manage software/servers/services. 2. Saturday, March 17, 12 ... works with every cloud (via jclouds) and more.

Boston Clojure Meetup -
mobile web. ClojureScript. +. X. = hybrid app. Clojure. +. RoboVM (iOS)/ various (Android). = native app. Android's already Java. On. iOS, compile Java bytecode ...

Boston Clojure Meetup -
“Create truly native iOS apps in Java”. Two things ... http://docs.robovm.com/advanced-topics/bro.html ... libraries, not an abstraction on top of iOS/Android. 3. ... The right tool for native development depends on why you want native in the fir

Download Professional Clojure Full eBook
Web Development with Clojure: Build Bulletproof Web Apps with Less Code · The Joy of ... Mastering Clojure Macros: Write Cleaner, Faster, Smarter Code.

Download Programming Clojure Full Books
Mastering Clojure Macros: Write Cleaner, Faster, Smarter Code · Building Microservices · Structure and Interpretation of Computer Programs, 2nd Edition (MIT ...

PDF Programming Clojure, 3e Full Books
Web Development with Clojure: Build Bulletproof Web Apps with Less Code ... Designing Data-Intensive Applications: The Big Ideas Behind Reliable, Scalable, ...

Read PdF Clojure for Data Science Full Online
Book Synopsis. Statistics, big data, and machine learning for Clojure. programmersAbout This. BookWrite code using. Clojure to harness the power.

PDF Download Mastering Clojure Macros: Write ...
discover how to write straightforward code that avoids duplication and clarifies ... Lisp "code-as-data" philosophy gives tremendous advantages to macro authors ...

pdf-1886\clojure-applied-from-practice-to-practitioner.pdf ...
pdf-1886\clojure-applied-from-practice-to-practitioner.pdf. pdf-1886\clojure-applied-from-practice-to-practitioner.pdf. Open. Extract. Open with. Sign In.