84
How I Learned to Stop Worrying & Love the λ or Dr. Strange-λ Todd L. Montgomery @toddlmontgomery

How I Learned to Stop Worrying & Love the or Dr. …...How I Learned to Stop Worrying & Love the λ or Dr. Strange-λ Todd L. Montgomery @toddlmontgomery λ Haskell Erlang λ λ Clojure

  • Upload
    others

  • View
    8

  • Download
    0

Embed Size (px)

Citation preview

Page 1: How I Learned to Stop Worrying & Love the or Dr. …...How I Learned to Stop Worrying & Love the λ or Dr. Strange-λ Todd L. Montgomery @toddlmontgomery λ Haskell Erlang λ λ Clojure

How I Learned to Stop Worrying & Love the λ or

Dr. Strange-λTodd L. Montgomery @toddlmontgomery

Page 2: How I Learned to Stop Worrying & Love the or Dr. …...How I Learned to Stop Worrying & Love the λ or Dr. Strange-λ Todd L. Montgomery @toddlmontgomery λ Haskell Erlang λ λ Clojure
Page 3: How I Learned to Stop Worrying & Love the or Dr. …...How I Learned to Stop Worrying & Love the λ or Dr. Strange-λ Todd L. Montgomery @toddlmontgomery λ Haskell Erlang λ λ Clojure

λ

Page 4: How I Learned to Stop Worrying & Love the or Dr. …...How I Learned to Stop Worrying & Love the λ or Dr. Strange-λ Todd L. Montgomery @toddlmontgomery λ Haskell Erlang λ λ Clojure

Haskell

Erlang

λ

Page 5: How I Learned to Stop Worrying & Love the or Dr. …...How I Learned to Stop Worrying & Love the λ or Dr. Strange-λ Todd L. Montgomery @toddlmontgomery λ Haskell Erlang λ λ Clojure

λ

ClojureHaskell

ErlangGroovy

Scala

Page 6: How I Learned to Stop Worrying & Love the or Dr. …...How I Learned to Stop Worrying & Love the λ or Dr. Strange-λ Todd L. Montgomery @toddlmontgomery λ Haskell Erlang λ λ Clojure

λ

ClojureHaskell

ErlangGroovy

C#

C++11Scala

Page 7: How I Learned to Stop Worrying & Love the or Dr. …...How I Learned to Stop Worrying & Love the λ or Dr. Strange-λ Todd L. Montgomery @toddlmontgomery λ Haskell Erlang λ λ Clojure

λ

Scala

ClojureHaskell

ErlangGroovy

C#

C++11

C11

Page 8: How I Learned to Stop Worrying & Love the or Dr. …...How I Learned to Stop Worrying & Love the λ or Dr. Strange-λ Todd L. Montgomery @toddlmontgomery λ Haskell Erlang λ λ Clojure
Page 9: How I Learned to Stop Worrying & Love the or Dr. …...How I Learned to Stop Worrying & Love the λ or Dr. Strange-λ Todd L. Montgomery @toddlmontgomery λ Haskell Erlang λ λ Clojure

9

“Mr. President,"we must not allooooow a "

Lambda Gap!”

Page 10: How I Learned to Stop Worrying & Love the or Dr. …...How I Learned to Stop Worrying & Love the λ or Dr. Strange-λ Todd L. Montgomery @toddlmontgomery λ Haskell Erlang λ λ Clojure

Java 8

Page 11: How I Learned to Stop Worrying & Love the or Dr. …...How I Learned to Stop Worrying & Love the λ or Dr. Strange-λ Todd L. Montgomery @toddlmontgomery λ Haskell Erlang λ λ Clojure

What could we do…"green field…

Page 12: How I Learned to Stop Worrying & Love the or Dr. …...How I Learned to Stop Worrying & Love the λ or Dr. Strange-λ Todd L. Montgomery @toddlmontgomery λ Haskell Erlang λ λ Clojure

Perfect Timing!

Page 13: How I Learned to Stop Worrying & Love the or Dr. …...How I Learned to Stop Worrying & Love the λ or Dr. Strange-λ Todd L. Montgomery @toddlmontgomery λ Haskell Erlang λ λ Clojure

Aeronhttps://github.com/real-logic/Aeron

