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.
Scala Erlang                
                Beijing 2010.04


Caoyuan (NetBeans Dream Team Member)

                     ...
•                     (
     )

•             

• 
•                                
     •         CPU                           
     •                       
          • ...
-                          

•       1206                      
•  103       x1.5 =155                6 
•  6144 CPU 5120 ...
• 
               
     •  Fortress Erlang Scala => Scala 
          •          
          •                            
 ...
Actor              Erlang Scala                   
      Erlang Scala             Actor    



•  Erlang
   •  Erlang VM  ...
Actor               -                       Actor
                                                                
Actor  ...
Actor                                
     Actor                    OO                                       


•         ...
Actor                  
Actor                  



•                 
•                          
• 
         Actor
      ...
Actor   




                       
                   
            CPU
Actor              –            vs       
                 
                                

        Actor
              ...
JVM          




                                       
              Scheduler
                                       
...
Scala JVM                     Actor
                                                 


                                  ...
Erlang           Actor             Process
                                              




                            ...
•                                        Actor
                 
                      Actors                            ...
Erlang vs Scala –                      

•  Erlang Process                                          
  •          Process
...
Erlang vs Scala –          

•  Scala Actor                    
  •    Actor
                            Actors
       
  ...
Erlang vs Scala –                     

•  Erlang Process          
  •                            
  •                 (G...
Erlang vs Scala –                

•  Scala Actor
   Erlang                
  •                      
  •                 ...
Erlang vs Scala –                                               
object ThreadRing {	
  val (nTokens, nProcs) = (20000, 10...
Erlang vs Scala –                                       
-module(threadring).	
-export([main/0, ring/2]).	
-define(N_TOKEN...
Erlang vs Scala –FP       OO+FP
                                     

•  Erlang                         
   •            ...
Erlang vs Scala –FP   OO+FP
                                     

•  Scala                OO+FP          
   •           ...
Q&A


       Scala
Upcoming SlideShare
Loading in …5
×

并发需求下Scala和Erlang的比较-QConBeijing2010

3,345 views

Published on

  • Be the first to comment

并发需求下Scala和Erlang的比较-QConBeijing2010

  1. 1. Scala Erlang Beijing 2010.04 Caoyuan (NetBeans Dream Team Member) http://blogtrader.net @dcaoyuan
  2. 2. •  ( ) •  • 
  3. 3. •  •  CPU •  •  •  •  • 
  4. 4. - •  1206 •  103 x1.5 =155 6 •  6144 CPU 5120 GPU •  •  1280 •  1280 •  3 16 •  CPU 60%
  5. 5. •  •  Fortress Erlang Scala => Scala •  •  •  DSL •  - •  Map-Reduce, Fork-Join • 
  6. 6. Actor Erlang Scala Erlang Scala Actor •  Erlang •  Erlang VM Actor •  •  Scala •  Actor JVM •  actor
  7. 7. Actor - Actor Actor •  Actors actor ! ChangeYourPosition Pid ! change_your_position •  Actors val a = actor { loop(I) -> def loop(i: Int): Unit = receive react { I -> I, loop(I + 1); case i: Int => loop(i + 1) exit -> io:format(“~p~n”, [I]) case Exit => println(i) end } end loop(0) Pid = spawn(fun loop/1, [0]) } •  •  Actor •  loop (Scala Erlang) (Scala) •  Actors
  8. 8. Actor Actor OO •  •  OO •  Actor •  (immutable) •  •  •  Actor •  Actor Actor •  Actor Actor Actor
  9. 9. Actor Actor •  •  •  Actor CPU • 
  10. 10. Actor CPU
  11. 11. Actor – vs Actor Actor CPU Actors CPU
  12. 12. JVM Scheduler •  •  IO •  CPU
  13. 13. Scala JVM Actor Scheduler •  Actor Object •  Actor •  Actor •  Actor Actor •  Actors Actors •  Scala IO IO Actor
  14. 14. Erlang Actor Process Scheduler •  Erlang Actor Process •  Process •  Process •  Process •  Erlang IO Process IO
  15. 15. •  Actor   Actors Actor •    sleep IO   •  Scala Actor NIO
  16. 16. Erlang vs Scala – •  Erlang Process •  Process •  Process •  Process CPU Process •  log   2-core 140 process 200 process CPU 1 / 200 * 2 Core = 1%   8-core 700 process 980 process CPU 1 / 980 * 8 Core = 0.82%
  17. 17. Erlang vs Scala – •  Scala Actor •  Actor Actors •  Actor •  •  Actor
  18. 18. Erlang vs Scala – •  Erlang Process •  •  (GC ) •  ( ) •  VM ( ) •  •  ( )
  19. 19. Erlang vs Scala – •  Scala Actor Erlang •  •  •  VM VM •  •  JVM • 
  20. 20. Erlang vs Scala – object ThreadRing { val (nTokens, nProcs) = (20000, 10000) def main(args: Array[String]) { val last= Ring(null, 1) val h = Range(nProcs, 2, -1).foldLeft(last){(acc, i) => Ring(acc, i)} last.next = h h ! nTokens } case class Ring(var next: Ring, id: Int) extends Actor { start def act = loop { react { case 1 => println("Done") println(id) System.exit(0) case token: Int => next ! token - 1 println(token) //fib(N_FIB) } } } }
  21. 21. Erlang vs Scala – -module(threadring). -export([main/0, ring/2]). -define(N_TOKENS, 20000). -define(N_PROCS, 10000). main() -> start(?N_TOKENS). start(NToken) -> H = lists:foldl(fun(Id, Pid) -> spawn(threadring, ring, [Id, Pid]) end, self(), lists:seq(?N_PROCS, 2, -1)), H ! NToken, ring(1, H). ring(Id, Pid) -> receive 1 -> io:fwrite(”~p~n", [done]), io:fwrite("~b~n", [Id]), erlang:halt(); Token -> Pid ! Token - 1, io:fwrite("~b~n", [Token]), //fib(?N_FIB), ring(Id, Pid) end.
  22. 22. Erlang vs Scala –FP OO+FP •  Erlang •  •  Process • 
  23. 23. Erlang vs Scala –FP OO+FP •  Scala OO+FP •  •  Actor Actors •  Actor • 
  24. 24. Q&A Scala

×