Large-scale websites performance optimisation tricks @PHPUK2016

Large-scale websites performance optimisation tricks @PHPUK2016

Practical lessons learned while revamping a US airline website to resist huge Black Friday and Cyber Monday traffic values. Using HTTP status codes and PHP cleverly, we have made parallel requests possible, so that the user experience is greatly enhanced, and we pre-cache resource-consuming user searches. All on a solid Symfony2 foundation.

84cfe0e14cd3fdf8d1b2ef8223d99619?s=128

Georgiana Gligor

February 18, 2016
Tweet

Transcript

  1. 1.

    AIRLINE CASE STUDY LARGE-SCALE WEBSITES PHP UK | February 2016

    @gbtekkie PERFORMANCE OPTIMISATION TRICKS
  2. 2.

    @gbtekkie PHP UK | February 2016 Georgiana Gligor ✓ Geek.

    Mother. Do-er. ✓ Crafting enterprise-level applications in PHP since 2003 ✓ Architecture and DevOps consultant ✓ PHP Cluj Meetup Organizer
  3. 3.

    @gbtekkie PHP UK | February 2016 Customer ✓ low cost

    airline, similar to Ryan Air / Wizzair / EasyJet
  4. 4.

    @gbtekkie PHP UK | February 2016 ✓ low cost airline,

    similar to Ryan Air / Wizzair / EasyJet ✓ clever strategy of using airports, so that they don’t have a direct competition on 90% of their routes Customer Customer
  5. 5.

    @gbtekkie PHP UK | February 2016 ✓ low cost airline,

    similar to Ryan Air / Wizzair / EasyJet ✓ clever strategy of using airports, so that they don’t have a direct competition on 90% of their routes ✓ use their own reservation system (no GDS) Customer Customer
  6. 6.

    @gbtekkie PHP UK | February 2016 ✓ low cost airline,

    similar to Ryan Air / Wizzair / EasyJet ✓ clever strategy of using airports, so that they don’t have a direct competition on 90% of their routes ✓ use their own reservation system (no GDS) ✓ selling models: website, call-centre Customer Customer
  7. 8.

    @gbtekkie PHP UK | February 2016 The wants Wanted ✓

    enable end-user to purchase a full travel experience based on the destination, not just cheap plane tickets ✓ flexibility ✓ scalability ✓ be in front of the competition by withstanding the Black Friday + Cyber Monday test ✓ move at the speed of a greenfield project even if the business is up and running
  8. 9.

    @gbtekkie PHP UK | February 2016 The needs ✓ polyglot

    technology stack - Java reservations engine - LAMP for the web-facing part ✓ handle geographically distributed teams - 10 timezones - round-the-clock development ✓ replace legacy monolithic app Constraints
  9. 10.

    @gbtekkie PHP UK | February 2016 The needs (1) booking

    path (2) online check-in (3) Cyber Monday preparation Milestones
  10. 17.

    @gbtekkie PHP UK | February 2016 1 silo = full

    setup of servers that run each application component and deliver the end-to-end functionality ✓ frontend (Drupal, Javascript SPAs) ✓ backend (Symfony services) ✓ cache What is a silo
  11. 28.

    @gbtekkie PHP UK | February 2016 ✓ enforces discussing contracts

    before doing actual coding ✓ helps eliminate certain problems by having them discussed in advance ✓ allows developers to work independently and run all the stack on their machine ✓ each component is independently tested Fixture-based development
  12. 30.

    @gbtekkie PHP UK | February 2016 ✓ HTTP status code

    204 ✓ success code ✓ Content-Length: 0 ✓ the backend acknowledges the request and will carry on ✓ the client can continue processing The 204 trick
  13. 32.

    @gbtekkie PHP UK | February 2016 POST /batch-process public function

    batchProcessAction() { } Batch processing example
  14. 33.

    @gbtekkie PHP UK | February 2016 POST /batch-process public function

    batchProcessAction() { // 1 - check permissions } Batch processing example
  15. 34.

    @gbtekkie PHP UK | February 2016 POST /batch-process public function

    batchProcessAction() { // 1 - check permissions // 2 - validate user data } Batch processing example
  16. 35.

    @gbtekkie PHP UK | February 2016 POST /batch-process public function

    batchProcessAction() { // 1 - check permissions // 2 - validate user data // 3 - return 204 No Content } Batch processing example
  17. 36.

    @gbtekkie PHP UK | February 2016 POST /batch-process public function

    batchProcessAction() { // 1 - check permissions // 2 - validate user data // 3 - return 204 No Content // 4 - process batch } Batch processing example
  18. 37.

    @gbtekkie PHP UK | February 2016 Close connection: raw PHP

    public function closeConnection() { header('HTTP/1.0 204 No Content'); header('Content-Length: 0', true); header('Content-Type: application/json', true); flush(); // or ob_flush() }
  19. 38.

    @gbtekkie PHP UK | February 2016 Close connection: Symfony-specific public

    function closeConnection(Request $request) { $response = new StreamedResponse(); $response->setStatusCode(204); $response->headers->add(array('Connection' => 'close')); $c = function () { /* do nothing */ }; $response->setCallback($c); // needs to be a valid PHP callable $response->prepare($request); // ensure compliancy with HTTP specification $response->send(); return $response; }
  20. 39.

    @gbtekkie PHP UK | February 2016 ✓ cheap ✓ does

    not impact application performance ✓ logs are searchable ✓ logs tell the story of a user’s journey ✓ greatly help debugging Event logging system
  21. 44.

    @gbtekkie PHP UK | February 2016 ✓ recoverable user can

    continue inside the booking path ✓ non-recoverable user’s checkin process can’t proceed Error types
  22. 45.

    @gbtekkie PHP UK | February 2016 4xx status codes ✓

    401 unauthorised ✓ 403 forbidden ✓ 409 conflict ✓ 413 payload too large instruct the UI where to go back Recoverable errors
  23. 46.

    @gbtekkie PHP UK | February 2016 ✓ 5xx status codes

    ✓ 500 internal server error ✓ 503 service unavailable Non-recoverable errors
  24. 48.

    @gbtekkie PHP UK | February 2016 ✓ asynchronously process multiple

    cURL handles ✓ same good old cURL, but on steroids ✓ curl_multi Parallel PHP
  25. 54.

    @gbtekkie PHP UK | February 2016 ✓ silos ✓ static

    data ✓ fixtures Lessons learned
  26. 55.

    @gbtekkie PHP UK | February 2016 ✓ silos ✓ static

    data ✓ fixtures ✓ delegate responsibility Lessons learned
  27. 56.

    @gbtekkie PHP UK | February 2016 ✓ silos ✓ static

    data ✓ fixtures ✓ delegate responsibility ✓ parallelism Lessons learned