addisdev meetup ii: golang and flow-based programming

64
Go(lang), Flow based programming, and some: Flow-based programming experiments in Go(lang) AddisDev Meetup #2, Addis Ababa Nov 11, 2014 (meetup.com/addisdev) Samuel Lampa @smllmp // +samuellampa // saml.rilspace.org // bionics.it Developer at www.farmbio.uu.se // bils.se // rilpartner.com

Upload: samuel-lampa

Post on 11-Jul-2015

1.508 views

Category:

Technology


3 download

TRANSCRIPT

Page 1: AddisDev Meetup ii: Golang and Flow-based Programming

Go(lang), Flow based programming, and some:

Flow-based programming experiments in Go(lang)

AddisDev Meetup #2, Addis AbabaNov 11, 2014

(meetup.com/addisdev)

Samuel Lampa@smllmp // +samuellampa // saml.rilspace.org // bionics.it

Developer atwww.farmbio.uu.se // bils.se // rilpartner.com

Page 2: AddisDev Meetup ii: Golang and Flow-based Programming

The Go programming language

#golang

Page 3: AddisDev Meetup ii: Golang and Flow-based Programming

Turned 5 yesterday (Nov 10)! :)

http://blog.golang.org/5years

Page 4: AddisDev Meetup ii: Golang and Flow-based Programming

Interest increasing every month

Page 5: AddisDev Meetup ii: Golang and Flow-based Programming

Invented at Google by Robert Griesemer, Rob Pike and Ken Thompson

Page 6: AddisDev Meetup ii: Golang and Flow-based Programming

Go(lang) characteristics● Open source● Compiled (like C, C++, Pascal, etc)● Garbage collected (Like Java)● Statically typed (Like C++, Java, C# etc)● Statically linked

(includes dependent code in the executable when compiling, not just linking to it when running)● Has primitives for writing concurrent code built into the language (channels and go-routines)● Multiplexes go-routines on operating system threads

(rather than start one thread per go-routine).● Has a C-like syntax● Has a small set of keywords● Has explicit error handling (no Exception handling)● Supports Reflection● Has no Generic programming● Has, for its age, a rather extensive standard library (Less need to reinvent the wheel)● Is supported by Google, Canonical and a few other companies.

Page 7: AddisDev Meetup ii: Golang and Flow-based Programming

Go(lang) benefits● Easy Concurrency

… due to in-built primitives, multi-plexing, and in-built garbage collector.● Good at handling many concurrent connections

… due to concurrency primitives and the multiplexing.● Generally good performance, especially compared to scripting languages

… due to static typing, being compiled and good concurrency primitives.● Easy to learn

… due to small language, and similarity with existing C-like languages.● Very easy to deploy to production (servers)

… due to static linking (Just copy the executable to the destination server!)● Predictable code

… due to the explicit error handling (see also downside for same reason)● Getting a lot of media attention

… and with that, a fast growing community) due to big backers like Google.

Page 8: AddisDev Meetup ii: Golang and Flow-based Programming

Go(lang) potential drawbacks

● The lack of Generic programming means that some redundancy might be needed at times, when implementing the same algorithm for slightly varying data types.

● Somewhat verbose code might be needed at times due to the explicit error handling (see also upside for same reason)

● Performance can be affected (to the worse) by the pauses incurred by the garbage collector (but being worked on!)

● Might not produce as optimized code as some other languages, due mostly to the young age of the language (although that improves with each release!)

Page 9: AddisDev Meetup ii: Golang and Flow-based Programming

Concurrency is not parallelism

Page 10: AddisDev Meetup ii: Golang and Flow-based Programming

Parallellism

Page 11: AddisDev Meetup ii: Golang and Flow-based Programming

Concurrency

Page 12: AddisDev Meetup ii: Golang and Flow-based Programming

Concurrency + Parallelism

Page 13: AddisDev Meetup ii: Golang and Flow-based Programming

“Pipeline” concurrency

Page 14: AddisDev Meetup ii: Golang and Flow-based Programming

