Web, Concurrency, FP

Web, Concurrency, FP

Hotcode, 2013

B9b7a5ffa24e2af6f877a7950461ba0f?s=128

Oleksii Kachaiev

May 31, 2013
Tweet

Transcript

  1. Web, Concurrency, FP the problems that we can’t ignore ...

    any more (c) Alexey Kachayev, 2013
  2. About me Alexey Kachayev •CTO at Attendify •Open source activist

    (Fn.py) •Functional programming advocate •Erlang, Python, Scala, Clojure, Haskell, Go hacker
  3. Contacts •kachayev <$> twitter •kachayev <$> gmail •kachayev <$> github

  4. Disclaimer #1 It’s hard to tell “is this language functional?”

    We will talk about: Erlang, Scala, Clojure, Haskell
  5. Disclaimer #2 Web is only one way to communicate. We

    will talk “mostly” about web. I assume that you know what “Web” is. Note, that it changes really fast.
  6. Modern web challenges •real-time notifications •chats and other RT messaging

    systems •real-time activity stream •collaborative documents editing •task board for team •multi-player Bomberman (* or your favorite game)
  7. Concurrency... Concurrency is the composition of independently executing computations. Concurrency

    is a way to structure software, ... (c) Rob Pike “Concurrency is not parallelism”
  8. Concurrency is hard when independent computations depend on each other

  9. WTF??? how independent computations can depend on each other?

  10. Why should I care? I’m just coding Python/Ruby/PHP/ Node.js...

  11. Classical web dev •Many OS processes •Database to store data

    •.... •You are welcome in the world of concurrency!
  12. So what? •Race condition on your data •Real-time is hard

    (databases are not designed for this) •Leaking abstractions •Independency is expensive •No tests •No control
  13. Java & .NET web dev •Threads instead of processes (VM

    as OS???) •You can use memory for data collaboration •Necessity to control access to shared data leads you to locks/ mutex/semaphores
  14. So what? •Independency is still too expensive •Still hard to

    test •Still hard to control •Locks are not so good abstraction
  15. Event- driven web dev •Single-thread environment •Event-based context switching loop

    •Not so “independent” as we want •Errors are hard to manage •It’s hard to keep code simple to read
  16. Do you need more problems? •request-reply doesn’t work (almost at

    all) •concurrency is hard •fault-tolerance is hard •vertical scaling is hard (as well as horizontal) •everything should have been done yesterday
  17. How to deal with concurrency?

  18. Story about developers and tasks board •Locks: what is locks

    and why it’s not a good idea? •Message passing: how to communicate and what are the benefits? •STM: how to collaborate efficiently and not lose control?
  19. From theory to practice

  20. Concurrency •Erlang •Scala •others •Clojure •Haskell •others Communication Collaboration And

    why do FP “features” matter?
  21. Erlang •message-passing concurrency •multi-core support •distributed systems •“super” stable VM

    (VM as OS!) •“hard to break” something •interactive development
  22. Scala • JVM based, high performance • (mostly) functional paradigm

    • expressive type system (ADT & TI) • “less code with more results” • message-passing concurrency (prev. Akka) • ... XML is native Scala type
  23. Reactivity or “super- thin” client •Liftweb (Scala) •Nitrogen (Erlang) •N2O

    (Erlang)
  24. Clojure •FP, lisp-family •STM concurrency model •modern language •interactive development

    •macros •JavaScript compiler •huge web stack
  25. Haskell •FP, “ML-family” •green threads and STM •expressive type system

    •high level of code modularity and composability •compact declarative syntax •compile-time program verification
  26. IWBYP http://iwbyp.chris-granger.com/

  27. How to start? •do not wait! •do not hesitate! •do

    not panic!!! •do something simple •do something interesting •find problem (pain?) and solve it
  28. Links • https://github.com/extend/cowboy • http://nitrogenproject.com/ • http://liftweb.net/ • https://github.com/twitter/finagle •

    http://www.scalatra.org/ • https://github.com/ring-clojure/ring • https://github.com/weavejester/ compojure • http://pedestal.io/ • http://himera.herokuapp.com/ synonym.html • http://snapframework.com/
  29. Questions? * other talks: https://kachayev.github.com/talks ** me: http://twitter.com/kachayev P.S. We

    are hiring