Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
STREAMS ON
TOP OF SCALA
BY @WAXZCE – QUENTIN ADAM
LAMBDACON 2015 BOLOGNA
Quentin ADAM from the Clever Cloud
@waxzce on twitter – github- soundcloud – instagram ….
WHO AM I ?
MY DAY TO DAY WORK :
CLEVER CLOUD, MAKE YOUR
APP RUN ALL THE TIME
And learn a lot of things about your code, apps, and good/bad design…
KEEP YOUR APPS ONLINE. MADE WITH
NODE.JS, SCALA, JAV...
AND LEARN A LOT OF THINGS ABOUT
YOUR CODE, APPS, AND GOOD/BAD
DESIGN…
WHY ARE STREAMS SO
TRENDY THESE DAYS?
2 MAIN
REASONS
DATA IS BECOMING
BIGGER AND BIGGER
WE NEED TO ACT WHILE
DATA TRANSFERRING IS
OCCURRING
&
WE ARE NOW USING
LOTS OF PERMANENT
CONNECTIONS
REALITY FOR
MANY
DEVELOPERS
WEBSOCKETS
HTTP/2
EXAMPLE
WHAT IS INSIDE AN
HTTP REQUEST ?
Verb
• The action
Resource
• The object of the action
Headers
• The context of the action...
IN MANY CASES THE REQUEST IS
MANIPULATED ALL FROM MEMORY
UPLOADING A
20 GB FILE ON
A POST
REQUEST
AND STORING IT
EXAMPLE
IT’S A BAD IDEA TO PUT THE BODY
PART IN MEMORY
CREATE A TEMP FILE TO STORE THE
DATA
I HATE FILE
SYSTEMS
I HATE FILE
SYSTEMS
DO NOT USE THE FILE
SYSTEM AS A DATASTORE
File systems are POSIX compliant
• POSIX is ACID
• POSIX is powerful but is a bo...
Client
uploads
file
Create a
temp file
Send a
file in a
backend
Then
answer to
the client
The file is
transferring two
tim...
NOT SO GOOD
Client
uploads file
Directly
stream it to
the backend
Then
answer to
the client
LET’S ACT ON STREAMS!
CLASSIC JAVA STREAM
MANAGEMENT
CLASSIC JAVA STREAM
MANAGEMENT
• Buffers
• Buffer management
• Buffer exception
• Buffer overflow
CLASSIC JAVA STREAM
MANAGEMENT
• Low performances if not buffered
• Not modular
• Thread blocking
• Code is ugly
• No back...
I CAN’T SLEEP AT NIGHT
WE HAVE TO FIND A BETTER WAY
DATA
STRUCTURES
TO EXPRESS
DATA STREAM
MANAGEMENT
PLAY-
ITERATEES
FIRST OPTION
Like a recipe
Consume the data
ITERATEE : HOW TO MANAGE A STREAM
Produce the data
ENUMERATOR : DATA STREAM
Set of tools to do cool things with Iteratee and Enumerator
ENUMERATEE
SIMPLE EXAMPLE TO START
WHAT’S OUR GOAL
• Get Reactive Manifesto words
• Stream it to an iteratee to group it by pair of word
• Print it
AN ENUMERATOR
AN ITERATEE
input
EOF
EmptyEl
Iteratee
State
Done
ErrorCont
AN ITERATEE
AN ITERATEE TO
MANAGE THE STREAM
AN ITERATEE
ITERATEE
COMPOSITION
PURELY FUNCTIONAL
TYPE SAFE
COMPOSITION
WHAT’S
TRENDY?
BUT ITERATEES ARE GOING TO DIE
SCALAZ STREAMS
WHAT’S IN
THE BOX ?
BASED ON SCALAZ
BASICS
PROCESS IS KEY
SIMPLY USE THE
COLLECTION API
DEMO
BINDINGS WITH
• http with (netty or http4s)
• scodec
• …
BUT WE
NEED TO
TALK WITH
OTHERS…
LIKE OUR
FRIENDS
ON TOP OF
JVM
AND THEY
HAVE LESS
EXPRESSIVE
TYPE
SYSTEM
+ POLITICS
REACTIVE
STREAMS
ENTER
AKKA
STREAMS
CURRENT 1.0-M5 (MILESTONE) (M5 OUT
YESTEDAY)
BASIC EXAMPLE
BASIC EXAMPLE
DEMO AGAIN
MORE POSSIBILITIES
Grab from
rabbitMQ
Parse Event
Check event
ACL from
DB
Find reliable
WS
Send data to
WS
ARE YOU CONVINCE
TO USE STREAM ?
GO NOW
Iteratee
Scalaz-
streams
Akka-
stream
• learn
• Act now on play!
• Beautiful design
• The most scala-ish
way to do
...
DATA STREAMING
PROGRAMMING IS NOW
TRENDING
THX TO @CLEMENTD
CLEMENT DELAFARGUE
I’m @waxzce on twitter
I’m the CEO of
A PaaS provider, give it a try
;-)
THX FOR LISTENING
& QUESTIONS TIME
Coupon for Cle...
Streams on top of scala - #lambdaCon
Streams on top of scala - #lambdaCon
Streams on top of scala - #lambdaCon
Upcoming SlideShare
Loading in …5
×