Page 14: How I Learned to Stop Worrying & Love the or Dr. …...How I Learned to Stop Worrying & Love the λ or Dr. Strange-λ Todd L. Montgomery @toddlmontgomery λ Haskell Erlang λ λ Clojure

Low Latency"High Throughput"

Open Source"Messaging Transport

Page 15: How I Learned to Stop Worrying & Love the or Dr. …...How I Learned to Stop Worrying & Love the λ or Dr. Strange-λ Todd L. Montgomery @toddlmontgomery λ Haskell Erlang λ λ Clojure
Page 16: How I Learned to Stop Worrying & Love the or Dr. …...How I Learned to Stop Worrying & Love the λ or Dr. Strange-λ Todd L. Montgomery @toddlmontgomery λ Haskell Erlang λ λ Clojure

“Mr. President, the technology required is easily within the means of even the smallest

nuclear power. It requires only the will to do so.”

Page 17: How I Learned to Stop Worrying & Love the or Dr. …...How I Learned to Stop Worrying & Love the λ or Dr. Strange-λ Todd L. Montgomery @toddlmontgomery λ Haskell Erlang λ λ Clojure

Todd Montgomery Richard Warburton

Martin Thompson

The Aeron Team

Page 18: How I Learned to Stop Worrying & Love the or Dr. …...How I Learned to Stop Worrying & Love the λ or Dr. Strange-λ Todd L. Montgomery @toddlmontgomery λ Haskell Erlang λ λ Clojure

Why?

Page 19: How I Learned to Stop Worrying & Love the or Dr. …...How I Learned to Stop Worrying & Love the λ or Dr. Strange-λ Todd L. Montgomery @toddlmontgomery λ Haskell Erlang λ λ Clojure

Latency "is"

[lost] opportunity

In finance & other places…

Page 20: How I Learned to Stop Worrying & Love the or Dr. …...How I Learned to Stop Worrying & Love the λ or Dr. Strange-λ Todd L. Montgomery @toddlmontgomery λ Haskell Erlang λ λ Clojure

Capital Markets

Page 21: How I Learned to Stop Worrying & Love the or Dr. …...How I Learned to Stop Worrying & Love the λ or Dr. Strange-λ Todd L. Montgomery @toddlmontgomery λ Haskell Erlang λ λ Clojure

The FX Trader

$ / £ = 0.6375"£ / ¥ = 123.77"¥ / $ = 0.0127

$1,000,000 = £637,500""

£637,500 = 78,903,375¥""

78,903,375¥ = $1,002,072""

CHA-CHING!

Currency Pairs Trades

¥ / $ = 0.0126

78,903,375¥ = $994,182.53 !!!

Page 22: How I Learned to Stop Worrying & Love the or Dr. …...How I Learned to Stop Worrying & Love the λ or Dr. Strange-λ Todd L. Montgomery @toddlmontgomery λ Haskell Erlang λ λ Clojure

Ad Market

Page 23: How I Learned to Stop Worrying & Love the or Dr. …...How I Learned to Stop Worrying & Love the λ or Dr. Strange-λ Todd L. Montgomery @toddlmontgomery λ Haskell Erlang λ λ Clojure

Sports & Entertainment

Page 24: How I Learned to Stop Worrying & Love the or Dr. …...How I Learned to Stop Worrying & Love the λ or Dr. Strange-λ Todd L. Montgomery @toddlmontgomery λ Haskell Erlang λ λ Clojure

Logistics

Page 25: How I Learned to Stop Worrying & Love the or Dr. …...How I Learned to Stop Worrying & Love the λ or Dr. Strange-λ Todd L. Montgomery @toddlmontgomery λ Haskell Erlang λ λ Clojure

Why Java?Why even an OS?

Why even …

Don't Settle!

Don’t Compromise!

Page 26: How I Learned to Stop Worrying & Love the or Dr. …...How I Learned to Stop Worrying & Love the λ or Dr. Strange-λ Todd L. Montgomery @toddlmontgomery λ Haskell Erlang λ λ Clojure
Page 27: How I Learned to Stop Worrying & Love the or Dr. …...How I Learned to Stop Worrying & Love the λ or Dr. Strange-λ Todd L. Montgomery @toddlmontgomery λ Haskell Erlang λ λ Clojure
Page 28: How I Learned to Stop Worrying & Love the or Dr. …...How I Learned to Stop Worrying & Love the λ or Dr. Strange-λ Todd L. Montgomery @toddlmontgomery λ Haskell Erlang λ λ Clojure

