mario donkey kong · distribution, distances, concurrency, commodity, scale: all these are reasons...

127

Upload: trinhtuyen

Post on 15-Dec-2018

217 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Mario Donkey Kong · Distribution, distances, concurrency, commodity, scale: all these are reasons why parts of a system can anytime crash
Page 2: Mario Donkey Kong · Distribution, distances, concurrency, commodity, scale: all these are reasons why parts of a system can anytime crash

MarioMariovs.

Donkey Kong

Page 3: Mario Donkey Kong · Distribution, distances, concurrency, commodity, scale: all these are reasons why parts of a system can anytime crash

…oh, Pardon…

Page 4: Mario Donkey Kong · Distribution, distances, concurrency, commodity, scale: all these are reasons why parts of a system can anytime crash

Erlang/OTPvs.

Enterprise Java

Page 5: Mario Donkey Kong · Distribution, distances, concurrency, commodity, scale: all these are reasons why parts of a system can anytime crash

PavloBaron

Page 6: Mario Donkey Kong · Distribution, distances, concurrency, commodity, scale: all these are reasons why parts of a system can anytime crash
Page 7: Mario Donkey Kong · Distribution, distances, concurrency, commodity, scale: all these are reasons why parts of a system can anytime crash

www.pbit.orgwww.pbit.org

[email protected]

@pavlobaron@pavlobaron

Page 8: Mario Donkey Kong · Distribution, distances, concurrency, commodity, scale: all these are reasons why parts of a system can anytime crash
Page 9: Mario Donkey Kong · Distribution, distances, concurrency, commodity, scale: all these are reasons why parts of a system can anytime crash

Why am I talking Why am I talking about it

Page 10: Mario Donkey Kong · Distribution, distances, concurrency, commodity, scale: all these are reasons why parts of a system can anytime crash

Do you think it’s about heart?

Page 11: Mario Donkey Kong · Distribution, distances, concurrency, commodity, scale: all these are reasons why parts of a system can anytime crash

Or is there another reason?

Page 12: Mario Donkey Kong · Distribution, distances, concurrency, commodity, scale: all these are reasons why parts of a system can anytime crash

I DON‘TLIKELIKE

JAVA!

Page 13: Mario Donkey Kong · Distribution, distances, concurrency, commodity, scale: all these are reasons why parts of a system can anytime crash

The world of IT, as we knew it, has knew it, has changed…

Page 14: Mario Donkey Kong · Distribution, distances, concurrency, commodity, scale: all these are reasons why parts of a system can anytime crash

Instead of huge cabinets…

Page 15: Mario Donkey Kong · Distribution, distances, concurrency, commodity, scale: all these are reasons why parts of a system can anytime crash

…we can now use lots of cheap commodity hardware

Page 16: Mario Donkey Kong · Distribution, distances, concurrency, commodity, scale: all these are reasons why parts of a system can anytime crash

Physics has hit the wall…

Page 17: Mario Donkey Kong · Distribution, distances, concurrency, commodity, scale: all these are reasons why parts of a system can anytime crash

…and we must think parallel

Page 18: Mario Donkey Kong · Distribution, distances, concurrency, commodity, scale: all these are reasons why parts of a system can anytime crash

Our physically Our physically huge globe…

Page 19: Mario Donkey Kong · Distribution, distances, concurrency, commodity, scale: all these are reasons why parts of a system can anytime crash

s

…became a tiny electronic ball. It‘s completely wired

Page 20: Mario Donkey Kong · Distribution, distances, concurrency, commodity, scale: all these are reasons why parts of a system can anytime crash

Spontanuous requirements…

Page 21: Mario Donkey Kong · Distribution, distances, concurrency, commodity, scale: all these are reasons why parts of a system can anytime crash

…can be covered by the fog (aka cloud)

Page 22: Mario Donkey Kong · Distribution, distances, concurrency, commodity, scale: all these are reasons why parts of a system can anytime crash

So what?

Page 23: Mario Donkey Kong · Distribution, distances, concurrency, commodity, scale: all these are reasons why parts of a system can anytime crash

We must accept some things…

Page 24: Mario Donkey Kong · Distribution, distances, concurrency, commodity, scale: all these are reasons why parts of a system can anytime crash

Functional languages much better suit parallel programming

Page 25: Mario Donkey Kong · Distribution, distances, concurrency, commodity, scale: all these are reasons why parts of a system can anytime crash