Based on idea of “Communicating Sequential Processes”

(CSP)

Especially suited for concurrent apps that utilize multiple CPU cores

Page 15: AddisDev Meetup ii: Golang and Flow-based Programming

http://tour.golang.org

Page 16: AddisDev Meetup ii: Golang and Flow-based Programming

Go-routines

Page 17: AddisDev Meetup ii: Golang and Flow-based Programming

Channels

Page 18: AddisDev Meetup ii: Golang and Flow-based Programming

Some Go(lang) links

● golang.org● tour.golang.org● groups.google.com/forum/#!forum/golang-nuts● gplus.to/golang● talks.golang.org/2012/concurrency.slide#1

Page 19: AddisDev Meetup ii: Golang and Flow-based Programming

Generator Function in Go

Page 20: AddisDev Meetup ii: Golang and Flow-based Programming

More advanced generator function

Page 21: AddisDev Meetup ii: Golang and Flow-based Programming

Connecting Generators together...

Page 22: AddisDev Meetup ii: Golang and Flow-based Programming

Using it ...

Page 23: AddisDev Meetup ii: Golang and Flow-based Programming

Flow-based programming

http://en.wikipedia.org/wiki/Flow-based_programming

Page 24: AddisDev Meetup ii: Golang and Flow-based Programming

What is this?

Page 25: AddisDev Meetup ii: Golang and Flow-based Programming

Right answer: Function calls, or a “call graph”

What is this?

Page 26: AddisDev Meetup ii: Golang and Flow-based Programming

What if we could take control of this...…and define the graph declaratively? Wow! :)

qq

Page 27: AddisDev Meetup ii: Golang and Flow-based Programming

FBP Inventor J. Paul Morrison

q

Invented at the 60's at IBM

Page 28: AddisDev Meetup ii: Golang and Flow-based Programming

The flow based programming book- A must read

→ tinyurl.com/fbpbook

Page 29: AddisDev Meetup ii: Golang and Flow-based Programming

“In computer programming, flow­based programming (FBP) is a programming paradigm that defines applications as networks of "black box" processes, which exchange data across predefined connections by message passing, where the connections are specified externally to the processes. These black box processes can be reconnected endlessly to form different applications without having to be changed internally. FBP is thus naturally component­oriented”

Wikipedia

Page 30: AddisDev Meetup ii: Golang and Flow-based Programming
Page 31: AddisDev Meetup ii: Golang and Flow-based Programming
Page 32: AddisDev Meetup ii: Golang and Flow-based Programming

Core FBP Concepts

● “Black box” processes (comp. to functions)● Named in / outports as interfaces to processes● Channels with bounded buffers● Separate network definition

Page 33: AddisDev Meetup ii: Golang and Flow-based Programming

Some FBP network examples...

Page 34: AddisDev Meetup ii: Golang and Flow-based Programming

Some FBP network examples...

Page 35: AddisDev Meetup ii: Golang and Flow-based Programming

An array of benefits ...● Change of connection wiring

without rewriting components

● Inherently concurrent - suited for the multi-core CPU world!

● Testing, monitoring and logging very easy: Just plug in a mock-, logging- or debugging component.

● Etc.

qq

Page 36: AddisDev Meetup ii: Golang and Flow-based Programming

Many similar tools: Unix pipes

Page 37: AddisDev Meetup ii: Golang and Flow-based Programming

Many similar tools: LabView

Page 38: AddisDev Meetup ii: Golang and Flow-based Programming

Many similar tools: Yahoo Pipes

Page 39: AddisDev Meetup ii: Golang and Flow-based Programming

Many similar tools: Apple Quartz Composer

Page 40: AddisDev Meetup ii: Golang and Flow-based Programming

Mitov Software (Video effects)

Page 41: AddisDev Meetup ii: Golang and Flow-based Programming

Implementations in many languages● Java (JavaFBP) - github.com/jpaulm/javafbp● C# (C#FBP) - github.com/jpaulm/csharpfbp● C++

