Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Large-scale websites performance optimisation t...

Large-scale websites performance optimisation tricks. Airline case study.

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.

Georgiana Gligor

November 15, 2015
Tweet

More Decks by Georgiana Gligor

Other Decks in Technology

Transcript

  1. Large scale websites performance optimisation tricks GEORGIANA GLIGOR ▸ Geek.

    Mother. Do-er. ▸ Crafting enterprise-level applications with PHP since 2003 ▸ architecture and devops consultant ▸ Symfony & Reactjs consultant ▸ PHP Cluj Meetup Organizer
  2. Large scale websites performance optimisation tricks CUSTOMER ▸ low cost

    airline, similar to Ryan Air / Wizzair / EasyJet
  3. Large scale websites performance optimisation tricks CUSTOMER ▸ 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
  4. Large scale websites performance optimisation tricks CUSTOMER ▸ 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 ▸ selling models: website, call-centre, travel agents
  5. Large scale websites performance optimisation tricks CUSTOMER ▸ 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 ▸ selling models: website, call-centre, travel agents ▸ use their own reservation system
  6. Large scale websites performance optimisation tricks THE WANTS ‣ enables

    customer to purchase a full 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
  7. Large scale websites performance optimisation tricks THE NEEDS ‣ introduce

    polyglot technology stack ‣ handle geographically distributed teams ‣ replace legacy monolithic app
  8. Large scale websites performance optimisation tricks WELCOME SILOS 1 silo

    = full setup of servers that run each application component ‣ frontend (Drupal, Javascript SPAs) ‣ backend (Symfony services) ‣ cache
  9. Large scale websites performance optimisation tricks FIXTURE-BASED DEVELOPMENT ‣ 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
  10. Large scale websites performance optimisation tricks ‣ HTTP status code

    204 ‣ success code ‣ Content-Length: 0 ‣ the backend acknowledges the request and will carry on ‣ the client can continue processing
  11. Large scale websites performance optimisation tricks BATCH PROCESSING EXAMPLE POST

    /batch-process public function batchProcessAction() { }
  12. Large scale websites performance optimisation tricks BATCH PROCESSING EXAMPLE POST

    /batch-process public function batchProcessAction() { // 1 - check permissions }
  13. Large scale websites performance optimisation tricks BATCH PROCESSING EXAMPLE POST

    /batch-process public function batchProcessAction() { // 1 - check permissions // 2 - validate user data }
  14. Large scale websites performance optimisation tricks BATCH PROCESSING EXAMPLE POST

    /batch-process public function batchProcessAction() { // 1 - check permissions // 2 - validate user data // 3 - return 204 No Content }
  15. Large scale websites performance optimisation tricks BATCH PROCESSING EXAMPLE POST

    /batch-process public function batchProcessAction() { // 1 - check permissions // 2 - validate user data // 3 - return 204 No Content // 4 - process batch }
  16. Large scale websites performance optimisation tricks 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() }
  17. Large scale websites performance optimisation tricks 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; }
  18. Large scale websites performance optimisation tricks BLACKBOX: EVENT LOGGING SYSTEM

    ‣ cheap ‣ does not impact application performance ‣ logs are searchable ‣ logs tell the story of a user’s journey ‣ greatly help debugging
  19. Large scale websites performance optimisation tricks ERROR TYPES ‣ recoverable

    ‣ user can continue inside the booking path ‣ non-recoverable ‣ user’s checkin process can’t proceed
  20. Large scale websites performance optimisation tricks RECOVERABLE ERRORS ‣ 4xx

    status codes ‣ 401 unauthorised ‣ 403 forbidden ‣ 409 conflict ‣ 413 payload too large ‣ instruct the UI where to go back
  21. Large scale websites performance optimisation tricks NON-RECOVERABLE ERRORS ‣ 5xx

    status codes ‣ 500 internal server error ‣ 503 service unavailable
  22. Large scale websites performance optimisation tricks ‣ asynchronously process multiple

    cURL handles ‣ same good old cURL, but on steroids ‣ http://php.net/manual/en/function.curl-multi- init.php#refsect1-function.curl-multi-init-examples
  23. Large scale websites performance optimisation tricks ‣ silos ‣ static

    data ‣ fixtures ‣ delegate responsibility
  24. Large scale websites performance optimisation tricks ‣ silos ‣ static

    data ‣ fixtures ‣ delegate responsibility ‣ parallelism