Design Principles

1. Garbage free in steady state running"2. Apply Smart Batching in the message path"3. Wait-free algorithms in the message path"4. Non-blocking IO in the message path"5. No exceptional cases in the message path"6. Apply the Single Writer Principle"7. Prefer unshared state"8. Avoid unnecessary data copies

https://github.com/real-logic/Aeron/wiki/Design-Principles

Page 29: How I Learned to Stop Worrying & Love the or Dr. …...How I Learned to Stop Worrying & Love the λ or Dr. Strange-λ Todd L. Montgomery @toddlmontgomery λ Haskell Erlang λ λ Clojure

And, yes, Unsafe

Page 30: How I Learned to Stop Worrying & Love the or Dr. …...How I Learned to Stop Worrying & Love the λ or Dr. Strange-λ Todd L. Montgomery @toddlmontgomery λ Haskell Erlang λ λ Clojure
Page 31: How I Learned to Stop Worrying & Love the or Dr. …...How I Learned to Stop Worrying & Love the λ or Dr. Strange-λ Todd L. Montgomery @toddlmontgomery λ Haskell Erlang λ λ Clojure

But…"We have the launch codes"

so, it’s cool

Page 32: How I Learned to Stop Worrying & Love the or Dr. …...How I Learned to Stop Worrying & Love the λ or Dr. Strange-λ Todd L. Montgomery @toddlmontgomery λ Haskell Erlang λ λ Clojure

Publisher

Subscriber

Subscriber

Publisher

Architecture

IPC Log Buffer

Page 33: How I Learned to Stop Worrying & Love the or Dr. …...How I Learned to Stop Worrying & Love the λ or Dr. Strange-λ Todd L. Montgomery @toddlmontgomery λ Haskell Erlang λ λ Clojure

Sender

Receiver

Receiver

Sender

Publisher

Subscriber

Subscriber

Publisher

Architecture

Media

IPC Log BufferMedia (UDP, InfiniBand, PCI-e 3.0)

Page 34: How I Learned to Stop Worrying & Love the or Dr. …...How I Learned to Stop Worrying & Love the λ or Dr. Strange-λ Todd L. Montgomery @toddlmontgomery λ Haskell Erlang λ λ Clojure

Conductor

Sender

Receiver

Conductor

Receiver

Sender

Publisher

Subscriber

Subscriber

Publisher

Admin

Events

Architecture

Admin

EventsMedia

IPC Log BufferMedia (UDP, InfiniBand, PCI-e 3.0)Function/Method CallVolatile Fields & Queues

Page 35: How I Learned to Stop Worrying & Love the or Dr. …...How I Learned to Stop Worrying & Love the λ or Dr. Strange-λ Todd L. Montgomery @toddlmontgomery λ Haskell Erlang λ λ Clojure

ClientMedia DriverMedia Driver

Conductor

Sender

Receiver

Conductor

Receiver

Sender

Client

Publisher

Conductor Conductor

Subscriber

Subscriber

Publisher

Admin

Events

Architecture

Admin

EventsMedia

IPC Log Buffer

IPC Ring/Broadcast Buffer

Media (UDP, InfiniBand, PCI-e 3.0)Function/Method CallVolatile Fields & Queues

Page 36: How I Learned to Stop Worrying & Love the or Dr. …...How I Learned to Stop Worrying & Love the λ or Dr. Strange-λ Todd L. Montgomery @toddlmontgomery λ Haskell Erlang λ λ Clojure

Much, much more…"but…

Page 37: How I Learned to Stop Worrying & Love the or Dr. …...How I Learned to Stop Worrying & Love the λ or Dr. Strange-λ Todd L. Montgomery @toddlmontgomery λ Haskell Erlang λ λ Clojure

Java 8…

Page 38: How I Learned to Stop Worrying & Love the or Dr. …...How I Learned to Stop Worrying & Love the λ or Dr. Strange-λ Todd L. Montgomery @toddlmontgomery λ Haskell Erlang λ λ Clojure

What have we learned?

Page 39: How I Learned to Stop Worrying & Love the or Dr. …...How I Learned to Stop Worrying & Love the λ or Dr. Strange-λ Todd L. Montgomery @toddlmontgomery λ Haskell Erlang λ λ Clojure