– CppFBP - github.com/jpaulm/cppfbp

– Dspatch - www.flowbasedprogramming.com/DSPatch/

– Blockie.io – blockie.io

● Javascript – NoFlo - noflojs.org

– Node Red – nodered.org

● Go (GoFlow) - github.com/trustmaster/goflow● Python (PaPy) - papy.org● Common lisp - ● Shell script (net2sh) - sam.nipl.net/code/net2sh/net2sh● D (Dendrite) - bitbucket.org/eris0xaa/dendrite ● …?

Page 42: AddisDev Meetup ii: Golang and Flow-based Programming

Resurgence in FBP interest with NoFlo

Page 43: AddisDev Meetup ii: Golang and Flow-based Programming
Page 44: AddisDev Meetup ii: Golang and Flow-based Programming

NoFlo creator Henri Bergius

Page 45: AddisDev Meetup ii: Golang and Flow-based Programming

NoFlo summary

● Based on Node.js● Written in coffeescript● 237 reusable components● Successful (116% of 100k USD) Kickstarter for

in-browser UI● FBP definition format in JSON● Proof-of concept:

Re-implementation of Jekyll Static site generator: 16 000 LOC 107 components→(4 custom ones of ~500 LOC, rest re-usable!)

Page 46: AddisDev Meetup ii: Golang and Flow-based Programming

The UI for NoFlo: FlowHub

Page 47: AddisDev Meetup ii: Golang and Flow-based Programming

Book on Data Flow, FBP and Reactive Programming

Page 48: AddisDev Meetup ii: Golang and Flow-based Programming

Node-RED, by IBM Emerging tech

Page 49: AddisDev Meetup ii: Golang and Flow-based Programming

Blockie.io (Swedish project)

Page 50: AddisDev Meetup ii: Golang and Flow-based Programming

My adventures in GoFlow

Page 51: AddisDev Meetup ii: Golang and Flow-based Programming

My adventures in GoFlow: Network

Page 52: AddisDev Meetup ii: Golang and Flow-based Programming

My adventures in GoFlow: Component

Page 53: AddisDev Meetup ii: Golang and Flow-based Programming

My adventures in GoFlow: Aspiring bioinformatics library :)

Page 54: AddisDev Meetup ii: Golang and Flow-based Programming

Framework-less Flow-based programming in Go!

Page 55: AddisDev Meetup ii: Golang and Flow-based Programming
Page 56: AddisDev Meetup ii: Golang and Flow-based Programming

A few example components...

Page 57: AddisDev Meetup ii: Golang and Flow-based Programming

A few example components...

Page 58: AddisDev Meetup ii: Golang and Flow-based Programming

A few example components...

Page 59: AddisDev Meetup ii: Golang and Flow-based Programming

A few example components...

Page 60: AddisDev Meetup ii: Golang and Flow-based Programming

Some links

● Main website:

www.jpaulmorrison.com/fbp● Mailing list:

tinyurl.com/fbplist● Google+:

gplus.to/flowbased

Page 62: AddisDev Meetup ii: Golang and Flow-based Programming

Bonus slides

Page 63: AddisDev Meetup ii: Golang and Flow-based Programming

What's trending● Stream based processing● “New” (old) paradigms for multi-core programming

– Flow-based programming

– Actor-based programming● Erlang / Elixir● Akka

● Distributed programming (apps running across many computers)– Erlang / Elixir

– GoCircuit

● Reactive programming● New compiled languages

– Go (Google...)

– Rust (Mozilla)

– D ...

Page 64: AddisDev Meetup ii: Golang and Flow-based Programming

Some recommended news sources

● InfoQ – infoq.com● StrangeLoop talks at InfoQ – infoq.com/strange_loop● Prismatic – getprismatic.com

– Follow topics:● Programming● Distributed programming, etc...

● StatusCode Newsletter - statuscode.org● Hacker News – news.ycombinator.com● Hacker Newsletter – hackernewsletter.com● My twitter - twitter.com/smllmp ;)