Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Production Clojure: An Experience Report

Shantanu Kumar
September 12, 2015

Production Clojure: An Experience Report

Talk slides from Functional Conf 2015:
http://confengine.com/functional-conf-2015/schedule#session-7456-info

Experience of using Clojure at Concur as of September 2015

Shantanu Kumar

September 12, 2015
Tweet

More Decks by Shantanu Kumar

Other Decks in Technology

Transcript

  1. Scope • Rebuilding the core platform • Pervasive decoupling and

    fault tolerance • Common services across products • Authentication, Authorization, Profile, Identity… 3
  2. Approach • Web services (microservices) • Shared nothing architecture •

    N, N+1 versions • Open Standards • REST • JSON • JSON Web Token (JWT) • X509, PKI • OAuth2, SAML 4
  3. Building microservices:
 First cut — The prototype • Leiningen (for

    builds) • Configuration properties file • Ring + Compojure • Jetty server (via uberjar) • clojure/java.jdbc (SQL Server) • couchbase-clj • 150-200ms response time 5
  4. “Shell” constituents • Logging: SLF4j + Logback + tools.logging +

    JSON • Mapped Diagnostic Context (MDC) wrapper • Web server: http-kit • JSON serialization: Cheshire • c3p0 (Instrumented JDBC connection pool) • Clojure equivalent of Hystrix core 9
  5. “Shell” Resiliency • In-house Clojure equivalent of Netflix Hystrix-core •

    Circuit breaker, Semaphore, Thread-pool, Metrics • Integrates with Hystrix-dashboard via SSE 11
  6. Performance (after tuning) • Sub milli-second response time (within datacenter)

    • Because in microservices, every service adds up • Measure in ns, optimize microseconds • Simulate load, stress for long duration 12
  7. External components • ElasticSearch, Logstash, Kibana (ELK) • Appdynamics •

    Yourkit profiler • Health checks (HTTP) • SQL Server • Couchbase 13
  8. Clojure impressions • First class values • Immutability, isolation (safety)

    • Functional programming (HoF, Transducers) • REPL • Easy side effects (I/O) • Java interop • Small language, easy to learn & reason about • Homoiconicity and macros 14
  9. ## Immutability, Isolation (Safety) • Epochal time model • Pro

    concurrency • Persistent data structures • Good performance 16
  10. Practices • IDE/editor — To each his own (Emacs, Eclipse,

    vi) • Most things are configurable (properties file) • Tests and launch must work from command line • Unit and integration tests are a must • Docker in development, QA and production • Internal Maven repository for JAR artifacts 21
  11. String concatenation — Stringer • https://github.com/kumarshantanu/stringer • Fast string concatenation

    • Pre-concatenation of literals at compile time • Caveat — not function 25
  12. JDBC access — Asphalt • https://github.com/kumarshantanu/asphalt • Functional design •

    Named parameters • Extensible (works with SQL generation libraries) • Precise control via type hints 29
  13. Comparative micro- benchmarking — Citius • https://github.com/kumarshantanu/citius • Comparative benchmarks

    using Criterium • Simulate load with concurrency • Setup can be tweaked • Built-in comparative latency bar charts 31
  14. Inter-layer latency finder — Espejito • https://github.com/kumarshantanu/espejito • Finds latency

    across layers • Summary reporting (customizable) • Low overhead • Programmable for conditional trigger 33
  15. Learning • Clojure (the language) is very well designed •

    Library eco-system is great, but still maturing • Java-interop is not the panacea • Adoption: Status-quo > other FP languages • Parentheses may cause knee-jerk reaction • Being on the JVM is a huge win 36