streamline.js and node

19
www.RivalIQ.com Digital Marketing Analytics with a Competitive Edge Digital Marketing Analytics with a Competitive Edge Seth Pollack Async Node Programming with Streamline.js February 17, 2015

Upload: rival-iq

Post on 22-Jul-2015

602 views

Category:

Software


0 download

TRANSCRIPT

Page 1: Streamline.js and Node

www.RivalIQ.comDigital Marketing Analytics with a Competitive Edge

Digital Marketing Analytics with a Competitive Edge

Seth Pollack

Async Node Programming with Streamline.js

February 17, 2015

Page 2: Streamline.js and Node

www.RivalIQ.comDigital Marketing Analytics with a Competitive Edge2

if you use Node, you’d be nuts not to evaluate Streamline

codebase ~1/3 smaller

significant overall productivity gain (1.5x?)

more fun!

My Pitch: Node + Streamline

Page 3: Streamline.js and Node

www.RivalIQ.comDigital Marketing Analytics with a Competitive Edge3

Why do you love Node?

Ask Yourselves

Page 4: Streamline.js and Node

www.RivalIQ.comDigital Marketing Analytics with a Competitive Edge4

Why do you love Node?

What don’t you like about Node?

Ask Yourselves

Page 5: Streamline.js and Node

www.RivalIQ.comDigital Marketing Analytics with a Competitive Edge5

Key decision point for me is productivity

Node’s simple concurrency model is a win

JavaScript (expressiveness; one language everywhere) is a win

My “Why Node?”

Page 6: Streamline.js and Node

www.RivalIQ.comDigital Marketing Analytics with a Competitive Edge6

Control flow with callbacks is clunky

Error handling is complex

Correct callback behavior is easy to get wrong

Node-body’s Perfect

Page 7: Streamline.js and Node

www.RivalIQ.comDigital Marketing Analytics with a Competitive Edge7

My Path to Enlightenment

Node Rocks!

Control flow, ouch

Async lib!

Still painful…

Streamline!

Great Success!!!

Sadness….

Page 8: Streamline.js and Node

www.RivalIQ.comDigital Marketing Analytics with a Competitive Edge8

Imagine If…

Page 9: Streamline.js and Node

www.RivalIQ.comDigital Marketing Analytics with a Competitive Edge9

Streamline lets you use standard control flow primitives for asyncwork

You write your control flow as if async functions were sync, and pass a special token (“_”) as the callback parameter

Success results are presented as the return value of the function; error response or exceptions are presented as a thrown exception

What is Streamline?

Page 10: Streamline.js and Node

www.RivalIQ.comDigital Marketing Analytics with a Competitive Edge10

Example 1: user login

[over to the IDE]

Code example 1

Page 11: Streamline.js and Node

www.RivalIQ.comDigital Marketing Analytics with a Competitive Edge11

Simple control flow

Unified error handling

No need for manual callback invocation

PLUS…

JS tools work great

Better debugging

Logical stack trace

No wrappers

Transparent inter-op

Streamline FTW

Page 12: Streamline.js and Node

www.RivalIQ.comDigital Marketing Analytics with a Competitive Edge12

Example 2: processing data

[over to the IDE]

Code example 2

Page 13: Streamline.js and Node

www.RivalIQ.comDigital Marketing Analytics with a Competitive Edge13

Streamline is its own language, extremely similar to JavaScript

Streamline source JIT-ed into native JavaScript

Can target various back-ends (callbacks, fibers, generators)

Streamline yields and resumes on your behalf

Under the covers, the Node event loop continues to run; no blocking or busy-waiting occurs

Under the Hood

Page 14: Streamline.js and Node

www.RivalIQ.comDigital Marketing Analytics with a Competitive Edge14

Be sure to name your files *._js

You’ll have to use a different variable name than “_” for the underscore library

The magic underscore token isn’t a function, it’s a keyword

It’s important to understand that the underscore means yield, and when execution hits it, the event loop may run

Fibers backend to Streamline has best combo of performance and developer experience

Many more goodies exist in Streamline that I haven’t covered here

Tips & Tricks

Page 15: Streamline.js and Node

www.RivalIQ.comDigital Marketing Analytics with a Competitive Edge15

Some runtime overhead (very small slowdown, a bit more memory usage)

• Extra work is only on async calls, we haven’t found it to be material

Since Streamline needs to keep up to date with JavaScript language enhancements (current thinking is that new ES6 language features to be handled by integrating 6to5)

With ES7 async/await, we may not need Streamline anymore. I can’t wait ;-)

Streamline Drawbacks

Page 16: Streamline.js and Node

www.RivalIQ.comDigital Marketing Analytics with a Competitive Edge16

Give Streamline a try!

Conclusion

Page 17: Streamline.js and Node

www.RivalIQ.comDigital Marketing Analytics with a Competitive Edge17

Questions

Page 18: Streamline.js and Node

www.RivalIQ.comDigital Marketing Analytics with a Competitive Edge18

Streamline repo: https://github.com/Sage/streamlinejs

Streamline FAQ: https://github.com/Sage/streamlinejs/blob/master/FAQ.md

Streamline mailing list: https://groups.google.com/forum/#!forum/streamlinejs

My blog post on Streamline: http://blog.rivaliq.com/develop-double-time-node-plus-streamline/

Streamline perf tests: https://gist.github.com/bjouhier/5554200

Bruno Jouhier’s blog: https://bjouhier.wordpress.com/

References

Page 19: Streamline.js and Node

www.RivalIQ.comDigital Marketing Analytics with a Competitive Edge

Digital Marketing Analytics with a Competitive Edge

Thank You