Upgrade to Pro — share decks privately, control downloads, hide ads and more …

PHP Getting Faster

nunulk
October 12, 2019

PHP Getting Faster

nunulk

October 12, 2019
Tweet

More Decks by nunulk

Other Decks in Programming

Transcript

  1. ࣗݾ঺հ • ໊લ: nunulkʢ͵͵Δ͘ʣ • ৬ۀ: ϑϦʔϥϯεͷ΢ΣϒΤϯδχΞ • ਆಸ઒ݝ͔Βདྷ·ͨ͠ •

    PHPͷ޷͖ͳͱ͜Ζ: Մมؔ਺ɺϚδοΫϝιου • Laravel Meetup Okinawa ࢀՃ཰: ໿ 45%
  2. New features • Typed Properties • Arrow Functions • Null

    coalescing assignment operator • Spread operator in arrays • Covariant Returns and Contravariant Parameters • Opcache Preloading • FFI
  3. New features • Typed Properties • Arrow Functions • Null

    coalescing assignment operator • Spread operator in arrays • Covariant Returns and Contravariant Parameters • Opcache Preloading • FFI
  4. Opcache Preloading // ϑϨʔϜϫʔΫͷ͢΂ͯͷϑΝΠϧΛΩϟογϡ͢Δ $frameworkDir = $baseDir . 'vendor/laravel/framework/ src/Illuminate';

    $paths = load_all_files([$frameworkDir]); foreach ($paths as $path) { opcache_compile_file($path);
 }
  5. Opcache Preloading ab -n 100 -c 10 http://localhost Opcache ͳ͠

    Requests per second: 0.91 [#/sec] (mean) Time per request: 11010.544 [ms] (mean) Opcache ͋Γ Requests per second: 5.34 [#/sec] (mean) Time per request: 1872.084 [ms] (mean) Opcache ͋Γ w/ preload Requests per second: 6.32 [#/sec] (mean) Time per request: 1582.046 [ms] (mean)
  6. Opcache Preloading ab -n 100 -c 10 http://localhost Opcache ͳ͠

    Requests per second: 0.91 [#/sec] (mean) Time per request: 11010.544 [ms] (mean) Opcache ͋Γ Requests per second: 5.34 [#/sec] (mean) Time per request: 1872.084 [ms] (mean) Opcache ͋Γ w/ preload Requests per second: 6.32 [#/sec] (mean) Time per request: 1582.046 [ms] (mean)  
  7. Opcache Preloading • Opcache.enable = 1 ͢Δ͚ͩͰे෼଎͘ͳΔ • αʔόΛ࠶ىಈ͠ͳ͍ͱΩϟογϡ͸ߋ৽͞Εͳ͍ͷͰɺ ӡ༻ͷࡍ͸஫ҙ͕ඞཁ

    • Composer Ͱ΋ಋೖ͕ݕ౼͞Ε͍ͯΔͷͰɺকདྷతʹ͸ preload͢Δର৅ͷબఆΛ composer ͔Βߦ͑ΔΑ͏ʹͳ Δ͔΋͠Εͳ͍
  8. FFI - Foreign Function Interface • PHP ͔ΒωΠςΟϒϥΠϒϥϦ ʢ.so, .dylib,

    .dllʣΛݺͿ࢓૊Έ • Python, Ruby, Java ͳͲͰ͢Ͱʹ࠾༻͞Ε ͍ͯΔ
  9. FFI <?php $libfib = FFI::cdef(' int fib(int a); ', ‘../nim/libfib.so');

    $ret = $libfib->fib(40); var_dump($ret); // int(102334155)
  10. FFI // for/if Λ࢖ͬͯ N ·Ͱͷۮ਺ͷ࿨Λܭࢉ͢Δ
 # php index.php loop

    --php 1000000 0.056366920471191 
 # php index.php loop --ffi 1000000 0.037209987640381 
 // N ൪໨ͷϑΟϘφον਺Λ࠶ؼͰܭࢉ͢Δ # php index.php fib --php 40 4.6368939876556 # php index.php fib --ffi 40 0.28206396102905 // MySQL ʹ N ݅σʔλΛૠೖ͢Δ # php index.php mysql --php 1000 0.47904992103577 # php index.php mysql --ffi 1000 0.57981204986572
  11. FFI // for/if Λ࢖ͬͯ N ·Ͱͷۮ਺ͷ࿨Λܭࢉ͢Δ
 # php index.php loop

    --php 1000000 0.056366920471191 
 # php index.php loop --ffi 1000000 0.037209987640381 
 // N ൪໨ͷϑΟϘφον਺Λ࠶ؼͰܭࢉ͢Δ # php index.php fib --php 40 4.6368939876556 # php index.php fib --ffi 40 0.28206396102905 // MySQL ʹ N ݅σʔλΛૠೖ͢Δ # php index.php mysql --php 1000 0.47904992103577 # php index.php mysql --ffi 1000 0.57981204986572 
  12. FFI // for/if Λ࢖ͬͯ N ·Ͱͷۮ਺ͷ࿨Λܭࢉ͢Δ
 # php index.php loop

    --php 1000000 0.056366920471191 
 # php index.php loop --ffi 1000000 0.037209987640381 
 // N ൪໨ͷϑΟϘφον਺Λ࠶ؼͰܭࢉ͢Δ # php index.php fib --php 40 4.6368939876556 # php index.php fib --ffi 40 0.28206396102905 // MySQL ʹ N ݅σʔλΛૠೖ͢Δ # php index.php mysql --php 1000 0.47904992103577 # php index.php mysql --ffi 1000 0.57981204986572 
  13. FFI // for/if Λ࢖ͬͯ N ·Ͱͷۮ਺ͷ࿨Λܭࢉ͢Δ
 # php index.php loop

    --php 1000000 0.056366920471191 
 # php index.php loop --ffi 1000000 0.037209987640381 
 // N ൪໨ͷϑΟϘφον਺Λ࠶ؼͰܭࢉ͢Δ # php index.php fib --php 40 4.6368939876556 # php index.php fib --ffi 40 0.28206396102905 // MySQL ʹ N ݅σʔλΛૠೖ͢Δ # php index.php mysql --php 1000 0.47904992103577 # php index.php mysql --ffi 1000 0.57981204986572 
  14. Nim proc fib(a: cint): cint {.exportc, cdecl, dynlib.} = if

    a <= 2: result = 1 else: result = fib(a - 1) + fib(a - 2)