Ce diaporama a bien été signalé.
Nous utilisons votre profil LinkedIn et vos données d’activité pour vous proposer des publicités personnalisées et pertinentes. Vous pouvez changer vos préférences de publicités à tout moment.
Evented I/O based web servers,
   explained using bunnies
                 Simon Willison
    Part of a talk given at Full...
Your Web Server
 (using a bunny)
Your Web Server
                            (using a bunny)




                Single threaded (one bunny), so can only
 ...
Your Web Server
                                        (using a bunny)
       (The hamsters are using web
        browser...
Your Web Server
5 bunnies = can handle 5 requests at
           the same time                (using threads,
             ...
fetching a web API
                                           (2 seconds)

  Long running operations cause a
thread to blo...
fetching a web API
                         (2 seconds)


                     uploading an image
                        ...
Replace the bunnies with a single
 hyperactive squid. The squid runs up
and down as fast as it can dealing with
 each hams...
Bad code

• rows = database.fetch(category = 'news')
• template = read_file('homepage.html')
• json = fetch_url('http://......
Good code

• database.fetch(category = 'news', callback)
• read_file('homepage.html', callback)
• fetch_url('http://.../', ...
Prochain SlideShare
Chargement dans…5
×

67

Partager

Télécharger pour lire hors ligne

Evented I/O based web servers, explained using bunnies

Télécharger pour lire hors ligne

Part of a talk about Node.js given at Full Frontal 2009 in Brighton. I've added some additional explanatory notes.

Livres associés

Gratuit avec un essai de 30 jours de Scribd

Tout voir

Livres audio associés

Gratuit avec un essai de 30 jours de Scribd

Tout voir

Evented I/O based web servers, explained using bunnies

  1. 1. Evented I/O based web servers, explained using bunnies Simon Willison Part of a talk given at Full Frontal 2009
  2. 2. Your Web Server (using a bunny)
  3. 3. Your Web Server (using a bunny) Single threaded (one bunny), so can only handle one request at a time Happy hamster
  4. 4. Your Web Server (using a bunny) (The hamsters are using web browsers to visit your site) Impatient hamsters
  5. 5. Your Web Server 5 bunnies = can handle 5 requests at the same time (using threads, aka bunnies) Happy hamsters
  6. 6. fetching a web API (2 seconds) Long running operations cause a thread to block, causing requests to build up in a queue Your Web Server (using threads, aka bunnies)
  7. 7. fetching a web API (2 seconds) uploading an image (3 seconds) fetching a web API (2 seconds) fetching a web API (2 seconds) comet long polling (10 seconds) Impatient hamsters
  8. 8. Replace the bunnies with a single hyperactive squid. The squid runs up and down as fast as it can dealing with each hamster in turn. It fires off any Your Web Server long running I/O operations and then moves on to the next hamster. When (event loop, aka the I/O operation reports progress, it hyperactive squid) does a little more work on behalf of the corresponding hamster.
  9. 9. Bad code • rows = database.fetch(category = 'news') • template = read_file('homepage.html') • json = fetch_url('http://.../') These functions block and wait for results - blocking the squid and causing the entire event loop (and hence server) to pause until they complete
  10. 10. Good code • database.fetch(category = 'news', callback) • read_file('homepage.html', callback) • fetch_url('http://.../', callback) These functions specify a callback to be executed as soon as the I/O operation completes
  • guptaprateek21

    Sep. 5, 2016
  • hczcolin

    Apr. 17, 2016
  • SameerBarha

    Apr. 15, 2016
  • crownabhisek

    Jan. 21, 2016
  • seekdhananjay

    Sep. 3, 2015
  • leowang01

    Apr. 5, 2015
  • hoangvv

    Mar. 7, 2015
  • surajsharma121

    Jan. 20, 2015
  • JooHweeHUI

    Dec. 3, 2014
  • SyedRazaKhalid

    Jun. 26, 2014
  • keheliya

    Nov. 15, 2013
  • webknjaz

    Oct. 26, 2013
  • YoshiharuDewa

    Jul. 8, 2013
  • jogchandan

    Jun. 23, 2013
  • roycec

    Jun. 2, 2013
  • singhmp2k

    Mar. 7, 2013
  • satoryu

    Jan. 26, 2013
  • manojkumrm

    Aug. 1, 2012
  • PhaneendraHegde

    Jul. 4, 2012
  • RoystonS

    Mar. 12, 2012

Part of a talk about Node.js given at Full Frontal 2009 in Brighton. I've added some additional explanatory notes.

Vues

Nombre de vues

36 357

Sur Slideshare

0

À partir des intégrations

0

Nombre d'intégrations

1 632

Actions

Téléchargements

315

Partages

0

Commentaires

0

Mentions J'aime

67

×