Extrem scenarios require require

technologies allowing extrem scalability – no scalability – no

forced standards

Page 26: Mario Donkey Kong · Distribution, distances, concurrency, commodity, scale: all these are reasons why parts of a system can anytime crash

Application types have pretty much changed

Page 27: Mario Donkey Kong · Distribution, distances, concurrency, commodity, scale: all these are reasons why parts of a system can anytime crash

Data became more different, more different, bigger, more fine-grained and more and more frequent

Page 28: Mario Donkey Kong · Distribution, distances, concurrency, commodity, scale: all these are reasons why parts of a system can anytime crash

High availability High availability counts for many among must-have parameters

Page 29: Mario Donkey Kong · Distribution, distances, concurrency, commodity, scale: all these are reasons why parts of a system can anytime crash

Distribution, distances, concurrency,concurrency,commodity,scale: all these are reasons why parts reasons why parts of a system can anytime crash

Page 30: Mario Donkey Kong · Distribution, distances, concurrency, commodity, scale: all these are reasons why parts of a system can anytime crash

Share-nothing approaches scale best

Page 31: Mario Donkey Kong · Distribution, distances, concurrency, commodity, scale: all these are reasons why parts of a system can anytime crash

Tell me something new –

Enterprise Java Enterprise Java solves it all. Where does Erlang/OTP Erlang/OTP

come into play?

Page 32: Mario Donkey Kong · Distribution, distances, concurrency, commodity, scale: all these are reasons why parts of a system can anytime crash

Exactly!Let‘s take a Let‘s take a look at it

Page 33: Mario Donkey Kong · Distribution, distances, concurrency, commodity, scale: all these are reasons why parts of a system can anytime crash

Language

Page 34: Mario Donkey Kong · Distribution, distances, concurrency, commodity, scale: all these are reasons why parts of a system can anytime crash

List<Integer> l = Arrays.asList(1, 2, 3, 4, 5);

Java: list processing

List<Integer> l = Arrays.asList(1, 2, 3, 4, 5);List<Integer> r = new ArrayList<Integer>();for (int i : l) {

if (i % 2 == 0) {r.add(i);

}}}

Page 35: Mario Donkey Kong · Distribution, distances, concurrency, commodity, scale: all these are reasons why parts of a system can anytime crash

Erlang: list comprehensions

[X || X <- lists:seq(1, 5), X rem 2 == 0].

Page 36: Mario Donkey Kong · Distribution, distances, concurrency, commodity, scale: all these are reasons why parts of a system can anytime crash

Where is more boilerplate?boilerplate?

Page 37: Mario Donkey Kong · Distribution, distances, concurrency, commodity, scale: all these are reasons why parts of a system can anytime crash

synchronized (this) {if (!crawledSites.contains(site)) {

linkedSites.add(site);}

}

Java:„concurrency“

public class CountingSemaphore {private int signals = 0;public synchronized void take() {

this.signals++;this.notify();

}

„concurrency“

public synchronized void release()throws InterruptedException {

while (this.signals == 0) wait();this.signals--;

}}

Page 38: Mario Donkey Kong · Distribution, distances, concurrency, commodity, scale: all these are reasons why parts of a system can anytime crash

Java concurrency: like two boxers alternating the gloves, thus hitting sequentially

Page 39: Mario Donkey Kong · Distribution, distances, concurrency, commodity, scale: all these are reasons why parts of a system can anytime crash

Java concurrency: like a Java concurrency: like a goalkeeper telling the forwards to wait while he takes a pull on a battle

Page 40: Mario Donkey Kong · Distribution, distances, concurrency, commodity, scale: all these are reasons why parts of a system can anytime crash

Erlang: functional

Page 41: Mario Donkey Kong · Distribution, distances, concurrency, commodity, scale: all these are reasons why parts of a system can anytime crash

Erlang: single assignment

Page 42: Mario Donkey Kong · Distribution, distances, concurrency, commodity, scale: all these are reasons why parts of a system can anytime crash

Erlang: single assignment

1> A = 5.52> A = 10.** exception error: no match of right hand side value 103>

Page 43: Mario Donkey Kong · Distribution, distances, concurrency, commodity, scale: all these are reasons why parts of a system can anytime crash

Enterprise Java: why not pick „more modern“ weapons?..

