Building the perfect PHP app for the enterprise
Episode 2 : Developing apps fasterMaurice KherlakianTwitter: @mkherlakianEmail: [email protected]
2
Series overviewNow: Developing apps faster
September 28: Resolving problems and high availabilityYour reputation as a miracle worker is secure when using these principles to isolate faults, optimize scale, and synchronize sessions across clusters.
October 12: Optimizing performanceKeep users on your site by learning how to use background jobs and caching, measure performance, and make data-driven decisions.
Maurice KherlakianDirector of professional servicesRogue Wave Software
4
Enterprise PHP is mission-critical
• Built securely• Delivers optimal performance + scale• Always on• Meets release timelines• Modernizes legacy business logic• Clear support path (production + LTS)
5
What does deployment automation look like?• Amazon – 1 deployments/second
- Werner Vogels. CTO Amazon
• Etsy – 40 – 50 deployments/day
• Netflix – highly automated deployments and testing (Simian Army)techblog.netflix.com/2016/03/how-we-build-code-at-netflix.htmltechblog.netflix.com/2013/08/deploying-netflix-api.htmlquora.com/How-fast-is-Netflixs-development-cycle-in-practice
Poll #1:At what frequency do you deploy? • Multiple times a day• Once a day• Once a week• Once a quarter• Once a year
7
Faster deployment
cycles
Faster application developme
nt=
8
Faster deployment cycles benefits
• Faster feedback from your end users
• Faster development• More iterations• Better product overall
Faster deployment
cycles
Faster application
development=
9
The traditional approach
Requirements
Design
Implementation
Verification
Maintenance
10
WaterGile anyone?• Teams within an organization subscribing to Agile methodology• Teams often isolated – entire company didn’t buy into Agile
methodologies• Still gather requirements, but break the down into user stories
Poll #2:What development practice do you follow?• Waterfall principles• A combination f waterfall and Agile
(WaterGile – AgileFall)• Mainly Agile principles
12
You are always behind!
• Technical debt keeps increasing
13
Faster deployment
cycles
Faster application developme
nt=
Feedback loop and monitoring
15
You’ve just released a feature
Add a map display of all available cars to rent in a 10 km radius Released to
everyone
Impact?
Overload – servers down, root cause
unknown
PANIC!
16
You’ve just released a feature to some users
Add a map display of all available cars to rent in a 10 km radius Released to 20% of
users
Impact – compare with other 80%
through app monitoring system
Change in CPU consumption profiles for same amount of
users
Fix or turn feature off
17
Tools that can help• Instrument your code
– PHP feature toggle (qandidate-toggle - ) – release to a subset of users
• Zend Server Monitoring – a complete solution to monitor the behavior of your application – so you will catch the 20% spike in CPU usage
18
It’s working… ramp it up!
Add a map display of all available cars to rent in a 10 km radius Released to 50% of
users
10% more rentals per visitor on version with
map
Little to no change in performance
Release to everyone
Release automation
20
It worked fine on dev!• Environment consistency
21
Git
Developer’s code for map
featureCheck in
PackagePackaged app (parametrized
)
Staging
TEST
Prod
Rollback
Packaging for release
22
Tools that can help• VMs and consistency
– Vagrant– Docker
• Deployment– Zend Server (deployment)– AWS code deploy
Continuous integration
24
What is a CI server?• CI automates the various tasks of building,
packaging, testing and deploying
• If build breaks, up to developer that broke it to fix it
• If build passes, it CAN go all the way to production
25
A typical CI pipeline
Git clone Composer install Unit test Package
Deploy to test
Functional test
Deploy to Staging
Deploy to prod
Add a map display of all available cars to rent in a 10 km radius
26
Failure!
Git clone Composer install Unit test
FAIL Build 783 failed
Add a map display of all available cars to rent in a 10 km radius
27
Tools that can help
Poll #3:Do you use a CI server?• Yes• No
Demo
Testing automation
31
Testing at different stages• Unit testing
• Functional testing
• Integration testing
• Load testing
Reference: techblog.netflix.com/search/label/Integration%20Testing
32
Cost of bug fixing
Stefan Priebsch – Advanced OOP and design patternsCredit: Stefan Priebsch
33
Test early, test often!
34
Add a map display of all available cars to rent in a 10 km radius
Simulate a browser request and ensure that a map loads, and that the map has the number of vehicles available for rent
Functional
getCars($criteria, $radius)
$map->plotCoordinates($cars)
$modelView->assign(‘map’, $map)
Unit
Load 1,000 concurrent search requests for cars from 1000 different locations
Load
Poll #4:Do you unit test?• Yes• No
36
Tools that can help• ab, Jmeter, LoadRunner• PHPUnit• Behat – Mink• PHPspec
Frameworks/libraries
Poll #5:Do you use a framework?• Yes• No
39
Evolution of frameworks• Component frameworks
• MVC out, middleware in
• Microservices architecture
40
Tools that can helpSo many…
• Zend Framework: ZF3, Expressive, Apigility
• Laravel, Symfony, Yii, and many more
Writing code and left shifting
42
Catch bugs early• Remember how a bug in prod can cost as much as 15X times the
cost of a bug in development?
43
How do you catch bugs early?
• Test early, test often – when developing, test locally before committing
• Peer reviews
• Code instrumentation tools
What about hardware and infrastructure?
46
Infrastructure should also be automated• Automate server provisioning
• Source control your environment configurations
• The goal is to fully rebuild an environment automatically in case of failure
47
Another example – dealnews.com• In the past 2 weeks
– Deployed web application 64 times – average 6.5 times a day– Deployed configuration management changes 12 times– Deployed MySQL schema changes 13 times
- Courtesy of Brian Moon
Q&A
49
Learn more
• Watch this webinar on demand
• Read the recap blog to see the results of the polls and Q&A session
50
Stay tunedSeptember 28: Resolving problems and high availabilityYour reputation as a miracle worker is secure when using these principles to isolate faults, optimize scale, and synchronize sessions across clusters.
October 12: Optimizing performanceKeep users on your site by learning how to use background jobs and caching, measure performance, and make data-driven decisions.
Building the perfect PHP app for the enterprise
Episode 2 : Developing apps fasterMaurice KherlakianSeptember 14, 2016