PHP Getting Faster

73b0a25ed03f649ec63ded82ce4ac7cb?s=47 nunulk
October 12, 2019

PHP Getting Faster

73b0a25ed03f649ec63ded82ce4ac7cb?s=128

nunulk

October 12, 2019
Tweet

Transcript

  1. 3.

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

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

    New features • Typed Properties • Arrow Functions • Null

    coalescing assignment operator • Spread operator in arrays • Covariant Returns and Contravariant Parameters • Opcache Preloading • FFI
  3. 7.

    New features • Typed Properties • Arrow Functions • Null

    coalescing assignment operator • Spread operator in arrays • Covariant Returns and Contravariant Parameters • Opcache Preloading • FFI
  4. 9.

    Opcache Preloading // ϑϨʔϜϫʔΫͷ͢΂ͯͷϑΝΠϧΛΩϟογϡ͢Δ $frameworkDir = $baseDir . 'vendor/laravel/framework/ src/Illuminate';

    $paths = load_all_files([$frameworkDir]); foreach ($paths as $path) { opcache_compile_file($path);
 }
  5. 10.

    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. 11.

    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. 12.

    Opcache Preloading • Opcache.enable = 1 ͢Δ͚ͩͰे෼଎͘ͳΔ • αʔόΛ࠶ىಈ͠ͳ͍ͱΩϟογϡ͸ߋ৽͞Εͳ͍ͷͰɺ ӡ༻ͷࡍ͸஫ҙ͕ඞཁ

    • Composer Ͱ΋ಋೖ͕ݕ౼͞Ε͍ͯΔͷͰɺকདྷతʹ͸ preload͢Δର৅ͷબఆΛ composer ͔Βߦ͑ΔΑ͏ʹͳ Δ͔΋͠Εͳ͍
  8. 13.

    FFI - Foreign Function Interface • PHP ͔ΒωΠςΟϒϥΠϒϥϦ ʢ.so, .dylib,

    .dllʣΛݺͿ࢓૊Έ • Python, Ruby, Java ͳͲͰ͢Ͱʹ࠾༻͞Ε ͍ͯΔ
  9. 15.

    FFI <?php $libfib = FFI::cdef(' int fib(int a); ', ‘../nim/libfib.so');

    $ret = $libfib->fib(40); var_dump($ret); // int(102334155)
  10. 16.

    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. 17.

    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. 18.

    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. 19.

    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. 22.
  15. 23.

    Nim proc fib(a: cint): cint {.exportc, cdecl, dynlib.} = if

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