clojure at datastax: the long road from python to clojure

Post on 12-Apr-2017

518 Views

Category:

Software

5 Downloads

Preview:

Click to see full reader

TRANSCRIPT

CLOJURE AT DATASTAX: THE LONG ROAD FROM PYTHON TO CLOJURENick Bailey @nickmbailey

© 2016 DataStax, All Rights Reserved.

1 Introduction

2 Starting with Python

3 Clojure Enters the Ring

4 Clojure Everywhere!

5 Takeaways

2

© 2016 DataStax, All Rights Reserved. 3

1. Introduction

© 2016 DataStax, All Rights Reserved.

Me• DataStax • Clojure • Apache Cassandra • Austin

4

© 2016 DataStax, All Rights Reserved.

DataStax• DSE (distributed database) • Java

• OpsCenter • Python • Clojure

5

© 2016 DataStax, All Rights Reserved.

This talk• DataStax Clojure experience report • Python shop interested in Clojure? • Have a large python application you wish was written in Clojure?

6

© 2016 DataStax, All Rights Reserved. 7

2. Starting With Python

© 2016 DataStax, All Rights Reserved. 8

A long time ago in an galaxy far far away…

© 2016 DataStax, All Rights Reserved. 9

A long time ago in an office not far away…

(5 years ago)

© 2016 DataStax, All Rights Reserved.

Building a Database Monitoring Tool

10

© 2016 DataStax, All Rights Reserved.

Building a Database Monitoring Tool

11

© 2016 DataStax, All Rights Reserved.

Building a Database Monitoring Tool

12

© 2016 DataStax, All Rights Reserved. 13

Ok… but why?

© 2016 DataStax, All Rights Reserved.

Why Twisted?

14

• 2010 • 10ish person startup • 1 front-end dev • 1 back-end dev

© 2016 DataStax, All Rights Reserved.

Product Complexity Grows

15

• Single process isn’t enough • Need an agent to run on the cluster

© 2016 DataStax, All Rights Reserved.

Product Growth

16

© 2016 DataStax, All Rights Reserved.

Things go wrong

17

• The JVM doesn’t play nice • Python may not be the best choice for monitoring a JVM… • … but there is definitely a JVM available…

© 2016 DataStax, All Rights Reserved. 18

3. Clojure Enters the Ring

© 2016 DataStax, All Rights Reserved. 19

3. Clojure Enters the Ring (pun intended)

© 2016 DataStax, All Rights Reserved. 20

(still 5 years ago)

© 2016 DataStax, All Rights Reserved.

Replacement Needed

21

?

?

?

?

© 2016 DataStax, All Rights Reserved.

Responsibilities

22

• Gather and report metric data

© 2016 DataStax, All Rights Reserved.

Requirements

23

• Need to interact heavily with a JVM based database • Maintainability • Developer happiness

© 2016 DataStax, All Rights Reserved.

Contenders

24

• Java • Clojure • Scala • Jython

© 2016 DataStax, All Rights Reserved.

Why Clojure

25

• Isolated piece of the architecture • Immutability was a good fit • Great interoperability • An experiment worth taking a risk on

© 2016 DataStax, All Rights Reserved.

New Architecture

26

© 2016 DataStax, All Rights Reserved. 27

Experiment Results…

© 2016 DataStax, All Rights Reserved.

Smashing Success!

28

• Clojure fit all of our needs • Great recruitment tool • Clojure inspires passion • Picked up by new developers

© 2016 DataStax, All Rights Reserved.

On Learning Clojure

29

“…the most important transition will be opening your soul to Truth and Beauty, if you do so, Clojure will come naturally…”

—Philip Doctor

© 2016 DataStax, All Rights Reserved.

A Note on Hiring

30

• Datastax has a distributed engineering organization • Our clojure engineers span the globe

© 2016 DataStax, All Rights Reserved.

The rough edges

31

• Deployed on 1.2, immediate painful migration • JMX library unmaintained • Less mature libraries

© 2016 DataStax, All Rights Reserved. 32

Ok… why didn’t you just rewrite it all?

© 2016 DataStax, All Rights Reserved.

Hindsight is 20/20…

33

• Clojure was definitely considered an experiment/risk • Still a tiny startup • Bulk of code and functionality in the Twisted code

