SlideShare une entreprise Scribd logo
1  sur  24
Télécharger pour lire hors ligne
Scala Erlang                
                Beijing 2010.04


Caoyuan (NetBeans Dream Team Member)

                                        
         http://blogtrader.net
         @dcaoyuan
•                     (
     )

•             

• 
•                                
     •         CPU                           
     •                       
          •              
          •                          
          •          


• 
-                          

•       1206                      
•  103       x1.5 =155                6 
•  6144 CPU 5120 GPU
•                 
     •          1280 
     •        1280   
     •    3              16   
•              CPU                     60%
• 
               
     •  Fortress Erlang Scala => Scala 
          •          
          •                            
          •  DSL
               
     •        -                            
          •  Map-Reduce, Fork-Join 
• 
Actor              Erlang Scala                   
      Erlang Scala             Actor    



•  Erlang
   •  Erlang VM                     Actor       
   •                 


•  Scala
   •  Actor                   JVM           
   •      actor
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
Actor                                
     Actor                    OO                                       


•                                  
     •  OO                                         
     •          Actor                                              
     •          (immutable)                            


•                                  
     •                                         
     •  Actor
                                               
     •  Actor
                                   Actor                       
     •                                 Actor
          Actor        Actor
Actor                  
Actor                  



•                 
•                          
• 
         Actor
                 CPU               
• 
Actor   




                       
                   
            CPU
Actor              –            vs       
                 
                                

        Actor
                                              



Actor                CPU
       Actors            CPU
JVM          




                                       
              Scheduler
                                       


• 

                               
•    IO                            
•               CPU
Scala JVM                     Actor
                                                 


                                                                  


                                                                  

                            Scheduler
                            
                                                                  

•    Actor         Object                            
•    Actor                   
•    Actor                               
•    Actor
                                             Actor   
•             Actors                                     Actors
                                                           
•            Scala   IO
     IO        Actor
Erlang           Actor             Process
                                              




                                                               
                       Scheduler
                                                               

•    Erlang   Actor    Process                         
•    Process                        
•    Process                                               
•    Process                                    
•    Erlang IO                               Process
                      IO
•                                        Actor
                 
                      Actors                            Actor
                                                             
•                                                            
       
                      sleep     IO                           
       
                                                     
• 
             


     Scala       Actor NIO
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%
Erlang vs Scala –          

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

•  Erlang Process          
  •                            
  •                 (GC             )
  •                   (            )
  •  VM                                  (
             )
  • 
                           
  •                        (                     )
Erlang vs Scala –                

•  Scala Actor
   Erlang                
  •                      
  •                          
  •  VM                              VM
  •                                           
  •     JVM                               
  • 
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)	
        }	
     }	
  }	
}
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.
Erlang vs Scala –FP       OO+FP
                                     

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

•  Scala                OO+FP          
   •                             
   •  Actor
                                     Actors
   •                                        Actor
              
   • 
Q&A


       Scala

Contenu connexe

En vedette

Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTExpeed Software
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsPixeldarts
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthThinkNow
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfmarketingartwork
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsKurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summarySpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Applitools
 

En vedette (20)

Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
 

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

  • 1. Scala Erlang Beijing 2010.04 Caoyuan (NetBeans Dream Team Member) http://blogtrader.net @dcaoyuan
  • 2. •  ( ) •  • 
  • 3. •  •  CPU •  •  •  •  • 
  • 4. - •  1206 •  103 x1.5 =155 6 •  6144 CPU 5120 GPU •  •  1280 •  1280 •  3 16 •  CPU 60%
  • 5. •  •  Fortress Erlang Scala => Scala •  •  •  DSL •  - •  Map-Reduce, Fork-Join • 
  • 6. Actor Erlang Scala Erlang Scala Actor •  Erlang •  Erlang VM Actor •  •  Scala •  Actor JVM •  actor
  • 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. Actor Actor OO •  •  OO •  Actor •  (immutable) •  •  •  Actor •  Actor Actor •  Actor Actor Actor
  • 9. Actor Actor •  •  •  Actor CPU • 
  • 10. Actor CPU
  • 11. Actor – vs Actor Actor CPU Actors CPU
  • 12. JVM Scheduler •  •  IO •  CPU
  • 13. Scala JVM Actor Scheduler •  Actor Object •  Actor •  Actor •  Actor Actor •  Actors Actors •  Scala IO IO Actor
  • 14. Erlang Actor Process Scheduler •  Erlang Actor Process •  Process •  Process •  Process •  Erlang IO Process IO
  • 15. •  Actor   Actors Actor •    sleep IO   •  Scala Actor NIO
  • 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. Erlang vs Scala – •  Scala Actor •  Actor Actors •  Actor •  •  Actor
  • 18. Erlang vs Scala – •  Erlang Process •  •  (GC ) •  ( ) •  VM ( ) •  •  ( )
  • 19. Erlang vs Scala – •  Scala Actor Erlang •  •  •  VM VM •  •  JVM • 
  • 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. 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. Erlang vs Scala –FP OO+FP •  Erlang •  •  Process • 
  • 23. Erlang vs Scala –FP OO+FP •  Scala OO+FP •  •  Actor Actors •  Actor • 
  • 24. Q&A Scala