streamline.js and node
TRANSCRIPT
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
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
www.RivalIQ.comDigital Marketing Analytics with a Competitive Edge3
Why do you love Node?
Ask Yourselves
www.RivalIQ.comDigital Marketing Analytics with a Competitive Edge4
Why do you love Node?
What don’t you like about Node?
Ask Yourselves
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?”
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
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….
www.RivalIQ.comDigital Marketing Analytics with a Competitive Edge8
Imagine If…
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?
www.RivalIQ.comDigital Marketing Analytics with a Competitive Edge10
Example 1: user login
[over to the IDE]
Code example 1
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
www.RivalIQ.comDigital Marketing Analytics with a Competitive Edge12
Example 2: processing data
[over to the IDE]
Code example 2
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
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
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
www.RivalIQ.comDigital Marketing Analytics with a Competitive Edge16
Give Streamline a try!
Conclusion
www.RivalIQ.comDigital Marketing Analytics with a Competitive Edge17
Questions
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
www.RivalIQ.comDigital Marketing Analytics with a Competitive Edge
Digital Marketing Analytics with a Competitive Edge
Thank You