© 2016 DataStax, All Rights Reserved. 34

4. Clojure Everywhere!

© 2016 DataStax, All Rights Reserved. 35

Back to the future!

(ish)

© 2016 DataStax, All Rights Reserved.

What’s changed?

36

• 2 person team to 20 person team • Clojure codebase has grown significantly • JVM usage has increased across the company • Sorry Python, Clojure is the favorite child

© 2016 DataStax, All Rights Reserved.

Time to Reevaluate

37

?

© 2016 DataStax, All Rights Reserved.

Reevaluating Twisted

38

• Scalability requirements have grown • GIL rears it’s ugly head • Overlapping responsibilities

© 2016 DataStax, All Rights Reserved.

Reevaluating Twisted

39

• Need a path the JVM • Need to address scalability concerns

© 2016 DataStax, All Rights Reserved.

Possible Solutions

40

• Rewrite completely • Multiple processes • Jython?

© 2016 DataStax, All Rights Reserved.

Rewrite completely

41

• Benefit of hindsight when starting from the ground up • 4+ years invested • Pause feature development • Inevitable rewrite bugs introduced

© 2016 DataStax, All Rights Reserved.

Multiple Processes

42

• Less time intensive than a re-write • Can gradually move things out of python • Multi-processing is difficult • Untangling Twisted is extremely difficult • Adding IPC • Additional customer burden

© 2016 DataStax, All Rights Reserved.

Port to Jython

43

• Theoretically completely behind the scenes • Shortest path to being completely on the JVM • No out of the box support for Twisted • Introduction of a “third language” • The road less traveled

© 2016 DataStax, All Rights Reserved. 44

Jython Wins!

© 2016 DataStax, All Rights Reserved.

The Present

45

© 2016 DataStax, All Rights Reserved.

Migrating to Jython1. Make Twisted run on Jython 2. Replace all broken python libraries 3. Fix all the Jython* bugs you found 4. Write Jython <-> Clojure translation layer

46

© 2016 DataStax, All Rights Reserved.

1. Make Twisted run on Jython

47

• Upgrade Twisted • Start application on twisted • Get a stack trace and fix the issue • Rinse • Repeat

© 2016 DataStax, All Rights Reserved.

2. Replace all broken python libraries

48

• C extensions won’t run on Jython • SSL, LDAP, sqlite, crypto • Jython doesn’t support python sub processing

© 2016 DataStax, All Rights Reserved.

3. Fix all the Jython* bugs you found

49

• Brace yourselves…

© 2016 DataStax, All Rights Reserved.

3. Fix all the Jython* bugs you found

50

• Socket leaks • Deadlocks (including during garbage collection) • Incorrect socket implementations • Lots of SSL bugs • *And also 1 bug in Netty

© 2016 DataStax, All Rights Reserved. 51

If you thought stack traces and heap dumps were bad in Clojure…

© 2016 DataStax, All Rights Reserved.

Write Jython <-> Clojure translation layer

52

• The fun part • Clojure: “What’s a PyFunction object!?” • Jython: “Shut up, what’s an IPersistentVector!?” • Luckily, everyone speaks Java • https://gist.github.com/nickmbailey/3f11300e944e17d92edd6d42da785ab3

© 2016 DataStax, All Rights Reserved.

The Present

53

© 2016 DataStax, All Rights Reserved.

Success?

54

• There were some bumps a long the road • Took a lot longer than hoped • It was definitely the right choice

© 2016 DataStax, All Rights Reserved.

Over the Rainbow

55

© 2016 DataStax, All Rights Reserved. 56

Takeaways

© 2016 DataStax, All Rights Reserved.

Should I use Clojure?

57

• Yes, open yourself to Truth and Beauty

© 2016 DataStax, All Rights Reserved.

Should I not use Python?

58

• No one said that! • But if you are mainly interacting with the JVM… probably not.

© 2016 DataStax, All Rights Reserved.

Should I migrate my Python app to Clojure via Jython?

59

• Maybe? • Do you need to be on the JVM? • How much C code will you need to replace? • Are you brave enough to venture into the Jython codebase itself?

© 2016 DataStax, All Rights Reserved. 60

Questions? nickmbailey@gmail.com

top related