SlideShare une entreprise Scribd logo
1  sur  37
Ruby 1.9.3
                        GVL
                                           Fujitsu




Sunday, July 17, 2011
Who am I?




Sunday, July 17, 2011
•

                    •       IO   OS



                    • usa




Sunday, July 17, 2011
at Linux Kernel
                         Summit 2010


Sunday, July 17, 2011
Shyouhei commiter ranking




                                                me!




Sunday, July 17, 2011
Sunday, July 17, 2011
Sunday, July 17, 2011
GVL




Sunday, July 17, 2011
What’s GVL
                    • Global(or Giant) VM Lock
                    •

                    •             multi thread issue   Ruby script



                    •                      CPU



                    • Python


Sunday, July 17, 2011
What’s GVL (cont.)

                    • GVL


                    •        GVL



                    • OS


Sunday, July 17, 2011
f = false

                        Thread.new {

                            ....;

                            f = true

                        }

                        Thread.pass until f


Sunday, July 17, 2011
GVL design
                    • Lock
                            wait                             (e.g. write)



                    • lock, unlock

                                             Python, QEMU,    Linux



                    • GVL acquire/release
                        pthread_mutex_{lock,unlock}

Sunday, July 17, 2011
GVL design (cont.)
                    •


                    •




Sunday, July 17, 2011
GVL design (cont.)
                •       ON            if (th->interrupt_flag) {

                                          gvl_release();

                                          sched_yield();

                                          gvl_acquire();

                                      }




Sunday, July 17, 2011
•              OSS            while (true) {
                               (         )          lock();
                                                    if (hoge) {
                                                       unlock();
                                                       break;
                    •                               }
                                                    unlock();
                    • thread             lock       rep_nop();
                                                  }
                                         hoge=1
                                                  lock();
                                                  hoge = 1;
                                                  unlock();
Sunday, July 17, 2011
Why?




Sunday, July 17, 2011
CPU


                          cpu1        cpu2

        memory          core core   core core   memory
          1                                       2
                        core core   core core




Sunday, July 17, 2011
if (th->interrupt_flag) {

                                      gvl_release();

                                      sched_yield();

                                      gvl_acquire();

                                  }


          •gvl_release() gvl_acquire()                       sched_yield()


          •             sched_yield()                    yield


Sunday, July 17, 2011
sched_yield
                    • Unix                               API
                             http://pubs.opengroup.org/onlinepubs/009695399/
                             functions/sched_yield.html


                             int sched_yield(void);

                             • The sched_yield() function shall force the
                               running thread to relinquish the processor
                               until it again becomes the head of its
                               thread list.


                    •




Sunday, July 17, 2011
Thread
                core


                                 Thread   Thread   Thread
                        Thread
                  core



                        Thread
                  core