Stream API

Too much garbage!"Immature for now…

Page 40: How I Learned to Stop Worrying & Love the or Dr. …...How I Learned to Stop Worrying & Love the λ or Dr. Strange-λ Todd L. Montgomery @toddlmontgomery λ Haskell Erlang λ λ Clojure

JMC

Very handy. Use it!

Page 41: How I Learned to Stop Worrying & Love the or Dr. …...How I Learned to Stop Worrying & Love the λ or Dr. Strange-λ Todd L. Montgomery @toddlmontgomery λ Haskell Erlang λ λ Clojure

LOCK XADD

AtomicLong.getAndIncrement() Unsafe.getAndAddLong(…)

Replacing a CAS on x86!! HOT!!

Page 42: How I Learned to Stop Worrying & Love the or Dr. …...How I Learned to Stop Worrying & Love the λ or Dr. Strange-λ Todd L. Montgomery @toddlmontgomery λ Haskell Erlang λ λ Clojure

And, of course…

Page 43: How I Learned to Stop Worrying & Love the or Dr. …...How I Learned to Stop Worrying & Love the λ or Dr. Strange-λ Todd L. Montgomery @toddlmontgomery λ Haskell Erlang λ λ Clojure

Lambdas [& Allocation]

Page 44: How I Learned to Stop Worrying & Love the or Dr. …...How I Learned to Stop Worrying & Love the λ or Dr. Strange-λ Todd L. Montgomery @toddlmontgomery λ Haskell Erlang λ λ Clojure

Design Principles

1. Garbage free in steady state running!2. Apply Smart Batching in the message path"3. Wait-free algorithms in the message path!4. Non-blocking IO in the message path"5. No exceptional cases in the message path"6. Apply the Single Writer Principle"7. Prefer unshared state"8. Avoid unnecessary data copies

https://github.com/real-logic/Aeron/wiki/Design-Principles

Page 45: How I Learned to Stop Worrying & Love the or Dr. …...How I Learned to Stop Worrying & Love the λ or Dr. Strange-λ Todd L. Montgomery @toddlmontgomery λ Haskell Erlang λ λ Clojure

