0
YOU WILL REGRET THIS!                          My Other Mood is Even More AngryFriday, June 10, 2011
IM GONNA TELL YOU A STORY                        In which I tell you how to behave                                        ...
SOCKET.IO-ERLANG    • Developed              by Yurii Rashkovskii, Omar Yasin, Fred Hebert (me)    • Used              as ...
BIZARRO SOCKET.IO-ERLANG    • Bad             socket.io-erlang used for the presentation    • Freely  substitutes dependen...
APP STRUCTUREFriday, June 10, 2011
APP STRUCTURE                                Bunch of supervisorsFriday, June 10, 2011
APP STRUCTURE                                Bunch of supervisors                 web serverFriday, June 10, 2011
APP STRUCTURE                                Bunch of supervisors                                 transport handlers      ...
APP STRUCTURE                                Bunch of supervisors          Client code         attaches here              ...
WE USE A WEB SERVER    • We    need a web server (the slides title says just that (and also        the previous slide))   ...
PARAMETRISED MODULES                        -­‐module(test_module,	  [Param1]).                        some_method()	  -­‐...
PARAMETRISED MODULES             1> X = test_module:new(horror),             X:some_method().             horror          ...
PARAMETRISED MODULES    • They              are great!    • We   can use them as if they        were objects!    • They   ...
PARAMETRISED MODULES    • They              are great!    • We   can use them as if they        were objects!    • They   ...
What?Friday, June 10, 2011
ILL TELL YOU WHAT              3> dbg:tp({X, some_method, 0}, [...]).              ** exception error: no case clause matc...
What is this I dont even...Friday, June 10, 2011
ILL TELL YOU WHAT    •   The parameters are global and they ghost values, become implicit        function arguments. Error...
Ill use them anyway                        (in my server)Friday, June 10, 2011
YOU PROBABLY SHOULDNT                        But you might not have a choice, so lets keep goingFriday, June 10, 2011
WHAT ELSE DO WE HAVE?    •A         supervision tree, of course!    • Some    of the supervisors are tricky and must inter...
IN THIS VERY SLIDE I PRETEND          I MAKE THE CHANGESFriday, June 10, 2011
APP STRUCTUREFriday, June 10, 2011
APP STRUCTURE                                  transport handlers                                 were moved and no       ...
APP STRUCTURE                                  transport handlers                                 were moved and no       ...
What?                        ... my code is so much easier to read now!Friday, June 10, 2011
ILL TELL YOU WHAT    • You   need to add ad-hoc start/restart policies and make sure        orderly shutdowns work fine wit...
Its okay, Ill do rolling upgrades                    through all nodes                        this should avoid downtimeFr...
NOT WITH LIVE SESSIONS!               Nobody likes to be disconnected during a conversation!                              ...
Stolen from Yuriis talk earlier today                NOT WITH LIVE SESSIONS!                        Nobody likes to be dis...
Stolen from Yuriis talk earlier today                NOT WITH LIVE SESSIONS!                        Nobody likes to be dis...
Youre killing me. Ill leave the           change in. Code is meant to be                       read first!Friday, June 10, ...
OK, AS LONG AS YOU LISTEN            TO THE NEXT POINTFriday, June 10, 2011
SURE, IM HAPPY                                    WITH MY APP    • Its       all done in OTP    • Now               Easier...
THIS IS GONNA BE FUN                   main(_) ->                       appmon:start(),                       sasl:start(n...
THIS IS GONNA BE FUN                   main(_) ->                       appmon:start(),                       sasl:start(n...
YOU, AGAIN!?                        You are worse than clippy                        What is it this time?Friday, June 10,...
ILL TELL YOU WHAT    • The VM            starts all applications under the Application Controller    • Starting          o...
AND IT GETS WORSE    • With    bad default values (or overly defensive code) for env        variables, bad things happen.....
DO THIS INSTEAD                   main(_) ->                       appmon:start(),                       application:start...
Oh...Friday, June 10, 2011
RIGHT                        Your OTP code is not worth much without thatFriday, June 10, 2011
One more                         thing...Friday, June 10, 2011
DONT LISTEN TO ME                        If your product might not ship because of this.                        Making it ...
HAPPY HACKING                        Hopefully you wont regret thisFriday, June 10, 2011
Upcoming SlideShare
Loading in...5
×

YOU WILL REGRET THIS

861

Published on

A lightning talk given at the London Erlang Factory in 2011, discussing Erlang anti-patterns seen in real world applications.

Published in: Technology, Education
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
861
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
2
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Transcript of "YOU WILL REGRET THIS"

  1. 1. YOU WILL REGRET THIS! My Other Mood is Even More AngryFriday, June 10, 2011
  2. 2. IM GONNA TELL YOU A STORY In which I tell you how to behave - how dare I?Friday, June 10, 2011
  3. 3. SOCKET.IO-ERLANG • Developed by Yurii Rashkovskii, Omar Yasin, Fred Hebert (me) • Used as a base demo app for this presentation • Allows to write neat front-ends for conversational websitesFriday, June 10, 2011
  4. 4. BIZARRO SOCKET.IO-ERLANG • Bad socket.io-erlang used for the presentation • Freely substitutes dependencies and actual code for whatever purpose I haveFriday, June 10, 2011
  5. 5. APP STRUCTUREFriday, June 10, 2011
  6. 6. APP STRUCTURE Bunch of supervisorsFriday, June 10, 2011
  7. 7. APP STRUCTURE Bunch of supervisors web serverFriday, June 10, 2011
  8. 8. APP STRUCTURE Bunch of supervisors transport handlers web serverFriday, June 10, 2011
  9. 9. APP STRUCTURE Bunch of supervisors Client code attaches here transport handlers web serverFriday, June 10, 2011
  10. 10. WE USE A WEB SERVER • We need a web server (the slides title says just that (and also the previous slide)) • Oh, Carrying parameters and a connection around is annoying! • Lets use parametrised modules!Friday, June 10, 2011
  11. 11. PARAMETRISED MODULES -­‐module(test_module,  [Param1]). some_method()  -­‐>  Param1. Equivalent to: -­‐module(test_non_pmod). some_method(Param1)  -­‐>  Param1.Friday, June 10, 2011
  12. 12. PARAMETRISED MODULES 1> X = test_module:new(horror), X:some_method(). horror 2> test_non_pmod:some_method(sane). saneFriday, June 10, 2011
  13. 13. PARAMETRISED MODULES • They are great! • We can use them as if they were objects! • They let us carry everything as one large parameter! • Lets do this!Friday, June 10, 2011
  14. 14. PARAMETRISED MODULES • They are great! • We can use them as if they were objects! • They let us carry everything as one large parameter! • Lets do this!Friday, June 10, 2011
  15. 15. What?Friday, June 10, 2011
  16. 16. ILL TELL YOU WHAT 3> dbg:tp({X, some_method, 0}, [...]). ** exception error: no case clause matching {test_module,horror} 4> dbg:tp({test_module, some_method, 0}, [...]). * never matches anything * 5> dbg:tp({test_module, some_method, 1}, [...]). * will actually match stuff *Friday, June 10, 2011
  17. 17. What is this I dont even...Friday, June 10, 2011
  18. 18. ILL TELL YOU WHAT • The parameters are global and they ghost values, become implicit function arguments. Errors out of nowhere. • Theyre based on a old fun hack ({Mod, Fun}:(Args)) • They mess up the concept of arity • They mess up tracing (previous slide!) • They were added because some library accepts callback modules and nothing else but might still need state around. No other reason.Friday, June 10, 2011
  19. 19. Ill use them anyway (in my server)Friday, June 10, 2011
  20. 20. YOU PROBABLY SHOULDNT But you might not have a choice, so lets keep goingFriday, June 10, 2011
  21. 21. WHAT ELSE DO WE HAVE? •A supervision tree, of course! • Some of the supervisors are tricky and must interact with servers and dynamic children and ... • Who starts who? By which API? • We could probably just forget about supervisors, link stuff together and make it simpler • Lets do this!Friday, June 10, 2011
  22. 22. IN THIS VERY SLIDE I PRETEND I MAKE THE CHANGESFriday, June 10, 2011
  23. 23. APP STRUCTUREFriday, June 10, 2011
  24. 24. APP STRUCTURE transport handlers were moved and no longer need a supervisor. They only use links. The code is more straightforward!Friday, June 10, 2011
  25. 25. APP STRUCTURE transport handlers were moved and no longer need a supervisor. They only use links. The code is more straightforward!Friday, June 10, 2011
  26. 26. What? ... my code is so much easier to read now!Friday, June 10, 2011
  27. 27. ILL TELL YOU WHAT • You need to add ad-hoc start/restart policies and make sure orderly shutdowns work fine with just links. Care to add tests? • You can no longer benefit from systools application upgrades and downgrades as they depend on supervisors • You will need to take your app down!Friday, June 10, 2011
  28. 28. Its okay, Ill do rolling upgrades through all nodes this should avoid downtimeFriday, June 10, 2011
  29. 29. NOT WITH LIVE SESSIONS! Nobody likes to be disconnected during a conversation! Would you disconnect this guy?Friday, June 10, 2011
  30. 30. Stolen from Yuriis talk earlier today NOT WITH LIVE SESSIONS! Nobody likes to be disconnected!Friday, June 10, 2011
  31. 31. Stolen from Yuriis talk earlier today NOT WITH LIVE SESSIONS! Nobody likes to be disconnected!Friday, June 10, 2011
  32. 32. Youre killing me. Ill leave the change in. Code is meant to be read first!Friday, June 10, 2011
  33. 33. OK, AS LONG AS YOU LISTEN TO THE NEXT POINTFriday, June 10, 2011
  34. 34. SURE, IM HAPPY WITH MY APP • Its all done in OTP • Now Easier to read • Uses parametrized modules, hell yes! • Its time to start it! • Lets do this!Friday, June 10, 2011
  35. 35. THIS IS GONNA BE FUN main(_) -> appmon:start(), sasl:start(normal, []), socketio:start(normal,[]), {ok, Pid} = socketio_listener:start([ {http_port, 7878}, {default_http_handler,?MODULE}]), EventMgr = socketio_listener:event_manager(Pid), ok = gen_event:add_handler(EventMgr, ?MODULE,[]), receive _ -> ok end. And it works! (believe me)Friday, June 10, 2011
  36. 36. THIS IS GONNA BE FUN main(_) -> appmon:start(), sasl:start(normal, []), socketio:start(normal,[]), {ok, Pid} = socketio_listener:start([ {http_port, 7878}, {default_http_handler,?MODULE}]), EventMgr = socketio_listener:event_manager(Pid), ok = gen_event:add_handler(EventMgr, ?MODULE,[]), receive _ -> ok end. And it works! (believe me)Friday, June 10, 2011
  37. 37. YOU, AGAIN!? You are worse than clippy What is it this time?Friday, June 10, 2011
  38. 38. ILL TELL YOU WHAT • The VM starts all applications under the Application Controller • Starting one outside of it means it is not supervised by it • No app failure strategy (permanent, transient, temporary) • No access to env variables • No respect of start phases or dependenciesFriday, June 10, 2011
  39. 39. AND IT GETS WORSE • With bad default values (or overly defensive code) for env variables, bad things happen... • In this case, infinitely many web sockets opened for each client (before a patch to change that, because I forgot to listen to this hint)Friday, June 10, 2011
  40. 40. DO THIS INSTEAD main(_) -> appmon:start(), application:start(sasl), application:start(misultin), application:start(socketio), {ok, Pid} = socketio_listener:start([ {http_port, 7878}, {default_http_handler,?MODULE}]), EventMgr = socketio_listener:event_manager(Pid), ok = gen_event:add_handler(EventMgr, ?MODULE,[]), receive _ -> ok end. And it works better! (believe me)Friday, June 10, 2011
  41. 41. Oh...Friday, June 10, 2011
  42. 42. RIGHT Your OTP code is not worth much without thatFriday, June 10, 2011
  43. 43. One more thing...Friday, June 10, 2011
  44. 44. DONT LISTEN TO ME If your product might not ship because of this. Making it work is #1. Making it pretty is not.Friday, June 10, 2011
  45. 45. HAPPY HACKING Hopefully you wont regret thisFriday, June 10, 2011
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×