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

PHP Timisoara Meetup April 2016

PHP Timisoara Meetup April 2016

Trimmed-down version of the large-scale websites performance tricks presentation.

Georgiana Gligor

April 06, 2016
Tweet

More Decks by Georgiana Gligor

Other Decks in Technology

Transcript

  1. @gbtekkie PHP meetup Timisoara | April 2016 Georgiana Gligor ✓

    Geek. Mother. Do-er.  ✓ Crafting enterprise-level applications in PHP since 2003 ✓ Architecture and DevOps consultant ✓ PHP Cluj Meetup Organizer 2
  2. @gbtekkie PHP meetup Timisoara | April 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 3
  3. @gbtekkie PHP meetup Timisoara | April 2016 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 5
  4. @gbtekkie PHP meetup Timisoara | April 2016 ▸ 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 6
  5. @gbtekkie PHP meetup Timisoara | April 2016 (1) booking path

    (2) online check-in (3) Cyber Monday preparation Milestones 7
  6. @gbtekkie PHP meetup Timisoara | April 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 14
  7. @gbtekkie PHP meetup Timisoara | April 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 25
  8. @gbtekkie PHP meetup Timisoara | April 2016 ▸ asynchronously process

    multiple cURL handles ▸ same good old cURL, but on steroids ▸ curl_multi Parallel PHP 27
  9. @gbtekkie PHP meetup Timisoara | April 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
  10. @gbtekkie PHP meetup Timisoara | April 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 33
  11. @gbtekkie PHP meetup Timisoara | April 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() } 34
  12. @gbtekkie PHP meetup Timisoara | April 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; } 35
  13. @gbtekkie PHP meetup Timisoara | April 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 36
  14. @gbtekkie PHP meetup Timisoara | April 2016 ▸ recoverable user

    can continue inside the booking path ▸ non-recoverable user’s checkin process can’t proceed Error types 41
  15. @gbtekkie PHP meetup Timisoara | April 2016 4xx status codes

    ▸ 401 unauthorised ▸ 403 forbidden ▸ 409 conflict ▸ 413 payload too large instruct the UI where to go back Recoverable errors 42
  16. @gbtekkie PHP meetup Timisoara | April 2016 ▸ 5xx status

    codes ▸ 500 internal server error ▸ 503 service unavailable Non-recoverable errors 43
  17. @gbtekkie PHP meetup Timisoara | April 2016 ▸ silos ▸

    static data ▸ fixtures Lessons learned 47
  18. @gbtekkie PHP meetup Timisoara | April 2016 ▸ silos ▸

    static data ▸ fixtures ▸ delegate responsibility Lessons learned 48
  19. @gbtekkie PHP meetup Timisoara | April 2016 ▸ silos ▸

    static data ▸ fixtures ▸ delegate responsibility ▸ parallelism Lessons learned 49