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. AIRLINE CASE STUDY LARGE-SCALE WEBSITES PHP UK | February 2016

    @gbtekkie PERFORMANCE OPTIMISATION TRICKS
  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. @gbtekkie PHP UK | February 2016 Customer ✓ low cost

    airline, similar to Ryan Air / Wizzair / EasyJet
  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. @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. @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. @gbtekkie PHP UK | February 2016 Legacy

  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
  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
  10. @gbtekkie PHP UK | February 2016 The needs (1) booking

    path (2) online check-in (3) Cyber Monday preparation Milestones
  11. @gbtekkie PHP UK | February 2016 TECHNOLOGY STACK

  12. @gbtekkie PHP UK | February 2016 Legacy as data

  13. @gbtekkie PHP UK | February 2016 RESTful services access data

    transactional
  14. @gbtekkie PHP UK | February 2016 Isolate high traffic

  15. @gbtekkie PHP UK | February 2016 Web-facing components

  16. @gbtekkie PHP UK | February 2016 WELCOME SILOS

  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
  18. @gbtekkie PHP UK | February 2016 Silo diagram

  19. @gbtekkie PHP UK | February 2016 STATIC DATA

  20. @gbtekkie PHP UK | February 2016 Static data

  21. @gbtekkie PHP UK | February 2016 Optimise access to static

    data
  22. @gbtekkie PHP UK | February 2016 ANATOMY OF A SILO

  23. @gbtekkie PHP UK | February 2016 The pieces

  24. @gbtekkie PHP UK | February 2016 Data access

  25. @gbtekkie PHP UK | February 2016 Data caching

  26. @gbtekkie PHP UK | February 2016 FIXTURES

  27. @gbtekkie PHP UK | February 2016 Fixtures

  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
  29. @gbtekkie PHP UK | February 2016 THE 204 TRICK

  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
  31. @gbtekkie PHP UK | February 2016 204 trick in action

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

    batchProcessAction() { } Batch processing example
  33. @gbtekkie PHP UK | February 2016 POST /batch-process public function

    batchProcessAction() { // 1 - check permissions } Batch processing example
  34. @gbtekkie PHP UK | February 2016 POST /batch-process public function

    batchProcessAction() { // 1 - check permissions // 2 - validate user data } Batch processing example
  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
  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
  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() }
  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; }
  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
  40. @gbtekkie PHP UK | February 2016 Event logging system

  41. @gbtekkie PHP UK | February 2016 Event logging system

  42. @gbtekkie PHP UK | February 2016 Event logging system

  43. @gbtekkie PHP UK | February 2016 ERROR HANDLING

  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
  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
  46. @gbtekkie PHP UK | February 2016 ✓ 5xx status codes

    ✓ 500 internal server error ✓ 503 service unavailable Non-recoverable errors
  47. @gbtekkie PHP UK | February 2016 PARALLELISM

  48. @gbtekkie PHP UK | February 2016 ✓ asynchronously process multiple

    cURL handles ✓ same good old cURL, but on steroids ✓ curl_multi Parallel PHP
  49. @gbtekkie PHP UK | February 2016 Parallelism in practice

  50. @gbtekkie PHP UK | February 2016 Anatomy of a Symfony

    service
  51. @gbtekkie PHP UK | February 2016 LESSONS LEARNED

  52. @gbtekkie PHP UK | February 2016 ✓ silos Lessons learned

  53. @gbtekkie PHP UK | February 2016 ✓ silos ✓ static

    data Lessons learned
  54. @gbtekkie PHP UK | February 2016 ✓ silos ✓ static

    data ✓ fixtures Lessons learned
  55. @gbtekkie PHP UK | February 2016 ✓ silos ✓ static

    data ✓ fixtures ✓ delegate responsibility Lessons learned
  56. @gbtekkie PHP UK | February 2016 ✓ silos ✓ static

    data ✓ fixtures ✓ delegate responsibility ✓ parallelism Lessons learned
  57. @gbtekkie PHP UK | February 2016 Q & A

  58. THANK YOU! Georgiana Gligor @gbtekkie https://joind.in/talk/95a6e