Sunday, July 17, 2011
(ry
                                          CPU


                        Thread
                core             Thread     Thread



                        Thread
                  core           Thread



                        Thread
                  core           Thread

Sunday, July 17, 2011
Yield!


                           Ruby
                          Thread

                core               Thread



                          Thread
                  core              Ruby
                                   Thread




Sunday, July 17, 2011
thread list
                                          head

                        Thread
                core              Ruby
                                 Thread




                        Thread
                  core            Ruby
                                 Thread




Sunday, July 17, 2011
Ruby
                        Thread

                core             Thread



                        Thread
                  core            Ruby
                                 Thread




        POSIX


Sunday, July 17, 2011
CFS yield
                    • Linux    RHEL5   RHEL6



                    • RHEL6               (CFS)   sched_yield
                         (RHEL5           knob

                    •         Java

                    • Linux upstream   knob
                        CPU



Sunday, July 17, 2011
•   fairness




Sunday, July 17, 2011
•          fairness

                    •                     GVL




         gvl_acquire                            gvl_release
         mutex_lock(&lock->lock)                mutex_lock(&lock->lock)
         cond_wait(&lock->wait)                 lock->acquired = 0;
         lock->acquired = 1;                    cond_signal(&lock->wait_cond)

         //                                     //
         cond_signal(&lock->switch_cond)        cond_wait(&lock->switch_cond)

         mutex_unlock(&lock->lock)              mutex_unlock(&lock->lock)
Sunday, July 17, 2011
vm_thread_pipe
  lmax = 100_000
  r, w = IO.pipe
  [Thread.new{
    lmax.times{
      w.write('a')
    }
    p "w:exit"
  }, Thread.new{
    lmax.times{
      r.read(1)
    }
    p "r:exit"
  }].each{|t| t.join}
Sunday, July 17, 2011
(´   ω   )

Sunday, July 17, 2011
• fairness

                    •         unfairness



                    • Linux


                    •

Sunday, July 17, 2011
1.9.3
                    • 1.9.3      IO   GVL release
                        GVL release

                    • IO                GVL     1.9.2       IO   GVL
                        switch

                    •
                                              GVL release    switch
                                          GVL

                    •

Sunday, July 17, 2011
1.9.2          1.9.3

              2


         1.5


              1


         0.5


              0
                  create_join mutex1   mutex2   mutex3 pass_flood   pipe


Sunday, July 17, 2011
•   1.9.2

                    •

                    •



                    •

Sunday, July 17, 2011
vm_thread_mutex3




Sunday, July 17, 2011
Sunday, July 17, 2011
•            CPU

           • GVL              CPU

           •                   Ruby




Sunday, July 17, 2011
Question?




Sunday, July 17, 2011

Contenu connexe

Similaire à Ruby gvl-improvement at ruby 1.9.3

Clouds against the Floods (RubyConfBR2011)
Clouds against the Floods (RubyConfBR2011) Clouds against the Floods (RubyConfBR2011)
Clouds against the Floods (RubyConfBR2011)
Leonardo Borges
 
JVM for Dummies - OSCON 2011
JVM for Dummies - OSCON 2011JVM for Dummies - OSCON 2011
JVM for Dummies - OSCON 2011
Charles Nutter
 
Writing a Crawler with Python and TDD
Writing a Crawler with Python and TDDWriting a Crawler with Python and TDD
Writing a Crawler with Python and TDD
Andrea Francia
 
Java SE 7 - The Platform Evolves, Dalibor Topić (Oracle)
Java SE 7 - The Platform Evolves, Dalibor Topić (Oracle)Java SE 7 - The Platform Evolves, Dalibor Topić (Oracle)
Java SE 7 - The Platform Evolves, Dalibor Topić (Oracle)
OpenBlend society
 
Conquistando el Servidor con Node.JS
Conquistando el Servidor con Node.JSConquistando el Servidor con Node.JS
Conquistando el Servidor con Node.JS
Caridy Patino
 
让开发也懂前端
让开发也懂前端让开发也懂前端
让开发也懂前端
lifesinger
 
Google kick ass-game_programming_with_gwt
Google   kick ass-game_programming_with_gwtGoogle   kick ass-game_programming_with_gwt
Google kick ass-game_programming_with_gwt
momobeijing
 
international PHP2011_ilia alshanetsky_Hidden Features of PHP
international PHP2011_ilia alshanetsky_Hidden Features of PHPinternational PHP2011_ilia alshanetsky_Hidden Features of PHP
international PHP2011_ilia alshanetsky_Hidden Features of PHP
smueller_sandsmedia
 
Ruby hollywood
Ruby hollywoodRuby hollywood
Ruby hollywood
ehuard
 

Similaire à Ruby gvl-improvement at ruby 1.9.3 (20)

Clouds against the Floods (RubyConfBR2011)
Clouds against the Floods (RubyConfBR2011) Clouds against the Floods (RubyConfBR2011)
Clouds against the Floods (RubyConfBR2011)
 
Puppet camp europe 2011 hackability
Puppet camp europe 2011   hackabilityPuppet camp europe 2011   hackability
Puppet camp europe 2011 hackability
 
JVM for Dummies - OSCON 2011
JVM for Dummies - OSCON 2011JVM for Dummies - OSCON 2011
JVM for Dummies - OSCON 2011
 
Writing a Crawler with Python and TDD
Writing a Crawler with Python and TDDWriting a Crawler with Python and TDD
Writing a Crawler with Python and TDD
 
Java SE 7 - The Platform Evolves, Dalibor Topić (Oracle)
Java SE 7 - The Platform Evolves, Dalibor Topić (Oracle)Java SE 7 - The Platform Evolves, Dalibor Topić (Oracle)
Java SE 7 - The Platform Evolves, Dalibor Topić (Oracle)
 
Caridy patino - node-js
Caridy patino - node-jsCaridy patino - node-js
Caridy patino - node-js
 
Conquistando el Servidor con Node.JS
Conquistando el Servidor con Node.JSConquistando el Servidor con Node.JS
Conquistando el Servidor con Node.JS
 
Erlang: Bult for concurrent, distributed systems
Erlang: Bult for concurrent, distributed systemsErlang: Bult for concurrent, distributed systems
Erlang: Bult for concurrent, distributed systems
 
让开发也懂前端
让开发也懂前端让开发也懂前端
让开发也懂前端
 
Geolinkeddata 07042011 1
Geolinkeddata 07042011 1Geolinkeddata 07042011 1
Geolinkeddata 07042011 1
 
GeoLinkedData
GeoLinkedDataGeoLinkedData
GeoLinkedData
 
Web Operations Career
Web Operations CareerWeb Operations Career
Web Operations Career
 
Javascript Basics - part 1
Javascript Basics - part 1Javascript Basics - part 1
Javascript Basics - part 1
 
Google kick ass-game_programming_with_gwt
Google   kick ass-game_programming_with_gwtGoogle   kick ass-game_programming_with_gwt
Google kick ass-game_programming_with_gwt
 
international PHP2011_ilia alshanetsky_Hidden Features of PHP
international PHP2011_ilia alshanetsky_Hidden Features of PHPinternational PHP2011_ilia alshanetsky_Hidden Features of PHP
international PHP2011_ilia alshanetsky_Hidden Features of PHP
 
잘 알려지지 않은 Php 코드 활용하기
잘 알려지지 않은 Php 코드 활용하기잘 알려지지 않은 Php 코드 활용하기
잘 알려지지 않은 Php 코드 활용하기
 
Javascript - How to avoid the bad parts
Javascript - How to avoid the bad partsJavascript - How to avoid the bad parts
Javascript - How to avoid the bad parts
 
Ruby hollywood
Ruby hollywoodRuby hollywood
Ruby hollywood
 
RunDeck
RunDeckRunDeck
RunDeck
 
Image and Music: Processing plus Pure Data with libpd library
Image and Music: Processing plus Pure Data with libpd libraryImage and Music: Processing plus Pure Data with libpd library
Image and Music: Processing plus Pure Data with libpd library
 

Dernier

Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 

Dernier (20)

How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu SubbuApidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
 

Ruby gvl-improvement at ruby 1.9.3

  • 1. Ruby 1.9.3 GVL Fujitsu Sunday, July 17, 2011
  • 2. Who am I? Sunday, July 17, 2011
  • 3. • IO OS • usa Sunday, July 17, 2011
  • 4. at Linux Kernel Summit 2010 Sunday, July 17, 2011
  • 5. Shyouhei commiter ranking me! Sunday, July 17, 2011
  • 9. What’s GVL • Global(or Giant) VM Lock • • multi thread issue Ruby script • CPU • Python Sunday, July 17, 2011
  • 10. What’s GVL (cont.) • GVL • GVL • OS Sunday, July 17, 2011
  • 11. f = false Thread.new { ....; f = true } Thread.pass until f Sunday, July 17, 2011
  • 12. GVL design • Lock wait (e.g. write) • lock, unlock Python, QEMU, Linux • GVL acquire/release pthread_mutex_{lock,unlock} Sunday, July 17, 2011
  • 13. GVL design (cont.) • • Sunday, July 17, 2011
  • 14. GVL design (cont.) • ON if (th->interrupt_flag) { gvl_release(); sched_yield(); gvl_acquire(); } Sunday, July 17, 2011
  • 15. OSS while (true) { ( ) lock(); if (hoge) { unlock(); break; • } unlock(); • thread lock rep_nop(); } hoge=1 lock(); hoge = 1; unlock(); Sunday, July 17, 2011
  • 17. CPU cpu1 cpu2 memory core core core core memory 1 2 core core core core Sunday, July 17, 2011
  • 18. if (th->interrupt_flag) { gvl_release(); sched_yield(); gvl_acquire(); } •gvl_release() gvl_acquire() sched_yield() • sched_yield() yield Sunday, July 17, 2011
  • 19. sched_yield • Unix API http://pubs.opengroup.org/onlinepubs/009695399/ functions/sched_yield.html int sched_yield(void); • The sched_yield() function shall force the running thread to relinquish the processor until it again becomes the head of its thread list. • Sunday, July 17, 2011
  • 20. Thread core Thread Thread Thread Thread core Thread core Sunday, July 17, 2011
  • 21. (ry CPU Thread core Thread Thread Thread core Thread Thread core Thread Sunday, July 17, 2011
  • 22. Yield! Ruby Thread core Thread Thread core Ruby Thread Sunday, July 17, 2011
  • 23. thread list head Thread core Ruby Thread Thread core Ruby Thread Sunday, July 17, 2011
  • 24. Ruby Thread core Thread Thread core Ruby Thread POSIX Sunday, July 17, 2011
  • 25. CFS yield • Linux RHEL5 RHEL6 • RHEL6 (CFS) sched_yield (RHEL5 knob • Java • Linux upstream knob CPU Sunday, July 17, 2011
  • 26. fairness Sunday, July 17, 2011
  • 27. fairness • GVL gvl_acquire gvl_release mutex_lock(&lock->lock) mutex_lock(&lock->lock) cond_wait(&lock->wait) lock->acquired = 0; lock->acquired = 1; cond_signal(&lock->wait_cond) // // cond_signal(&lock->switch_cond) cond_wait(&lock->switch_cond) mutex_unlock(&lock->lock) mutex_unlock(&lock->lock) Sunday, July 17, 2011
  • 28. vm_thread_pipe lmax = 100_000 r, w = IO.pipe [Thread.new{ lmax.times{ w.write('a') } p "w:exit" }, Thread.new{ lmax.times{ r.read(1) } p "r:exit" }].each{|t| t.join} Sunday, July 17, 2011
  • 29. ω ) Sunday, July 17, 2011
  • 30. • fairness • unfairness • Linux • Sunday, July 17, 2011
  • 31. 1.9.3 • 1.9.3 IO GVL release GVL release • IO GVL 1.9.2 IO GVL switch • GVL release switch GVL • Sunday, July 17, 2011
  • 32. 1.9.2 1.9.3 2 1.5 1 0.5 0 create_join mutex1 mutex2 mutex3 pass_flood pipe Sunday, July 17, 2011
  • 33. 1.9.2 • • • Sunday, July 17, 2011
  • 36. CPU • GVL CPU • Ruby Sunday, July 17, 2011

Notes de l'éditeur

  1. \n
  2. \n
  3. \n
  4. \n
  5. \n
  6. \n
  7. \n
  8. \n
  9. \n
  10. \n
  11. \n
  12. \n
  13. \n
  14. \n
  15. \n
  16. \n
  17. \n
  18. \n
  19. \n
  20. \n
  21. \n
  22. \n
  23. \n
  24. \n
  25. \n
  26. \n
  27. \n
  28. \n
  29. \n
  30. \n
  31. \n
  32. \n
  33. \n
  34. \n
  35. \n
  36. \n
  37. \n