Streams on top of scala - #lambdaCon

2,132 views

Published on

Everybody has something about streams on the Scala platform: iteratee, scalaz.streams, reactive streams, akka.io, and so on.
But are they useful for the day to day developer job? Are they only for database drivers? What are the differences between all this technologies?
You will understand what are streams, why you need them and how to use them in real world scenarios

Published in: Technology
  • Login to see the comments

Streams on top of scala - #lambdaCon

  1. 1. STREAMS ON TOP OF SCALA BY @WAXZCE – QUENTIN ADAM LAMBDACON 2015 BOLOGNA
  2. 2. Quentin ADAM from the Clever Cloud @waxzce on twitter – github- soundcloud – instagram …. WHO AM I ?
  3. 3. MY DAY TO DAY WORK : CLEVER CLOUD, MAKE YOUR APP RUN ALL THE TIME
  4. 4. And learn a lot of things about your code, apps, and good/bad design… KEEP YOUR APPS ONLINE. MADE WITH NODE.JS, SCALA, JAVA, RUBY, PHP, PYTHON, GO OR DOCKER…
  5. 5. AND LEARN A LOT OF THINGS ABOUT YOUR CODE, APPS, AND GOOD/BAD DESIGN…
  6. 6. WHY ARE STREAMS SO TRENDY THESE DAYS?
  7. 7. 2 MAIN REASONS
  8. 8. DATA IS BECOMING BIGGER AND BIGGER
  9. 9. WE NEED TO ACT WHILE DATA TRANSFERRING IS OCCURRING
  10. 10. &
  11. 11. WE ARE NOW USING LOTS OF PERMANENT CONNECTIONS
  12. 12. REALITY FOR MANY DEVELOPERS
  13. 13. WEBSOCKETS
  14. 14. HTTP/2
  15. 15. EXAMPLE
  16. 16. WHAT IS INSIDE AN HTTP REQUEST ? Verb • The action Resource • The object of the action Headers • The context of the action Body • Optional • The datas
  17. 17. IN MANY CASES THE REQUEST IS MANIPULATED ALL FROM MEMORY
  18. 18. UPLOADING A 20 GB FILE ON A POST REQUEST AND STORING IT EXAMPLE
  19. 19. IT’S A BAD IDEA TO PUT THE BODY PART IN MEMORY
  20. 20. CREATE A TEMP FILE TO STORE THE DATA
  21. 21. I HATE FILE SYSTEMS
  22. 22. I HATE FILE SYSTEMS
  23. 23. DO NOT USE THE FILE SYSTEM AS A DATASTORE File systems are POSIX compliant • POSIX is ACID • POSIX is powerful but is a bottleneck • File System is the nightmare of ops • File System creates coupling (host provider/OS/language) • SPOF-free multi tenant File System is a unicorn
  24. 24. Client uploads file Create a temp file Send a file in a backend Then answer to the client The file is transferring two times
  25. 25. NOT SO GOOD
  26. 26. Client uploads file Directly stream it to the backend Then answer to the client
  27. 27. LET’S ACT ON STREAMS!
  28. 28. CLASSIC JAVA STREAM MANAGEMENT
  29. 29. CLASSIC JAVA STREAM MANAGEMENT • Buffers • Buffer management • Buffer exception • Buffer overflow
  30. 30. CLASSIC JAVA STREAM MANAGEMENT • Low performances if not buffered • Not modular • Thread blocking • Code is ugly • No back pressure • Error handling is bad • i/o management and business code are mixed
  31. 31. I CAN’T SLEEP AT NIGHT
  32. 32. WE HAVE TO FIND A BETTER WAY
  33. 33. DATA STRUCTURES TO EXPRESS DATA STREAM MANAGEMENT
  34. 34. PLAY- ITERATEES FIRST OPTION
  35. 35. Like a recipe Consume the data ITERATEE : HOW TO MANAGE A STREAM
  36. 36. Produce the data ENUMERATOR : DATA STREAM
  37. 37. Set of tools to do cool things with Iteratee and Enumerator ENUMERATEE
  38. 38. SIMPLE EXAMPLE TO START
  39. 39. WHAT’S OUR GOAL • Get Reactive Manifesto words • Stream it to an iteratee to group it by pair of word • Print it
  40. 40. AN ENUMERATOR
  41. 41. AN ITERATEE
  42. 42. input EOF EmptyEl
  43. 43. Iteratee State Done ErrorCont
  44. 44. AN ITERATEE
  45. 45. AN ITERATEE TO MANAGE THE STREAM
  46. 46. AN ITERATEE
  47. 47. ITERATEE COMPOSITION
  48. 48. PURELY FUNCTIONAL
  49. 49. TYPE SAFE
  50. 50. COMPOSITION
  51. 51. WHAT’S TRENDY? BUT ITERATEES ARE GOING TO DIE
  52. 52. SCALAZ STREAMS
  53. 53. WHAT’S IN THE BOX ?
  54. 54. BASED ON SCALAZ BASICS
  55. 55. PROCESS IS KEY
  56. 56. SIMPLY USE THE COLLECTION API
  57. 57. DEMO
  58. 58. BINDINGS WITH • http with (netty or http4s) • scodec • …
  59. 59. BUT WE NEED TO TALK WITH OTHERS…
  60. 60. LIKE OUR FRIENDS ON TOP OF JVM
  61. 61. AND THEY HAVE LESS EXPRESSIVE TYPE SYSTEM
  62. 62. + POLITICS
  63. 63. REACTIVE STREAMS ENTER
  64. 64. AKKA STREAMS CURRENT 1.0-M5 (MILESTONE) (M5 OUT YESTEDAY)
  65. 65. BASIC EXAMPLE
  66. 66. BASIC EXAMPLE
  67. 67. DEMO AGAIN
  68. 68. MORE POSSIBILITIES Grab from rabbitMQ Parse Event Check event ACL from DB Find reliable WS Send data to WS
  69. 69. ARE YOU CONVINCE TO USE STREAM ?
  70. 70. GO NOW Iteratee Scalaz- streams Akka- stream • learn • Act now on play! • Beautiful design • The most scala-ish way to do • Enterprise compatible • Wide ecosystem • Reactive stream ready
  71. 71. DATA STREAMING PROGRAMMING IS NOW TRENDING
  72. 72. THX TO @CLEMENTD CLEMENT DELAFARGUE
  73. 73. I’m @waxzce on twitter I’m the CEO of A PaaS provider, give it a try ;-) THX FOR LISTENING & QUESTIONS TIME Coupon for Clever Cloud trial : lambdacon

×