public void something() { List<Object> l = new ArrayList<>(); final int value = 10; " l.forEach(this::func); l.forEach((o) -> staticMethod(value)); l.forEach((o) -> this.func()); }

Page 46: How I Learned to Stop Worrying & Love the or Dr. …...How I Learned to Stop Worrying & Love the λ or Dr. Strange-λ Todd L. Montgomery @toddlmontgomery λ Haskell Erlang λ λ Clojure

http://mail.openjdk.java.net/pipermail/lambda-dev/2014-August/012097.html

public void something() { List<Object> l = new ArrayList<>(); final int value = 10; " l.forEach(this::func); l.forEach((o) -> staticMethod(value)); l.forEach((o) -> this.func()); }

http://www.infoq.com/articles/Java-8-Lambdas-A-Peek-Under-the-Hood

Each time something called, it allocates 3 lambdas!!!

Page 47: How I Learned to Stop Worrying & Love the or Dr. …...How I Learned to Stop Worrying & Love the λ or Dr. Strange-λ Todd L. Montgomery @toddlmontgomery λ Haskell Erlang λ λ Clojure

http://mail.openjdk.java.net/pipermail/lambda-dev/2014-August/012097.html

public void something() { List<Object> l = new ArrayList<>(); final int value = 10; " l.forEach(this::func); l.forEach((o) -> staticMethod(value)); l.forEach((o) -> this.func()); }

http://www.infoq.com/articles/Java-8-Lambdas-A-Peek-Under-the-Hood

Why? Capturing this or value

Page 48: How I Learned to Stop Worrying & Love the or Dr. …...How I Learned to Stop Worrying & Love the λ or Dr. Strange-λ Todd L. Montgomery @toddlmontgomery λ Haskell Erlang λ λ Clojure

But…"Lambdas Optimize Well

Page 49: How I Learned to Stop Worrying & Love the or Dr. …...How I Learned to Stop Worrying & Love the λ or Dr. Strange-λ Todd L. Montgomery @toddlmontgomery λ Haskell Erlang λ λ Clojure

More things about"Good Ol’ Java…"

(not Java 8 specific)

Page 50: How I Learned to Stop Worrying & Love the or Dr. …...How I Learned to Stop Worrying & Love the λ or Dr. Strange-λ Todd L. Montgomery @toddlmontgomery λ Haskell Erlang λ λ Clojure

Lack of Unsigned Types

Page 51: How I Learned to Stop Worrying & Love the or Dr. …...How I Learned to Stop Worrying & Love the λ or Dr. Strange-λ Todd L. Montgomery @toddlmontgomery λ Haskell Erlang λ λ Clojure

51

Page 52: How I Learned to Stop Worrying & Love the or Dr. …...How I Learned to Stop Worrying & Love the λ or Dr. Strange-λ Todd L. Montgomery @toddlmontgomery λ Haskell Erlang λ λ Clojure

Lack of [Efficient]"Primitive Maps"

"

Map<int,? extends Object> Map<long,? extends Object>

http://openjdk.java.net/jeps/8046267

Page 53: How I Learned to Stop Worrying & Love the or Dr. …...How I Learned to Stop Worrying & Love the λ or Dr. Strange-λ Todd L. Montgomery @toddlmontgomery λ Haskell Erlang λ λ Clojure

public static void main(final String[] args) { byte a = 0b0000_0001; byte b = 0b0000_0010; " byte flags = a | b; " System.out.printf( "flags=%s\n", Integer.toBinaryString(flags)); }

Page 54: How I Learned to Stop Worrying & Love the or Dr. …...How I Learned to Stop Worrying & Love the λ or Dr. Strange-λ Todd L. Montgomery @toddlmontgomery λ Haskell Erlang λ λ Clojure

public static void main(final String[] args) { byte a = 0b0000_0001; byte b = 0b0000_0010; " byte flags = a | b; " System.out.printf( "flags=%s\n", Integer.toBinaryString(flags)); }

Page 55: How I Learned to Stop Worrying & Love the or Dr. …...How I Learned to Stop Worrying & Love the λ or Dr. Strange-λ Todd L. Montgomery @toddlmontgomery λ Haskell Erlang λ λ Clojure

public void main(final String[] args) { byte a = 0b0000_0001; byte b = 0b0000_0010; " byte flags = a | b; " System.out.printf( "flags=%s\n", Integer.toBinaryString(flags)); } Erro

r:(8,  24

)  java:  in

compat

ible  typ

es:    

possibl

e  lossy  

conver

sion  fro

m  int  t

o  byte

Does not inspire confidence…

Page 56: How I Learned to Stop Worrying & Love the or Dr. …...How I Learned to Stop Worrying & Love the λ or Dr. Strange-λ Todd L. Montgomery @toddlmontgomery λ Haskell Erlang λ λ Clojure

NIO

Page 57: How I Learned to Stop Worrying & Love the or Dr. …...How I Learned to Stop Worrying & Love the λ or Dr. Strange-λ Todd L. Montgomery @toddlmontgomery λ Haskell Erlang λ λ Clojure

To an old network hacker, feels a bit “phoned” in…

Page 58: How I Learned to Stop Worrying & Love the or Dr. …...How I Learned to Stop Worrying & Love the λ or Dr. Strange-λ Todd L. Montgomery @toddlmontgomery λ Haskell Erlang λ λ Clojure

ByteBuffer & “Strangs”

Page 59: How I Learned to Stop Worrying & Love the or Dr. …...How I Learned to Stop Worrying & Love the λ or Dr. Strange-λ Todd L. Montgomery @toddlmontgomery λ Haskell Erlang λ λ Clojure

public void send(final String s) { // b be reused ByteBuffer " // allocating hot mess b.put(s.getBytes()); " // what could be… but JDK playin… b.put(s); }

http://mail.openjdk.java.net/pipermail/core-libs-dev/2014-September/028837.html

Allocate mutable from immutable…

Page 60: How I Learned to Stop Worrying & Love the or Dr. …...How I Learned to Stop Worrying & Love the λ or Dr. Strange-λ Todd L. Montgomery @toddlmontgomery λ Haskell Erlang λ λ Clojure

public String receive(final ByteBuffer b) { // could reuse, but that’s HARD byte[] tmp = new byte[b.remaining()]; " // allocating hot mess b.get(tmp, offset, length); return new String(tmp); " // what could be… but JDK playin… return new String(b, offset, length); }

http://mail.openjdk.java.net/pipermail/core-libs-dev/2014-September/028837.html

Yes, Charset, yes…

Page 61: How I Learned to Stop Worrying & Love the or Dr. …...How I Learned to Stop Worrying & Love the λ or Dr. Strange-λ Todd L. Montgomery @toddlmontgomery λ Haskell Erlang λ λ Clojure

STRINGS!

Page 62: How I Learned to Stop Worrying & Love the or Dr. …...How I Learned to Stop Worrying & Love the λ or Dr. Strange-λ Todd L. Montgomery @toddlmontgomery λ Haskell Erlang λ λ Clojure

NIO & Locks

Page 63: How I Learned to Stop Worrying & Love the or Dr. …...How I Learned to Stop Worrying & Love the λ or Dr. Strange-λ Todd L. Montgomery @toddlmontgomery λ Haskell Erlang λ λ Clojure

When Threads Collide…

Page 64: How I Learned to Stop Worrying & Love the or Dr. …...How I Learned to Stop Worrying & Love the λ or Dr. Strange-λ Todd L. Montgomery @toddlmontgomery λ Haskell Erlang λ λ Clojure

“You can’t fight in here, this is the War Room!”

Page 65: How I Learned to Stop Worrying & Love the or Dr. …...How I Learned to Stop Worrying & Love the λ or Dr. Strange-λ Todd L. Montgomery @toddlmontgomery λ Haskell Erlang λ λ Clojure

DatagramChannelImpl

http://grepcode.com/file/repository.grepcode.com/java/root/jdk/openjdk/8-b132/sun/nio/ch/DatagramChannelImpl.java#DatagramChannelImpl

public int write(ByteBuffer buf) { synchronized (writeLock) { synchronized (stateLock) { … } … } } "public int read(ByteBuffer buf) { synchronized (readLock) { synchronized (stateLock) { … } … } }

send & receive are similar

Page 66: How I Learned to Stop Worrying & Love the or Dr. …...How I Learned to Stop Worrying & Love the λ or Dr. Strange-λ Todd L. Montgomery @toddlmontgomery λ Haskell Erlang λ λ Clojure

Why would we care?

Page 67: How I Learned to Stop Worrying & Love the or Dr. …...How I Learned to Stop Worrying & Love the λ or Dr. Strange-λ Todd L. Montgomery @toddlmontgomery λ Haskell Erlang λ λ Clojure

Firewall Traversal

Page 68: How I Learned to Stop Worrying & Love the or Dr. …...How I Learned to Stop Worrying & Love the λ or Dr. Strange-λ Todd L. Montgomery @toddlmontgomery λ Haskell Erlang λ λ Clojure

SelectorImpl &"

Locks

http://grepcode.com/file/repository.grepcode.com/java/root/jdk/openjdk/8-b132/sun/nio/ch/SelectorImpl.java#SelectorImpl

Second verse, same as the first…

Page 69: How I Learned to Stop Worrying & Love the or Dr. …...How I Learned to Stop Worrying & Love the λ or Dr. Strange-λ Todd L. Montgomery @toddlmontgomery λ Haskell Erlang λ λ Clojure

FileChannel.transferTo &"

DatagramChannel

Page 70: How I Learned to Stop Worrying & Love the or Dr. …...How I Learned to Stop Worrying & Love the λ or Dr. Strange-λ Todd L. Montgomery @toddlmontgomery λ Haskell Erlang λ λ Clojure

FileChannel.transferTo &"

DatagramChannel

Observed on Mac:"call sendfile, get EINVAL, call sendto

over and over

Platform Dependent, sure

Page 71: How I Learned to Stop Worrying & Love the or Dr. …...How I Learned to Stop Worrying & Love the λ or Dr. Strange-λ Todd L. Montgomery @toddlmontgomery λ Haskell Erlang λ λ Clojure

SelectorImpl &"

HashSet Garbage

http://grepcode.com/file/repository.grepcode.com/java/root/jdk/openjdk/8-b132/sun/nio/ch/SelectorImpl.java#SelectorImpl

Page 72: How I Learned to Stop Worrying & Love the or Dr. …...How I Learned to Stop Worrying & Love the λ or Dr. Strange-λ Todd L. Montgomery @toddlmontgomery λ Haskell Erlang λ λ Clojure
Page 73: How I Learned to Stop Worrying & Love the or Dr. …...How I Learned to Stop Worrying & Love the λ or Dr. Strange-λ Todd L. Montgomery @toddlmontgomery λ Haskell Erlang λ λ Clojure

public void handleFds(Selector selector) { final Set<SelectionKey> keys = selector.selectedKeys(); " if (!keys.isEmpty()) { final Iterator<SelectionKey> iter = keys.iterator(); while (iter.hasNext()) { … } } }

Page 74: How I Learned to Stop Worrying & Love the or Dr. …...How I Learned to Stop Worrying & Love the λ or Dr. Strange-λ Todd L. Montgomery @toddlmontgomery λ Haskell Erlang λ λ Clojure

Whoa!… Java 8-ize!

Page 75: How I Learned to Stop Worrying & Love the or Dr. …...How I Learned to Stop Worrying & Love the λ or Dr. Strange-λ Todd L. Montgomery @toddlmontgomery λ Haskell Erlang λ λ Clojure

public void handleFds(Selector selector) { final Set<SelectionKey> keys = selector.selectedKeys(); " keys.forEach((key) -> { … }); }

HashSet usage means node garbage"so…"

Borrow from netty.io & replace"publicSelectedKeys &

selectedKeys

https://github.com/netty/netty/blob/master/transport/src/main/java/io/netty/channel/nio/NioEventLoop.javahttps://github.com/netty/netty/blob/master/transport/src/main/java/io/netty/channel/nio/SelectedSelectionKeySet.java

Page 76: How I Learned to Stop Worrying & Love the or Dr. …...How I Learned to Stop Worrying & Love the λ or Dr. Strange-λ Todd L. Montgomery @toddlmontgomery λ Haskell Erlang λ λ Clojure
Page 77: How I Learned to Stop Worrying & Love the or Dr. …...How I Learned to Stop Worrying & Love the λ or Dr. Strange-λ Todd L. Montgomery @toddlmontgomery λ Haskell Erlang λ λ Clojure

public void handleFds(Selector selector) { // optimize underneath, more usable API selector.forEachSelectedKey( (key) -> { … }); }

What it could be…"and something optimized underneath

Page 78: How I Learned to Stop Worrying & Love the or Dr. …...How I Learned to Stop Worrying & Love the λ or Dr. Strange-λ Todd L. Montgomery @toddlmontgomery λ Haskell Erlang λ λ Clojure

Just "the"tip"…"but"

some"times"

Page 79: How I Learned to Stop Worrying & Love the or Dr. …...How I Learned to Stop Worrying & Love the λ or Dr. Strange-λ Todd L. Montgomery @toddlmontgomery λ Haskell Erlang λ λ Clojure

But what can happen"when you get it right?

Page 80: How I Learned to Stop Worrying & Love the or Dr. …...How I Learned to Stop Worrying & Love the λ or Dr. Strange-λ Todd L. Montgomery @toddlmontgomery λ Haskell Erlang λ λ Clojure
Page 81: How I Learned to Stop Worrying & Love the or Dr. …...How I Learned to Stop Worrying & Love the λ or Dr. Strange-λ Todd L. Montgomery @toddlmontgomery λ Haskell Erlang λ λ Clojure

20+ million msgs/sec"single stream (NO contention)

40 byte messages

Page 82: How I Learned to Stop Worrying & Love the or Dr. …...How I Learned to Stop Worrying & Love the λ or Dr. Strange-λ Todd L. Montgomery @toddlmontgomery λ Haskell Erlang λ λ Clojure
Page 83: How I Learned to Stop Worrying & Love the or Dr. …...How I Learned to Stop Worrying & Love the λ or Dr. Strange-λ Todd L. Montgomery @toddlmontgomery λ Haskell Erlang λ λ Clojure

Not Just Java"C++, Erlang, Go, …

InfiniBand, PCI-e 3.0, …

Page 84: How I Learned to Stop Worrying & Love the or Dr. …...How I Learned to Stop Worrying & Love the λ or Dr. Strange-λ Todd L. Montgomery @toddlmontgomery λ Haskell Erlang λ λ Clojure

@toddlmontgomery

Questions?

• Aeron https://github.com/real-logic/Aeron"• Kaazing http://www.kaazing.com"• SlideShare http://www.slideshare.com/toddleemontgomery"• Twitter @toddlmontgomery

Thank You!