concurrency and distributed systems using jruby

47
CONCURRENCY AND DISTRIBUTED SYSTEMS IN JRUBY @iconara

Upload: iconara

Post on 01-Nov-2014

835 views

Category:

Technology


2 download

DESCRIPTION

Presented at JRubyConf EU August 2012

TRANSCRIPT

Page 1: Concurrency and Distributed Systems Using JRuby

CONCURRENCYAND DISTRIBUTED SYSTEMS IN JRUBY

@iconara

Page 2: Concurrency and Distributed Systems Using JRuby

speakerdeck.com/u/iconara(real time!)

Page 3: Concurrency and Distributed Systems Using JRuby

Theo / @iconara

Page 4: Concurrency and Distributed Systems Using JRuby

Chief Architect at

Page 5: Concurrency and Distributed Systems Using JRuby

big data with Ruby since 2009

Page 6: Concurrency and Distributed Systems Using JRuby

MAKING THIS

Page 7: Concurrency and Distributed Systems Using JRuby

INTO THIS

Page 8: Concurrency and Distributed Systems Using JRuby

big data with Ruby since 2009

Page 9: Concurrency and Distributed Systems Using JRuby

APRIL 2011stuck

Page 10: Concurrency and Distributed Systems Using JRuby

MAY 2011let’s try JRuby

Page 11: Concurrency and Distributed Systems Using JRuby

JUNE 2011wrapping Java libraries for fun and for profit

Page 12: Concurrency and Distributed Systems Using JRuby

HOTBUNNIESnatural Ruby API for RabbitMQ

Page 13: Concurrency and Distributed Systems Using JRuby

JULY 2011threads are better than processes

Page 14: Concurrency and Distributed Systems Using JRuby

JRUBY

Page 15: Concurrency and Distributed Systems Using JRuby

JRUBY

Page 16: Concurrency and Distributed Systems Using JRuby

J.U.C(java.util.concurrent)

Page 17: Concurrency and Distributed Systems Using JRuby

SHORTCUTJava Concurrency in Practice

Page 18: Concurrency and Distributed Systems Using JRuby

EXECUTORSconfigurable thread pools, a better

abstraction than using Thread directly

Page 19: Concurrency and Distributed Systems Using JRuby

thread_pool = Executors.new_fixed_thread_pool(16)

all_the_things.each do |thing| thread_pool.submit do crunch_crunch_crunch(thing) endend

Page 20: Concurrency and Distributed Systems Using JRuby

BLOCKING QUEUESeasy producer/consumer patterns

Page 21: Concurrency and Distributed Systems Using JRuby

J.U.C.ATOMICoptimistic locking primitives,

compare-and-swap, thread safe non-blocking counters

Page 22: Concurrency and Distributed Systems Using JRuby

MORE AWESOMESConcurrentHashMap, CountDownLatch,

ForkJoinPool, Google Guava, LMAX distruptor

Page 23: Concurrency and Distributed Systems Using JRuby

TL; DRuse j.u.c and avoid mutable state

and you’re safe, mostly

Page 24: Concurrency and Distributed Systems Using JRuby

enough ropeTHREADS

Page 25: Concurrency and Distributed Systems Using JRuby

AUGUST 2011threads are a mess, let’s try actors

Page 26: Concurrency and Distributed Systems Using JRuby

ACTORSa higher level abstraction of concurrency

Page 27: Concurrency and Distributed Systems Using JRuby

AKKAconcurrency library for Scala,famous actor implementation

Page 28: Concurrency and Distributed Systems Using JRuby

MIKKAAkka wrapper for JRuby

Page 29: Concurrency and Distributed Systems Using JRuby

DO ALL THE THINGSProgramming Concurrency on the JVM

Page 30: Concurrency and Distributed Systems Using JRuby

AUGUST 2011async systems with no back pressure

mechanism will die of memory starvation

Page 31: Concurrency and Distributed Systems Using JRuby

STATE

AGGREGATION

INPUT

PERSISTENCE

OUTPUT

TIMER

Page 32: Concurrency and Distributed Systems Using JRuby

STATE

AGGREGATION

INPUT

PERSISTENCE

OUTPUT

TIMER

!

Page 33: Concurrency and Distributed Systems Using JRuby

AUGUST 2011actors are cool, but not really

worth it when all the arrows in your flow chart point in the same direction

Page 34: Concurrency and Distributed Systems Using JRuby

DIVIDE DIVIDE DIVIDErun multiple independent, synchronous workers,

tune to the number of CPUs & IO wait

Page 35: Concurrency and Distributed Systems Using JRuby

SEPTEMBER 2011blocking all the way down,

back pressure all the way up

Page 36: Concurrency and Distributed Systems Using JRuby

AUGUST 2011(short rant about MongoDB’s global write lock)

Page 37: Concurrency and Distributed Systems Using JRuby

NEW SHINY TOYSfor building new shiny products

Page 38: Concurrency and Distributed Systems Using JRuby

CASSANDRAdistributed database, mostly magic

Page 39: Concurrency and Distributed Systems Using JRuby

CASSANDRAvery verbose drivers

ColumnFamilyUpdater<String, String> updater = template.createUpdater("a key");updater.setString("domain", "www.datastax.com");updater.setLong("time", System.currentTimeMillis());

try { template.update(updater);} catch (HectorException e) { // hurgh}

Page 40: Concurrency and Distributed Systems Using JRuby

EURYDICEJRuby nails it

new_data = {:domain => 'www.datastax.com', :time => Time.now.to_i}column_family.update('a key', new_data)

Page 41: Concurrency and Distributed Systems Using JRuby

STORMstream processing framework written in Clojure

Page 42: Concurrency and Distributed Systems Using JRuby

STORM(it does the arrows, you do the blobs)

Page 43: Concurrency and Distributed Systems Using JRuby

REDSTORMStorm for JRuby

Page 44: Concurrency and Distributed Systems Using JRuby

DON’T DO THIS AT HOME KIDS!the key to building concurrent and distributed

systems is to separate what you want to do from the concurrent- and distributed-ness, and let someone

else take care of that

YOUR CODE

Page 45: Concurrency and Distributed Systems Using JRuby

JRUBY IS A SLIPPERY SLOPE TO JBOSS

let there be no doubt about it

Page 46: Concurrency and Distributed Systems Using JRuby

SCALING IS HARDgo to Srdan’s talk tomorrow

Page 47: Concurrency and Distributed Systems Using JRuby

KTHXBAI@iconara

github.com/iconaraarchitecturalatrocities.com

burtcorp.com