Erlang real time


Published on


Published in: Technology
  • Be the first to comment

No Downloads
Total Views
On Slideshare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide

Erlang real time

  1. 1. Study of Erlang for Building Real-Time Systems<br />By<br />Dinesh Rajpoot<br />Roll no. 09305043<br />Under the guidance of<br /> Prof. Kavi Arya<br />August 20, 2010<br />
  2. 2. Outline<br /><ul><li>Introduction to Erlang
  3. 3. Erlang Highlights
  4. 4. Declarative
  5. 5. Concurrency
  6. 6. Fault-tolerant
  7. 7. Hot Code Swapping
  8. 8. Multi Core Programming</li></ul> Applications of Erlang<br /><ul><li>Robot Programming in Erlang
  9. 9. Challenges and Solutions
  10. 10. Case Study(Adaptive Cruise Control)
  11. 11. Conclusion and Future Work
  12. 12. References</li></li></ul><li>Introduction to Erlang<br />Erlang was designed by Ericcson.<br />It is a functional programming language.<br />Variables are immutable.<br />No side- effect(pure functions)<br />Referential Transparency <br />Int G =1; G is globalintplusG(int x){  return x + G;}<br />intplusOne(int x){  return x+1;}<br />
  13. 13. Declarative<br />Concentrate on “What” rather than “How”.<br />The programs are concise.<br />qsort([]) -> [];<br />qsort([Pivot|T]) -> qsort([X || X <- T, X =< Pivot]) ++ [Pivot] ++ <br />qsort([X || X <- T, X > Pivot]).<br />Programs are readable and easy to maintain.<br />It increases productivity.<br />
  14. 14. Concurrency<br />Each concurrent activity is called “process”.<br />Processes don’t share data.<br />Processes belong to language not operating system.<br />Processes communicate through “message passing”not shared memory.<br />Less process creation and message passing time. <br />
  15. 15. Concurrency<br />Create a process<br />Pid = spawn(Module, fun, [Arguments])<br />Send and receive<br />Pid ! message <br /> receive <br /> message1 -> actions1;<br /> message2 -> actions2;<br /> ……<br /> after Time -> time out actions;<br /> end.<br />
  16. 16. An example<br /> -module(echo).<br /> -export([start/0, loop/o]).<br /> start() -> <br />Pid = spawn (echo, loop, [ ] ),<br />Pid ! { self (), hello},<br /> receive <br /> { Pid, Msg } -><br />io:format ( “~w~n”, [Msg])<br /> end,<br />Pid ! stop.<br />loop() -> <br /> receive<br /> { From, Msg } -><br /> From ! { self(), Msg},<br /> loop();<br /> stop -> true<br /> end.<br />{<0.1.0>, hello}<br />{<0.1.0>, hello}<br />shell<br />Pid<br />{<0.2.0>, hello}<br />stop<br /><0.1.0><br /><0.2.0><br />
  17. 17. 1,000<br />erlang<br />java<br />C#<br />100<br />Microseconds/process<br />10<br />1<br />10<br />100<br />1,000<br />10,000<br />100,000<br />Number of processes<br />Process creation times (LOG/LOG scale)<br />> 200,000processes<br />Source:<br />Joe Armstrong<br />SICS<br />
  18. 18. 100,000<br />erlang<br />java<br />10,000<br />C#<br />1,000<br />Microseconds/message<br />100<br />10<br />1<br />1<br />10<br />100<br />1,000<br />10,000<br />100,000<br />Number of processes<br />Message passing times (LOG/LOG scale)<br />> 200,000processes<br />Source:<br />Joe Armstrong<br />SICS<br />
  19. 19. Fault Tolerant<br /><ul><li>Erlang provides fault tolerance through isolating errors and ensuring nonstop operation.</li></ul> {‘EXIT’, Pid, Reason} {‘EXIT’, Pid, Reason}<br /> {‘EXIT’, Pid, Reason}<br />
  20. 20. Hot Code Swapping<br />Embedded systems are reactive.<br />How can I update my system without shutting down?<br />In Erlang , we can change code on-the-fly. <br />We can keep 2 version of same module running.<br />
  21. 21. Multi-core Programming<br />How to achieve?<br />Use lots of processes.<br />Avoid side effects.<br />Avoid sequential bottleneck.<br />Write “small message, big computation”.<br />What is special about Erlang?<br />Message passing system.<br />No mutable data structure = No lock.<br />No mutable data structure = Easy to parallelize.<br />
  22. 22. Applications of Erlang<br />Erlang is useful when applications are concurrent, distributed and soft-real time.<br />It is used in telecommunication systems from Ericsson. <br />Some other commercial applications are:<br />Facebook uses Erlang to power the backend of its chat service, handling more than 100 million active users. <br />Mobile arts (GSM and UMTS services) <br />T-Mobile uses Erlang in its SMS and authentication systems. <br />
  23. 23. Robot Programming in Erlang<br />
  24. 24. Challenges & Solutions<br />Challenges<br />Erlang can’t directly interact with hardware.<br />Erlang can’t be converted into it’s equivalent C code.<br />Communication latency between PC and Firebird-V.<br />Solutions<br />Use C as middle-layer between Erlang and Micro-controller.<br />Use PC as master and Firebird as slave mode.<br />We can use small, low cost, fan-less processor and run Erlang on it.<br />
  25. 25. Case Study<br />Adaptive Cruise Control<br />Robot will follow white line while maintaining safe distance from other robots. <br />Robot using<br />FireBird V (8051 micro-controller)<br />Sensors using<br />Whiteline sensors(Left, Middle, Right)<br />Front sharp sensor<br />
  26. 26. Communication Model<br />Erlang<br />PC Micro-controller<br />read_sensor<br />Sensing<br />value <br />C program<br />Actuating<br />Take corrective measure<br />
  27. 27. Conclusion & Future Work<br />Programs in functional languages are concise and readable.<br />Concurrency model of Erlang helps in making concurrent programs without worrying about deadlocks.<br />We have seen the possibility of implementing robotic system using Erlang.<br />Since concurrency is crucial in building autonomous robotics applications, Erlang can be used in building such applications.<br />
  28. 28. References<br />Joe Armstrong “Programming Erlang”, May 2007<br />John Hughes "Why Functional programming Matters", 1984, revised in 1989 and 1990.<br />Francesco Cesarini and Simon Thompson, "Erlang Programming, O'Reilly, June 2009 .<br />Philip wadler "Functional Programming in the Real World“ .<br />Video lectures by Erlang- Training Consultancy<br />
  29. 29. Thank You<br />