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

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.

Georgiana Gligor

February 18, 2016
Tweet

More Decks by Georgiana Gligor

Other Decks in Technology

Transcript

  1. AIRLINE CASE STUDY
    LARGE-SCALE WEBSITES
    PHP UK | February 2016
    @gbtekkie
    PERFORMANCE OPTIMISATION TRICKS

    View full-size slide

  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

    View full-size slide

  3. @gbtekkie PHP UK | February 2016
    Customer
    ✓ low cost airline, similar to Ryan Air / Wizzair / EasyJet

    View full-size slide

  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

    View full-size slide

  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

    View full-size slide

  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

    View full-size slide

  7. @gbtekkie PHP UK | February 2016
    Legacy

    View full-size slide

  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

    View full-size slide

  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

    View full-size slide

  10. @gbtekkie PHP UK | February 2016
    The needs
    (1) booking path
    (2) online check-in
    (3) Cyber Monday preparation
    Milestones

    View full-size slide

  11. @gbtekkie PHP UK | February 2016
    TECHNOLOGY STACK

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  16. @gbtekkie PHP UK | February 2016
    WELCOME SILOS

    View full-size slide

  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

    View full-size slide

  18. @gbtekkie PHP UK | February 2016
    Silo diagram

    View full-size slide

  19. @gbtekkie PHP UK | February 2016
    STATIC DATA

    View full-size slide

  20. @gbtekkie PHP UK | February 2016
    Static data

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  23. @gbtekkie PHP UK | February 2016
    The pieces

    View full-size slide

  24. @gbtekkie PHP UK | February 2016
    Data access

    View full-size slide

  25. @gbtekkie PHP UK | February 2016
    Data caching

    View full-size slide

  26. @gbtekkie PHP UK | February 2016
    FIXTURES

    View full-size slide

  27. @gbtekkie PHP UK | February 2016
    Fixtures

    View full-size slide

  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

    View full-size slide

  29. @gbtekkie PHP UK | February 2016
    THE 204 TRICK

    View full-size slide

  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

    View full-size slide

  31. @gbtekkie PHP UK | February 2016
    204 trick in action

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  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

    View full-size slide

  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

    View full-size slide

  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()
    }

    View full-size slide

  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;
    }

    View full-size slide

  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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  43. @gbtekkie PHP UK | February 2016
    ERROR HANDLING

    View full-size slide

  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

    View full-size slide

  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

    View full-size slide

  46. @gbtekkie PHP UK | February 2016
    ✓ 5xx status codes
    ✓ 500 internal server error
    ✓ 503 service unavailable
    Non-recoverable errors

    View full-size slide

  47. @gbtekkie PHP UK | February 2016
    PARALLELISM

    View full-size slide

  48. @gbtekkie PHP UK | February 2016
    ✓ asynchronously process multiple cURL handles
    ✓ same good old cURL, but on steroids
    ✓ curl_multi
    Parallel PHP

    View full-size slide

  49. @gbtekkie PHP UK | February 2016
    Parallelism in practice

    View full-size slide

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

    View full-size slide

  51. @gbtekkie PHP UK | February 2016
    LESSONS LEARNED

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  57. @gbtekkie PHP UK | February 2016
    Q & A

    View full-size slide

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

    View full-size slide