duo disco - doing the erlang dance

21
Doing the Erlang dance A case study Arjan Scherpenisse @acscherp

Upload: arjan

Post on 20-Jun-2015

459 views

Category:

Technology


3 download

DESCRIPTION

Introducing Erlang and Zotonic through the use case of the Duo Disco app

TRANSCRIPT

Page 1: Duo Disco - doing the Erlang dance

Doing the Erlang danceA case study

Arjan Scherpenisse@acscherp

Page 2: Duo Disco - doing the Erlang dance

Who am I?● Wide range of interests

● Polyglot programmer

● Contributor to Open Source Software

● Doing things differently...

Page 3: Duo Disco - doing the Erlang dance

Where others use … , I use … ● Mac → Linux

● iOS → Android

● Textmate Sublime Text → Emacs

● … → Erlang!

Page 4: Duo Disco - doing the Erlang dance

Introducing:

Page 5: Duo Disco - doing the Erlang dance

Do the DuoDisco!● Mark Meeuwenoord, Klasien van de Zandschulp,

James Bryan Graves

● It’s fun. Profit comes later

1. Download app

2. Join disco

3. Dance

4. Find partner → score!

5. goto 3

Page 6: Duo Disco - doing the Erlang dance

DuoDisco Architecture● Table: player

○ id

○ name

○ status (“waiting”, “playing”, “loading”, etc)

○ connected (true / false)

○ connected_to (player id FK)

○ current_song_id

Page 7: Duo Disco - doing the Erlang dance
Page 8: Duo Disco - doing the Erlang dance

Disco architecture issues● Race Condition Paradise

○ Connection drops

○ Connection latency

○ Subtle client differences

● These bugs never happen while you’re

developing

● Player A → Player B, Player B → Player C○ Debugging nightmare..

Page 9: Duo Disco - doing the Erlang dance
Page 10: Duo Disco - doing the Erlang dance

So what about that Erlang thing?● A language, VM and runtime system

● Fault tolerant

● Concurrent

● Functional

● In use by major players

Page 11: Duo Disco - doing the Erlang dance

Erlang: Fault Tolerance● Systems will error

● “Let it crash”○ Only program the happy path

● You will be restarted ○ by your supervisor

○ with a clean slate

Page 12: Duo Disco - doing the Erlang dance

Erlang: Concurrence● Processes (“Actors”) are cheap

● Processes communicate

● Processes contain state

Page 13: Duo Disco - doing the Erlang dance

Erlang: It’s Functional● Assign-once

● Pattern matching

● No loops○ use (tail)recursion

○ list comprehensions, map/reduce

● It has a WEIRD SYNTAX? ?F()(*$#)(*#○ I had to say it somewhere

○ Look at Elixir, it rocks. http://elixir-lang.org/

Page 14: Duo Disco - doing the Erlang dance

Erlang + Web = Zotonic● “The Django of Erlang”

● Web development framework○ Built-in web server; CMS

○ Opinionated & extensible

● Great performance out-of-the-box

● Easy to use data model○ Semantic web “everything is a thing”

Page 15: Duo Disco - doing the Erlang dance

Back in the Disco… ● 3 clients, iOS, Android & HTML

● Backend: Erlang + Zotonic (obviously...)

● JSON over WebSockets

● REST for login / discovery

● Zotonic manages data model ○ (media files, multiple disco’s)

Page 16: Duo Disco - doing the Erlang dance

DuoDisco refactoring● Model it the Erlang way

● Every player is a process

● “Room” processes for connected players

● One match-making process ○ Uses process registry for querying processes

Page 17: Duo Disco - doing the Erlang dance
Page 18: Duo Disco - doing the Erlang dance
Page 19: Duo Disco - doing the Erlang dance

DuoDisco findings● First try-out at Extrapool Festival 2 wks ago

● No more weird bugs!

● Lessons learned

○ Think (a bit) before you code

○ Use the right tool for the job

○ Dare to iterate and start over

Page 20: Duo Disco - doing the Erlang dance

Linkshttp://erlang.org/ - the Erlang language

http://zotonic.com/ - The web framework

http://duodisco.nl/ - Duo Disco app info

http://elixir-lang.org/ - Erlang with different syntax

Page 21: Duo Disco - doing the Erlang dance

Thanks! Questions?Contact:

● http://twitter.com/acscherp

● http://miraclethings.nl/

● http://github.com/arjan

● buy me a beer :p