how badoo saved $1m switching to php7 - nikolay krapivnyy - phpday verona 2016
TRANSCRIPT
![Page 2: How Badoo Saved $1M Switching to PHP7 - Nikolay Krapivnyy - PHPDay Verona 2016](https://reader033.vdocuments.us/reader033/viewer/2022052312/587eebef1a28ab17388b6e8f/html5/thumbnails/2.jpg)
About me✦ Nikolay Krapivnyy
✦ 10+ years PHP experience
✦ 5 years with Badoo, now backend team lead
✦ This is my first talk in English :)
![Page 3: How Badoo Saved $1M Switching to PHP7 - Nikolay Krapivnyy - PHPDay Verona 2016](https://reader033.vdocuments.us/reader033/viewer/2022052312/587eebef1a28ab17388b6e8f/html5/thumbnails/3.jpg)
46languages
data
300Musers190
countries
“ BADOO IS THE LARGEST DATING NETWORK IN THE WORLD— Forbes
![Page 4: How Badoo Saved $1M Switching to PHP7 - Nikolay Krapivnyy - PHPDay Verona 2016](https://reader033.vdocuments.us/reader033/viewer/2022052312/587eebef1a28ab17388b6e8f/html5/thumbnails/4.jpg)
Badoo tech:
✦ 4 datacenters, ~3,000 servers overall
✦ up to 80,000 RPS for php backend
✦ ~200 engineers (~70 php devs)
✦ >2M PHP LoC
✦ and growing….
![Page 5: How Badoo Saved $1M Switching to PHP7 - Nikolay Krapivnyy - PHPDay Verona 2016](https://reader033.vdocuments.us/reader033/viewer/2022052312/587eebef1a28ab17388b6e8f/html5/thumbnails/5.jpg)
![Page 6: How Badoo Saved $1M Switching to PHP7 - Nikolay Krapivnyy - PHPDay Verona 2016](https://reader033.vdocuments.us/reader033/viewer/2022052312/587eebef1a28ab17388b6e8f/html5/thumbnails/6.jpg)
Today I will:✦ Share our practical experience
✦ Talk about some of our tools
✦ Tell you a million dollar story :)
![Page 7: How Badoo Saved $1M Switching to PHP7 - Nikolay Krapivnyy - PHPDay Verona 2016](https://reader033.vdocuments.us/reader033/viewer/2022052312/587eebef1a28ab17388b6e8f/html5/thumbnails/7.jpg)
1. Problem 2. Transition 3. Results
![Page 8: How Badoo Saved $1M Switching to PHP7 - Nikolay Krapivnyy - PHPDay Verona 2016](https://reader033.vdocuments.us/reader033/viewer/2022052312/587eebef1a28ab17388b6e8f/html5/thumbnails/8.jpg)
1. Problem
![Page 9: How Badoo Saved $1M Switching to PHP7 - Nikolay Krapivnyy - PHPDay Verona 2016](https://reader033.vdocuments.us/reader033/viewer/2022052312/587eebef1a28ab17388b6e8f/html5/thumbnails/9.jpg)
DBs
CLOUD SERVICES
LTM
How it works:APP
HTTPHTTP
API
API
![Page 10: How Badoo Saved $1M Switching to PHP7 - Nikolay Krapivnyy - PHPDay Verona 2016](https://reader033.vdocuments.us/reader033/viewer/2022052312/587eebef1a28ab17388b6e8f/html5/thumbnails/10.jpg)
9 %
15 %
22 %22 %
32 %phpmysqlotherphotosc/go
Hardware
![Page 11: How Badoo Saved $1M Switching to PHP7 - Nikolay Krapivnyy - PHPDay Verona 2016](https://reader033.vdocuments.us/reader033/viewer/2022052312/587eebef1a28ab17388b6e8f/html5/thumbnails/11.jpg)
32% or 1000of our servers are running php
![Page 12: How Badoo Saved $1M Switching to PHP7 - Nikolay Krapivnyy - PHPDay Verona 2016](https://reader033.vdocuments.us/reader033/viewer/2022052312/587eebef1a28ab17388b6e8f/html5/thumbnails/12.jpg)
PHP Cluster Growth
0
125
250
375
500
Jan, 2014 Jul, 2014 Jan, 2015 Jul, 2015 Jan, 2016
servers in 1DC users
![Page 13: How Badoo Saved $1M Switching to PHP7 - Nikolay Krapivnyy - PHPDay Verona 2016](https://reader033.vdocuments.us/reader033/viewer/2022052312/587eebef1a28ab17388b6e8f/html5/thumbnails/13.jpg)
CPU is the main bottleneck for us
![Page 14: How Badoo Saved $1M Switching to PHP7 - Nikolay Krapivnyy - PHPDay Verona 2016](https://reader033.vdocuments.us/reader033/viewer/2022052312/587eebef1a28ab17388b6e8f/html5/thumbnails/14.jpg)
How do we measure php performance?
![Page 15: How Badoo Saved $1M Switching to PHP7 - Nikolay Krapivnyy - PHPDay Verona 2016](https://reader033.vdocuments.us/reader033/viewer/2022052312/587eebef1a28ab17388b6e8f/html5/thumbnails/15.jpg)
Pinba!✦ Php is not a bottleneck anymore
✦ RT performance monitoring tool
✦ Extension for php + plugin for mysql
✦ Open source! http://pinba.org/
![Page 16: How Badoo Saved $1M Switching to PHP7 - Nikolay Krapivnyy - PHPDay Verona 2016](https://reader033.vdocuments.us/reader033/viewer/2022052312/587eebef1a28ab17388b6e8f/html5/thumbnails/16.jpg)
Request time
✦ Some API call: GET_USER
✦ avg request time = 0.12 sec
✦ request time = cpu time + i/o time
✦ i/o time = mysql + services + FS i/o +…
![Page 17: How Badoo Saved $1M Switching to PHP7 - Nikolay Krapivnyy - PHPDay Verona 2016](https://reader033.vdocuments.us/reader033/viewer/2022052312/587eebef1a28ab17388b6e8f/html5/thumbnails/17.jpg)
Pinba
Particular requests time
![Page 18: How Badoo Saved $1M Switching to PHP7 - Nikolay Krapivnyy - PHPDay Verona 2016](https://reader033.vdocuments.us/reader033/viewer/2022052312/587eebef1a28ab17388b6e8f/html5/thumbnails/18.jpg)
Pinba report
= +
![Page 19: How Badoo Saved $1M Switching to PHP7 - Nikolay Krapivnyy - PHPDay Verona 2016](https://reader033.vdocuments.us/reader033/viewer/2022052312/587eebef1a28ab17388b6e8f/html5/thumbnails/19.jpg)
Request time
✦ 0.12 sec = 0.07 (cpu) + 0.05 (i/o)
✦ 0.05 (i/o) = 0.012 + 0.05 + 0.03 + …
✦ 0.012 (memcache) = ~26*0.0005
✦ Realtime!
![Page 20: How Badoo Saved $1M Switching to PHP7 - Nikolay Krapivnyy - PHPDay Verona 2016](https://reader033.vdocuments.us/reader033/viewer/2022052312/587eebef1a28ab17388b6e8f/html5/thumbnails/20.jpg)
CPU usage takes ~50% of our request time
![Page 21: How Badoo Saved $1M Switching to PHP7 - Nikolay Krapivnyy - PHPDay Verona 2016](https://reader033.vdocuments.us/reader033/viewer/2022052312/587eebef1a28ab17388b6e8f/html5/thumbnails/21.jpg)
PHP7 alternatives?✦ HHVM (Facebook, http://hhvm.com/)
✦ kPHP (VK.com, https://github.com/vk-com/kphp-kdb)
+ JIT, PHP5 compatible— C++, extensions API
+ faster then HHVM
— no OOP support at all
![Page 22: How Badoo Saved $1M Switching to PHP7 - Nikolay Krapivnyy - PHPDay Verona 2016](https://reader033.vdocuments.us/reader033/viewer/2022052312/587eebef1a28ab17388b6e8f/html5/thumbnails/22.jpg)
2. Transition
![Page 23: How Badoo Saved $1M Switching to PHP7 - Nikolay Krapivnyy - PHPDay Verona 2016](https://reader033.vdocuments.us/reader033/viewer/2022052312/587eebef1a28ab17388b6e8f/html5/thumbnails/23.jpg)
Platform team:✦ C developers
✦ Php developers
✦ Badoo infrastructure support
![Page 24: How Badoo Saved $1M Switching to PHP7 - Nikolay Krapivnyy - PHPDay Verona 2016](https://reader033.vdocuments.us/reader033/viewer/2022052312/587eebef1a28ab17388b6e8f/html5/thumbnails/24.jpg)
Transition steps:2.1. Extensions
2.2. Codebase
2.3. Deploy
![Page 25: How Badoo Saved $1M Switching to PHP7 - Nikolay Krapivnyy - PHPDay Verona 2016](https://reader033.vdocuments.us/reader033/viewer/2022052312/587eebef1a28ab17388b6e8f/html5/thumbnails/25.jpg)
PHP7: extensions
xdebug
apcu
lua
imagick
✦ ~30 of them
✦ Already supported:
![Page 26: How Badoo Saved $1M Switching to PHP7 - Nikolay Krapivnyy - PHPDay Verona 2016](https://reader033.vdocuments.us/reader033/viewer/2022052312/587eebef1a28ab17388b6e8f/html5/thumbnails/26.jpg)
PHP7: extensions
blitz
xhprof
handlersocketi
pinba
leptonica
tarantool
sphinx
memtrack
judy
&& 15 more…
![Page 27: How Badoo Saved $1M Switching to PHP7 - Nikolay Krapivnyy - PHPDay Verona 2016](https://reader033.vdocuments.us/reader033/viewer/2022052312/587eebef1a28ab17388b6e8f/html5/thumbnails/27.jpg)
PHP7: extensions
https://github.com/tony2001
All php7 versions available:
Check for php7 branch
![Page 28: How Badoo Saved $1M Switching to PHP7 - Nikolay Krapivnyy - PHPDay Verona 2016](https://reader033.vdocuments.us/reader033/viewer/2022052312/587eebef1a28ab17388b6e8f/html5/thumbnails/28.jpg)
We thought we were done, but…
![Page 29: How Badoo Saved $1M Switching to PHP7 - Nikolay Krapivnyy - PHPDay Verona 2016](https://reader033.vdocuments.us/reader033/viewer/2022052312/587eebef1a28ab17388b6e8f/html5/thumbnails/29.jpg)
Runkit
![Page 30: How Badoo Saved $1M Switching to PHP7 - Nikolay Krapivnyy - PHPDay Verona 2016](https://reader033.vdocuments.us/reader033/viewer/2022052312/587eebef1a28ab17388b6e8f/html5/thumbnails/30.jpg)
What is runkit?
✦ runkit_method_add/redefine
✦ runkit_constant_add/redefine
✦ in runtime
✦ but why?
![Page 31: How Badoo Saved $1M Switching to PHP7 - Nikolay Krapivnyy - PHPDay Verona 2016](https://reader033.vdocuments.us/reader033/viewer/2022052312/587eebef1a28ab17388b6e8f/html5/thumbnails/31.jpg)
Unit testing!but why?
![Page 32: How Badoo Saved $1M Switching to PHP7 - Nikolay Krapivnyy - PHPDay Verona 2016](https://reader033.vdocuments.us/reader033/viewer/2022052312/587eebef1a28ab17388b6e8f/html5/thumbnails/32.jpg)
Unit testing:✦ 60K Tests now
✦ Coverage >50%
✦ Introduced only a few years ago
✦ Runkit: to isolate old code
![Page 33: How Badoo Saved $1M Switching to PHP7 - Nikolay Krapivnyy - PHPDay Verona 2016](https://reader033.vdocuments.us/reader033/viewer/2022052312/587eebef1a28ab17388b6e8f/html5/thumbnails/33.jpg)
Runkit: summary✦ essential for us
✦ no support for php7
![Page 34: How Badoo Saved $1M Switching to PHP7 - Nikolay Krapivnyy - PHPDay Verona 2016](https://reader033.vdocuments.us/reader033/viewer/2022052312/587eebef1a28ab17388b6e8f/html5/thumbnails/34.jpg)
Runkit for php7?✦ It`s different
✦ Alternatives? • UOPZ (https://github.com/krakjoe/uopz)
✦ Lots of changes anyway
![Page 35: How Badoo Saved $1M Switching to PHP7 - Nikolay Krapivnyy - PHPDay Verona 2016](https://reader033.vdocuments.us/reader033/viewer/2022052312/587eebef1a28ab17388b6e8f/html5/thumbnails/35.jpg)
Let`s remove this dependency
![Page 36: How Badoo Saved $1M Switching to PHP7 - Nikolay Krapivnyy - PHPDay Verona 2016](https://reader033.vdocuments.us/reader033/viewer/2022052312/587eebef1a28ab17388b6e8f/html5/thumbnails/36.jpg)
Soft mocks!✦ Soft means no extension
✦ Plain PHP, compatible with all PHP
✦ Replaces Runkit for us
✦ Open source! (https://github.com/badoo/soft-mocks)
![Page 37: How Badoo Saved $1M Switching to PHP7 - Nikolay Krapivnyy - PHPDay Verona 2016](https://reader033.vdocuments.us/reader033/viewer/2022052312/587eebef1a28ab17388b6e8f/html5/thumbnails/37.jpg)
How it works:✦ Rewrites code on the fly
✦ Inserts "interceptors" in methods
✦ Wraps all constant usages
✦ Uses PHP-Parser
![Page 38: How Badoo Saved $1M Switching to PHP7 - Nikolay Krapivnyy - PHPDay Verona 2016](https://reader033.vdocuments.us/reader033/viewer/2022052312/587eebef1a28ab17388b6e8f/html5/thumbnails/38.jpg)
1 require_once(__DIR__ . '/path.inc');2 ini_set(‘pinba.enabled', 1);3 echo RRD_BASE_PATH;
1 require_once SoftMocks::rewrite( ROOT_PATH . '/path' . '/path.inc' );2 SoftMocks::call( 'ini_set', array('pinba.enabled', 1’) );3 echo SoftMocks::getConst(‘RRD_BASE_PATH');
Original
After SoftMocks::rewrite()
![Page 39: How Badoo Saved $1M Switching to PHP7 - Nikolay Krapivnyy - PHPDay Verona 2016](https://reader033.vdocuments.us/reader033/viewer/2022052312/587eebef1a28ab17388b6e8f/html5/thumbnails/39.jpg)
1 class A2 {3 public function getValue()4 {5 return 10;6 }7 }
1 class A2 {3 public function getValue()4 { if (SoftMocks::isMocked(A::class, __FUNCTION__)) { return SoftMocks::getResult(…); }
5 return 10;6 }7 }
Original
After SoftMocks::rewrite()
![Page 40: How Badoo Saved $1M Switching to PHP7 - Nikolay Krapivnyy - PHPDay Verona 2016](https://reader033.vdocuments.us/reader033/viewer/2022052312/587eebef1a28ab17388b6e8f/html5/thumbnails/40.jpg)
So…
✦ No extension dependency
✦ 1.5 weeks for development
✦ A bit longer to adapt tests
✦ More stable tests in general
![Page 41: How Badoo Saved $1M Switching to PHP7 - Nikolay Krapivnyy - PHPDay Verona 2016](https://reader033.vdocuments.us/reader033/viewer/2022052312/587eebef1a28ab17388b6e8f/html5/thumbnails/41.jpg)
https://github.com/YuriyNasretdinov
CreditsMore cool stuff:
Soft mocks:
https://github.com/badoo/soft-mocks
![Page 42: How Badoo Saved $1M Switching to PHP7 - Nikolay Krapivnyy - PHPDay Verona 2016](https://reader033.vdocuments.us/reader033/viewer/2022052312/587eebef1a28ab17388b6e8f/html5/thumbnails/42.jpg)
2.2. Codebase
![Page 43: How Badoo Saved $1M Switching to PHP7 - Nikolay Krapivnyy - PHPDay Verona 2016](https://reader033.vdocuments.us/reader033/viewer/2022052312/587eebef1a28ab17388b6e8f/html5/thumbnails/43.jpg)
php7mar
✦ https://github.com/Alexia/php7mar
✦ Migration Assistant Report
![Page 44: How Badoo Saved $1M Switching to PHP7 - Nikolay Krapivnyy - PHPDay Verona 2016](https://reader033.vdocuments.us/reader033/viewer/2022052312/587eebef1a28ab17388b6e8f/html5/thumbnails/44.jpg)
php7mar 469 * foreachByReference 230 * oldClassConstructors 156 * funcGetArg 22 * hexadecimalString 19 * variableInterpolation 14 * yield 7 * deprecatedFunctions 4 * reservedNames 3 * arrayValueByReference
![Page 45: How Badoo Saved $1M Switching to PHP7 - Nikolay Krapivnyy - PHPDay Verona 2016](https://reader033.vdocuments.us/reader033/viewer/2022052312/587eebef1a28ab17388b6e8f/html5/thumbnails/45.jpg)
2.3. Deploy
![Page 46: How Badoo Saved $1M Switching to PHP7 - Nikolay Krapivnyy - PHPDay Verona 2016](https://reader033.vdocuments.us/reader033/viewer/2022052312/587eebef1a28ab17388b6e8f/html5/thumbnails/46.jpg)
Deploy✦ Devel: separate sandbox
✦ Staging
✦ Production
![Page 47: How Badoo Saved $1M Switching to PHP7 - Nikolay Krapivnyy - PHPDay Verona 2016](https://reader033.vdocuments.us/reader033/viewer/2022052312/587eebef1a28ab17388b6e8f/html5/thumbnails/47.jpg)
Deploy: production ✦ Several hosts in each cluster
✦ Several weeks of quarantine
✦ CLI: OK, WEB: ERROR
✦ WEB: fix for opcache reset in FPM
![Page 48: How Badoo Saved $1M Switching to PHP7 - Nikolay Krapivnyy - PHPDay Verona 2016](https://reader033.vdocuments.us/reader033/viewer/2022052312/587eebef1a28ab17388b6e8f/html5/thumbnails/48.jpg)
3. Results
![Page 49: How Badoo Saved $1M Switching to PHP7 - Nikolay Krapivnyy - PHPDay Verona 2016](https://reader033.vdocuments.us/reader033/viewer/2022052312/587eebef1a28ab17388b6e8f/html5/thumbnails/49.jpg)
CPU usage
![Page 50: How Badoo Saved $1M Switching to PHP7 - Nikolay Krapivnyy - PHPDay Verona 2016](https://reader033.vdocuments.us/reader033/viewer/2022052312/587eebef1a28ab17388b6e8f/html5/thumbnails/50.jpg)
cluster CPU usage
![Page 51: How Badoo Saved $1M Switching to PHP7 - Nikolay Krapivnyy - PHPDay Verona 2016](https://reader033.vdocuments.us/reader033/viewer/2022052312/587eebef1a28ab17388b6e8f/html5/thumbnails/51.jpg)
memory usage
![Page 52: How Badoo Saved $1M Switching to PHP7 - Nikolay Krapivnyy - PHPDay Verona 2016](https://reader033.vdocuments.us/reader033/viewer/2022052312/587eebef1a28ab17388b6e8f/html5/thumbnails/52.jpg)
We got: 2x CPU usage 9x memory usage
![Page 53: How Badoo Saved $1M Switching to PHP7 - Nikolay Krapivnyy - PHPDay Verona 2016](https://reader033.vdocuments.us/reader033/viewer/2022052312/587eebef1a28ab17388b6e8f/html5/thumbnails/53.jpg)
✦ 700 servers running FPM
✦ 1/2 required
✦ ~$4K each
✦ 350*4K = $1,4M
Let's calculate
![Page 54: How Badoo Saved $1M Switching to PHP7 - Nikolay Krapivnyy - PHPDay Verona 2016](https://reader033.vdocuments.us/reader033/viewer/2022052312/587eebef1a28ab17388b6e8f/html5/thumbnails/54.jpg)
![Page 55: How Badoo Saved $1M Switching to PHP7 - Nikolay Krapivnyy - PHPDay Verona 2016](https://reader033.vdocuments.us/reader033/viewer/2022052312/587eebef1a28ab17388b6e8f/html5/thumbnails/55.jpg)
Links✦ Pinba: http://pinba.org/
✦ Soft mocks: https://github.com/badoo/soft-mocks
✦ php7mar: https://github.com/Alexia/php7mar
✦ php7 exts: https://github.com/tony2001
![Page 56: How Badoo Saved $1M Switching to PHP7 - Nikolay Krapivnyy - PHPDay Verona 2016](https://reader033.vdocuments.us/reader033/viewer/2022052312/587eebef1a28ab17388b6e8f/html5/thumbnails/56.jpg)
Summary:✦ PHP7 rocks!
✦ Know your bottleneck
✦ Find your way
✦ Share!
![Page 57: How Badoo Saved $1M Switching to PHP7 - Nikolay Krapivnyy - PHPDay Verona 2016](https://reader033.vdocuments.us/reader033/viewer/2022052312/587eebef1a28ab17388b6e8f/html5/thumbnails/57.jpg)
Grazie!
![Page 58: How Badoo Saved $1M Switching to PHP7 - Nikolay Krapivnyy - PHPDay Verona 2016](https://reader033.vdocuments.us/reader033/viewer/2022052312/587eebef1a28ab17388b6e8f/html5/thumbnails/58.jpg)
Questions?
Twitter: @BadooTech
Blog: https://techblog.badoo.com
LinkedIn: https://linkedin.com/in/nkrapivnyy
Email: [email protected]
Joind.in: https://joind.in/talk/948d4