Page 44: Mario Donkey Kong · Distribution, distances, concurrency, commodity, scale: all these are reasons why parts of a system can anytime crash

Erlang: Share-nothing

Page 45: Mario Donkey Kong · Distribution, distances, concurrency, commodity, scale: all these are reasons why parts of a system can anytime crash

-record(state, {start,player1,

Erlang: message passing with state externalization

player1,player2

}).

..

State = #state{start=0}Pid ! {self(), State},Pid ! {self(), State},

receive{Pid, NewState} ->

…end,

Page 46: Mario Donkey Kong · Distribution, distances, concurrency, commodity, scale: all these are reasons why parts of a system can anytime crash

import kilim.Mailbox;import kilim.Pausable;import kilim.Task;

public class SimpleTask extends Task {static Mailbox<String> mb = new Mailbox<String>();

Java: „actor model“ This package comes with a bytecode transformation tool called Weaver (package: kilim.tools.Weaver) that post-processes .class fileslooking for the "throws Pausable" annotation.

When a task needs to pause, it

public static void main(String[] args) throws Exception {new SimpleTask().start();Thread.sleep(10);mb.putnb("Hello ");mb.putnb("World\n");mb.putnb("done");

}

public void execute() throws Pausable {while (true) {

When a task needs to pause, it unwinds its stack, squirrels away all state that it'll need later on resumption. This unwinding and rewinding the stack is automatically performed by the code introduced by the Weaver.(Debug information is adjusted so that the transformed code can be debugged inside eclipse) This is identical to what a

while (true) {String s = mb.get();if (s.equals("done")) break;

System.out.print(s);}

System.exit(0);}

}

is identical to what a programmer would havewritten

Page 47: Mario Donkey Kong · Distribution, distances, concurrency, commodity, scale: all these are reasons why parts of a system can anytime crash

Erlang: actor based

Page 48: Mario Donkey Kong · Distribution, distances, concurrency, commodity, scale: all these are reasons why parts of a system can anytime crash

register(serv, spawn(?MODULE, loop, []))serv ! {self(), “Hello there!”},receive

Spawn, loop, register und message passing

receive{_Pid, Msg} ->

…end.

loop() ->receive

{From, Txt}…loop();

Page 49: Mario Donkey Kong · Distribution, distances, concurrency, commodity, scale: all these are reasons why parts of a system can anytime crash

So what?In Java, I have

standards for standards for everything. And parallel systems I can solve with I can solve with Scala and Akka

Page 50: Mario Donkey Kong · Distribution, distances, concurrency, commodity, scale: all these are reasons why parts of a system can anytime crash

Exactly!Let‘s take a look at this as look at this as well

Page 51: Mario Donkey Kong · Distribution, distances, concurrency, commodity, scale: all these are reasons why parts of a system can anytime crash

Java: is it really the ultimate ultimate answer to everything?

Page 52: Mario Donkey Kong · Distribution, distances, concurrency, commodity, scale: all these are reasons why parts of a system can anytime crash

Enterprise Java: tries to standardize the half world

Page 53: Mario Donkey Kong · Distribution, distances, concurrency, commodity, scale: all these are reasons why parts of a system can anytime crash

This somehow reminds of…

Page 54: Mario Donkey Kong · Distribution, distances, concurrency, commodity, scale: all these are reasons why parts of a system can anytime crash

When Enterprise Java?

Page 55: Mario Donkey Kong · Distribution, distances, concurrency, commodity, scale: all these are reasons why parts of a system can anytime crash

When not Enterprise Java?

Page 56: Mario Donkey Kong · Distribution, distances, concurrency, commodity, scale: all these are reasons why parts of a system can anytime crash

Enterprise Java: suffers Swiss Army knife syndrome

Page 57: Mario Donkey Kong · Distribution, distances, concurrency, commodity, scale: all these are reasons why parts of a system can anytime crash

Java: application orientedoriented

Page 58: Mario Donkey Kong · Distribution, distances, concurrency, commodity, scale: all these are reasons why parts of a system can anytime crash

Java: especially concurrency and low level technology have generally never been to the fore

Page 59: Mario Donkey Kong · Distribution, distances, concurrency, commodity, scale: all these are reasons why parts of a system can anytime crash

Erlang/OTP: strong specialization

Page 60: Mario Donkey Kong · Distribution, distances, concurrency, commodity, scale: all these are reasons why parts of a system can anytime crash

Erlang: technology rather than application oriented. „Massive parallel“ from the beginning

Page 61: Mario Donkey Kong · Distribution, distances, concurrency, commodity, scale: all these are reasons why parts of a system can anytime crash

-define(IP_VERSION, 4).

Erlang: example of bitstring processing

-define(IP_VERSION, 4).-define(IP_MIN_HDR_LEN, 5).

DgramSize = byte_size(Dgram),case Dgram of

<<?IP_VERSION:4, HLen:4, SrvcType:8, TotLen:16, ID:16, Flgs:3, FragOff:13,TTL:8, Proto:8, HdrChkSum:16,SrcIP:32,DestIP:32, RestDgram/binary>> when HLen>=5, 4*HLen=<DgramSize ->DestIP:32, RestDgram/binary>> when HLen>=5, 4*HLen=<DgramSize ->OptsLen = 4*(HLen - ?IP_MIN_HDR_LEN),<<Opts:OptsLen/binary,Data/binary>> = RestDgram,

...end.

Page 62: Mario Donkey Kong · Distribution, distances, concurrency, commodity, scale: all these are reasons why parts of a system can anytime crash

When Erlang/OTP?

Network components controlNetwork components controlExtreme servers

Messaging middlewareDistributed systems

Systems for big data processingBulk calculation systemsBulk calculation systems

Critical systemsEvent control and processing

Bitstream processing

Page 63: Mario Donkey Kong · Distribution, distances, concurrency, commodity, scale: all these are reasons why parts of a system can anytime crash

When not Erlang/OTP?

UI-heavy applications

Application / business logic

Number crunchingNumber crunching

Page 64: Mario Donkey Kong · Distribution, distances, concurrency, commodity, scale: all these are reasons why parts of a system can anytime crash

Scala devotes itself primarily to… exactly, Scala!

Page 65: Mario Donkey Kong · Distribution, distances, concurrency, commodity, scale: all these are reasons why parts of a system can anytime crash

Scala doesn’t have an own VM und lives off the JVM

Page 66: Mario Donkey Kong · Distribution, distances, concurrency, commodity, scale: all these are reasons why parts of a system can anytime crash

JVM is by far not established in every IT in the world

Page 67: Mario Donkey Kong · Distribution, distances, concurrency, commodity, scale: all these are reasons why parts of a system can anytime crash

Scala‘s basis code inherits Java diseasesinherits Java diseases

Page 68: Mario Donkey Kong · Distribution, distances, concurrency, commodity, scale: all these are reasons why parts of a system can anytime crash

Akka development concentrates primarily on Scala

Page 69: Mario Donkey Kong · Distribution, distances, concurrency, commodity, scale: all these are reasons why parts of a system can anytime crash

Scala and Akka took over lots of Erlang concepts ☺

Page 70: Mario Donkey Kong · Distribution, distances, concurrency, commodity, scale: all these are reasons why parts of a system can anytime crash

Doesn’t matter!Enterprise Java platform is platform is proved, reliable, fault tolerantand optimal and optimal suitable for all situations!

Page 71: Mario Donkey Kong · Distribution, distances, concurrency, commodity, scale: all these are reasons why parts of a system can anytime crash

Exactly!Let‘s take a look at this, look at this, too

Page 72: Mario Donkey Kong · Distribution, distances, concurrency, commodity, scale: all these are reasons why parts of a system can anytime crash

Java: fault tolerancepublic static void main(String[] args) {

PathDasher dasher = new PathDasher(null); }

# A fatal error has been detected by the Java Runtime Environment:## EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x000000006da97783, pid=4772, tid=3416### JRE version: 6.0_15-b03# Java VM: Java HotSpot(TM) 64-Bit Server VM (14.1-b02 mixed mode windows-amd64 )# Problematic frame:# V [jvm.dll+0x207783]

Page 73: Mario Donkey Kong · Distribution, distances, concurrency, commodity, scale: all these are reasons why parts of a system can anytime crash

Java: JNI crash will crash the whole JVM

Page 74: Mario Donkey Kong · Distribution, distances, concurrency, commodity, scale: all these are reasons why parts of a system can anytime crash

Erlang: fault tolerance

Page 75: Mario Donkey Kong · Distribution, distances, concurrency, commodity, scale: all these are reasons why parts of a system can anytime crash

1> self().<0.31.0>

Erlang: fault tolerance

<0.31.0>2> 5/0.** exception error: bad argument in an arithmetic expression

in operator '/'/2called as 5 / 0called as 5 / 0

3> self().<0.34.0>4>

Page 76: Mario Donkey Kong · Distribution, distances, concurrency, commodity, scale: all these are reasons why parts of a system can anytime crash

Erlang:supervisor trees

Page 77: Mario Donkey Kong · Distribution, distances, concurrency, commodity, scale: all these are reasons why parts of a system can anytime crash

-module(dr_supervisor).-behaviour(supervisor).

Erlang: supervisor tree

-behaviour(supervisor).-export([start_link/1]).-export([init/1]).

start_link(Args) ->supervisor:start_link({local, ?MODULE}, ?MODULE, Args).

init(Args) ->{ok, {{one_for_one, 2, 10}, [{ok, {{one_for_one, 2, 10}, [

{session, {dr_session, start_link, [Args]}, transient, 2000, supervisor, [dr_session]}]}}.

Page 78: Mario Donkey Kong · Distribution, distances, concurrency, commodity, scale: all these are reasons why parts of a system can anytime crash

-module(dr_session).-behaviour(supervisor).

-export([start_link/1]).

Erlang: supervisor tree

-export([start_link/1]).-export([init/1]).

start_link(Args) ->supervisor:start_link({local, ?MODULE}, ?MODULE, Args).

init(Args) ->error_logger:info_report("session started"),{ok, {{one_for_one, 2, 10}, [{ok, {{one_for_one, 2, 10}, [{server, {dr_session_server, start_link, [Args]}, transient, 2000, worker,

[dr_session_server]},{state, {dr_session_state, start_link, [Args]}, transient, 2000, worker,

[dr_session_state]},{vm, {dr_session_vm, start_link, [Args]}, transient, 2000, worker,

[dr_session_vm]}]}}.

Page 79: Mario Donkey Kong · Distribution, distances, concurrency, commodity, scale: all these are reasons why parts of a system can anytime crash

import org.gridgain.grid.*;import org.gridgain.grid.gridify.*;import org.gridgain.grid.gridify.aop.spring.*;

public final class GridifyHelloWorldSessionExample {private GridifyHelloWorldSessionExample() { //ensure singleton}

@Gridify(taskClass = GridifyHelloWorldSessionTask.class, timeout = 3000)public static int sayIt(String phrase) {

System.out.println(phrase);

Java: distribution

System.out.println(phrase);return phrase.length();

}

public static void main(String[] args) throws GridException {if (args.length == 0) {

GridFactory.start();}else {

GridFactory.start(args[0]);}

To use other AOP implementations (such as JBoss AOP, or Spring AOP), refer to AOP Configuration documentation.The following configuration needs to be applied to enable AspectJ byte code weaving.JVM configuration should include:

try {

int phraseLen = sayIt("Hello World");

System.out.println(„number of characters is '" + phraseLen + "'.");}finally {

GridFactory.stop(true);}

}}

-javaagent:[GRIDGAIN_HOME]/libs/aspectjweaver-1.5.3.jar

Page 80: Mario Donkey Kong · Distribution, distances, concurrency, commodity, scale: all these are reasons why parts of a system can anytime crash

Erlang: distributed

Page 81: Mario Donkey Kong · Distribution, distances, concurrency, commodity, scale: all these are reasons why parts of a system can anytime crash

Erlang: example of multicall for code reload

%% Find object code for module Mod

{Mod, Bin, File} = code:get_object_code(Mod),

%% and load it on all nodes including this one

{ResL, _} = rpc:multicall(code, load_binary, [Mod, Bin, File,], 5000),{ResL, _} = rpc:multicall(code, load_binary, [Mod, Bin, File,], 5000),

%% and then maybe check the ResL list.

Page 82: Mario Donkey Kong · Distribution, distances, concurrency, commodity, scale: all these are reasons why parts of a system can anytime crash

QueueConnectionFactory connFactory = new QueueConnectionFactory();QueueConnection conn = connFactory.createQueueConnection();QueueSession session = conn.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);Queue q = new Queue("world");

Java: message exchange

Queue q = new Queue("world");QueueSender sender = session.createSender(q);TextMessage msg = session.createTextMessage();msg.setText("Hello there!");sender.send(msg);

QueueReceiver receiver = session.createReceiver(q);conn.start();Message m = receiver.receive();if (m instanceof TextMessage) {

TextMessage txt = (TextMessage) m;TextMessage txt = (TextMessage) m;}

session.close();conn.close();

Page 83: Mario Donkey Kong · Distribution, distances, concurrency, commodity, scale: all these are reasons why parts of a system can anytime crash

Boilerplate?Even with Spring still symptom still symptom treatment

Page 84: Mario Donkey Kong · Distribution, distances, concurrency, commodity, scale: all these are reasons why parts of a system can anytime crash

Erlang: message oriented

Page 85: Mario Donkey Kong · Distribution, distances, concurrency, commodity, scale: all these are reasons why parts of a system can anytime crash

Erlang: message passing

Pid ! {self(), “Hello there!”},receive

{Pid, Txt} ->…

end,

Page 86: Mario Donkey Kong · Distribution, distances, concurrency, commodity, scale: all these are reasons why parts of a system can anytime crash

VM

Page 87: Mario Donkey Kong · Distribution, distances, concurrency, commodity, scale: all these are reasons why parts of a system can anytime crash

JVM threads are too “heavy”. Context switching is extremely expensive to have many thousands of them. Only hacks thousands of them. Only hacks such as CPS simulation over byte code manipulation provide a remedy und illusion of a remedy und illusion of lightweight threads

Page 88: Mario Donkey Kong · Distribution, distances, concurrency, commodity, scale: all these are reasons why parts of a system can anytime crash

import kilim.Mailbox;import kilim.Pausable;import kilim.Task;

public class SimpleTask extends Task {static Mailbox<String> mb = new Mailbox<String>();

Java: „concurrency“This package comes with a bytecode transformation tool called Weaver (package: kilim.tools.Weaver) that post-processes .class fileslooking for the "throws

public static void main(String[] args) throws Exception {new SimpleTask().start();Thread.sleep(10);mb.putnb("Hello ");mb.putnb("World\n");mb.putnb("done");

}

public void execute() throws Pausable {while (true) {

looking for the "throws Pausable" annotation.

When a task needs to pause, it unwinds its stack, squirrels away all state that it'll need later on resumption. This unwinding and rewinding the stack is automatically performed by the code introduced by the Weaver.(Debug information is adjusted while (true) {

String s = mb.get();if (s.equals("done")) break;

System.out.print(s);}

System.exit(0);}

}

(Debug information is adjusted so that the transformed code can be debugged inside eclipse) This is identical to what a programmer would havewritten

Page 89: Mario Donkey Kong · Distribution, distances, concurrency, commodity, scale: all these are reasons why parts of a system can anytime crash

Java: instance-wide garbage collector

Page 90: Mario Donkey Kong · Distribution, distances, concurrency, commodity, scale: all these are reasons why parts of a system can anytime crash

Erlang: concurrent.Hunderts of Hunderts of thousends of lightweight VM processes per node processes per node instead of „native“ threads-> own scheduler

Page 91: Mario Donkey Kong · Distribution, distances, concurrency, commodity, scale: all these are reasons why parts of a system can anytime crash

Erlang: heap per process -> garbage collected per process

Page 92: Mario Donkey Kong · Distribution, distances, concurrency, commodity, scale: all these are reasons why parts of a system can anytime crash

Hot swapping

Page 93: Mario Donkey Kong · Distribution, distances, concurrency, commodity, scale: all these are reasons why parts of a system can anytime crash

Java: ClassLoadertrees can be trees can be complex and unpredictable.Middlewareoften causesoften causeslib conflicts

Page 94: Mario Donkey Kong · Distribution, distances, concurrency, commodity, scale: all these are reasons why parts of a system can anytime crash

Java: OSGi is invasive and imports a middleware

Page 95: Mario Donkey Kong · Distribution, distances, concurrency, commodity, scale: all these are reasons why parts of a system can anytime crash

Java: app server fatigue is a common phenomenon after

frequent application redeploymentredeployment

Page 96: Mario Donkey Kong · Distribution, distances, concurrency, commodity, scale: all these are reasons why parts of a system can anytime crash

Java: zero downtime systems are possible only with human support

Page 97: Mario Donkey Kong · Distribution, distances, concurrency, commodity, scale: all these are reasons why parts of a system can anytime crash

% hot_swap:sum(Num) addiert 1 dazu1> c(hot_swap).{ok,hot_swap}

Erlang: live code upgrade

{ok,hot_swap}2> hot_swap:sum(1).2...%hot_swap.erl wurde modifiziert. Jetzt% addiert es 2 dazu……3> c(hot_swap).{ok,hot_swap}4> hot_swap:sum(1).35>

Page 98: Mario Donkey Kong · Distribution, distances, concurrency, commodity, scale: all these are reasons why parts of a system can anytime crash

Erlang: non-stop systems arepossible and implemented

Page 99: Mario Donkey Kong · Distribution, distances, concurrency, commodity, scale: all these are reasons why parts of a system can anytime crash

Come on!Come on!Enterprise Java offers even more scalabilityscalability

Page 100: Mario Donkey Kong · Distribution, distances, concurrency, commodity, scale: all these are reasons why parts of a system can anytime crash

Exactly!This should also be also be considered

Page 101: Mario Donkey Kong · Distribution, distances, concurrency, commodity, scale: all these are reasons why parts of a system can anytime crash

Java doesn‘t scale as originally expected

Hacks

Scala & Co.

Java

EnterpriseJava

Page 102: Mario Donkey Kong · Distribution, distances, concurrency, commodity, scale: all these are reasons why parts of a system can anytime crash

Erlang: scaling

Page 103: Mario Donkey Kong · Distribution, distances, concurrency, commodity, scale: all these are reasons why parts of a system can anytime crash

From sequential program to world-wide distribution

MulticoreProgramming

DistributedProgramming

SequentialErlang

FunctionalErlang

Page 104: Mario Donkey Kong · Distribution, distances, concurrency, commodity, scale: all these are reasons why parts of a system can anytime crash

Frameworks

Page 105: Mario Donkey Kong · Distribution, distances, concurrency, commodity, scale: all these are reasons why parts of a system can anytime crash

Java: Framework-itis(like others, too ☺)

Page 106: Mario Donkey Kong · Distribution, distances, concurrency, commodity, scale: all these are reasons why parts of a system can anytime crash

Erlang: generic behaviors

Page 107: Mario Donkey Kong · Distribution, distances, concurrency, commodity, scale: all these are reasons why parts of a system can anytime crash

Erlang/OTP: behaviors

-module(dr_session_state).-behaviour(gen_fsm).-behaviour(gen_fsm).

-export([start_link/1]).-export([init/1]).

start_link(Args) ->gen_fsm:start_link({local, ?MODULE}, ?MODULE, Args, []).

init(_Args) ->init(_Args) ->error_logger:info_report("state started"),{ok, waiting1, []}.

Page 108: Mario Donkey Kong · Distribution, distances, concurrency, commodity, scale: all these are reasons why parts of a system can anytime crash

Erlang/OTP:behaviors

-module(dr_session_server).-behaviour(gen_server).

-export([start_link/1]).-export([init/1]).-export([code_change/3]).-export([handle_call/3]).-export([handle_cast/2]).-export([handle_cast/2]).-export([handle_info/2]).-export([terminate/2]).

-record(state, {start,player1,player2

}).

start_link(Args) ->gen_server:start_link({local, ?MODULE}, ?MODULE, [Args], []).

init(_Args) ->error_logger:info_report("server started"),process_flag(trap_exit, true),{ok, #state{}}.

Page 109: Mario Donkey Kong · Distribution, distances, concurrency, commodity, scale: all these are reasons why parts of a system can anytime crash

Erlang/OTP: behaviors

-module(dr_gen_vm).-export([behaviour_info/1]).

behaviour_info(callbacks) ->[{init,1}];

behaviour_info(_Other) ->undefined.undefined.

Page 110: Mario Donkey Kong · Distribution, distances, concurrency, commodity, scale: all these are reasons why parts of a system can anytime crash

NoSQL DSs made in Java don‘t implement Java standards for data access because they are impractical, and use open impractical, and use open standards instead

Page 111: Mario Donkey Kong · Distribution, distances, concurrency, commodity, scale: all these are reasons why parts of a system can anytime crash

NoSQL DSs made in Erlangreceive many things as a gift…

Page 112: Mario Donkey Kong · Distribution, distances, concurrency, commodity, scale: all these are reasons why parts of a system can anytime crash

Erlang: big data storage possibilities

Page 113: Mario Donkey Kong · Distribution, distances, concurrency, commodity, scale: all these are reasons why parts of a system can anytime crash

Erlang: Dets = Disk Erlang Term Storage

{_,D} = dets:open_file(„example“), dets:delete_all_objects(D),dets:insert(D, {mama, mia}),dets:insert(D, {here, we}),dets:insert(D, {go, again}),dets:insert(D, {go, again}),dets:close(D),

Page 114: Mario Donkey Kong · Distribution, distances, concurrency, commodity, scale: all these are reasons why parts of a system can anytime crash

Erlang: Mnesia = dets + transactions, quiries and

distributionmnesia:create_schema([node()]),mnesia:start(),mnesia:start(),mnesia:create_table(album,

[ {disc_copies, [node()] },{attributes,

record_info(fields, album)} ]),Insert = fun() ->

mnesia:write(#album{ index=A_Index,#album{ index=A_Index,

artist=A_Artist,title=A_Title } ) end,

{atomic, Result} = mnesia:transaction(Insert),…

Page 115: Mario Donkey Kong · Distribution, distances, concurrency, commodity, scale: all these are reasons why parts of a system can anytime crash

Really? ButEnterprise Java Enterprise Java integrates everything in the world!world!

Page 116: Mario Donkey Kong · Distribution, distances, concurrency, commodity, scale: all these are reasons why parts of a system can anytime crash

Exactly!Let‘s see…Let‘s see…

Page 117: Mario Donkey Kong · Distribution, distances, concurrency, commodity, scale: all these are reasons why parts of a system can anytime crash

Java prefers to integrate non-natively, from afar –natively, from afar –for example per web service. In a pinch JNI will do –at own risk.at own risk.

Page 118: Mario Donkey Kong · Distribution, distances, concurrency, commodity, scale: all these are reasons why parts of a system can anytime crash

Erlang: integrated

Page 119: Mario Donkey Kong · Distribution, distances, concurrency, commodity, scale: all these are reasons why parts of a system can anytime crash

Erlang: ways to integration

Erlang node Pseudo-OTP

Erlang program

PortPort

OTPnode with the externalprogram

Binary data

Linked-inDriver

Externalprogram

Binary data

Page 120: Mario Donkey Kong · Distribution, distances, concurrency, commodity, scale: all these are reasons why parts of a system can anytime crash

Erlang: example JInterfaceimport com.ericsson.otp.erlang.*;

...

OtpNode self = new OtpNode("pseudo@test");OtpNode self = new OtpNode("pseudo@test");OtpMbox mbox = self.createMbox("pingpong");OtpErlangObject o;OtpErlangTuple msg;OtpErlangPid from;

while (true) {try {o = mbox.receive();if (o instanceof OtpErlangTuple) {

msg = (OtpErlangTuple)o;msg = (OtpErlangTuple)o;from = (OtpErlangPid)(msg.elementAt(0));mbox.send(from, msg.elementAt(1));

}catch (Exception e) {...

}}

Page 121: Mario Donkey Kong · Distribution, distances, concurrency, commodity, scale: all these are reasons why parts of a system can anytime crash

Erlang: example JInterface

-module(pongclient).-export([pong/0]).

pong() ->{pingpong, "pseudo@test“} ! {self(), "ball"},receive

Result ->io:format("What comes back is : ~p~n", [Result])

end.

Page 122: Mario Donkey Kong · Distribution, distances, concurrency, commodity, scale: all these are reasons why parts of a system can anytime crash

And even I can do web services these days ☺

Page 123: Mario Donkey Kong · Distribution, distances, concurrency, commodity, scale: all these are reasons why parts of a system can anytime crash

Stop!Stop!I am constrained to the JVM!Period.Period.

Page 124: Mario Donkey Kong · Distribution, distances, concurrency, commodity, scale: all these are reasons why parts of a system can anytime crash

BEAM is not an option for every IT

Page 125: Mario Donkey Kong · Distribution, distances, concurrency, commodity, scale: all these are reasons why parts of a system can anytime crash

Erjang – Erlang on the JVM. It can already

boot some big Erlangsystems. It’s under systems. It’s under

development.I do help ☺

Page 126: Mario Donkey Kong · Distribution, distances, concurrency, commodity, scale: all these are reasons why parts of a system can anytime crash

Right tool for the job

Page 127: Mario Donkey Kong · Distribution, distances, concurrency, commodity, scale: all these are reasons why parts of a system can anytime crash

Thank you