Evented I/O based web servers, explained using bunnies
Upcoming SlideShare
Loading in...5
×

Like this? Share it with your network

Share

Evented I/O based web servers, explained using bunnies

  • 36,272 views
Uploaded on

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

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

More in: Technology , Business
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
No Downloads

Views

Total Views
36,272
On Slideshare
34,675
From Embeds
1,597
Number of Embeds
46

Actions

Shares
Downloads
294
Comments
1
Likes
61

Embeds 1,597

http://stendev.com 621
http://51elliot.blogspot.com 305
http://www.slideshare.net 156
http://lanyrd.com 121
http://phcostabh.wordpress.com 67
http://moot.ly 55
http://sens3.com 53
http://51elliot.blogspot.com.es 41
http://51elliot.blogspot.in 28
https://twitter.com 23
http://51elliot.blogspot.ca 17
http://rxvl.in 16
http://www.techgig.com 12
http://51elliot.blogspot.co.uk 9
http://mj89sp3sau2k7lj1eg3k40hkeppguj6j-a-sites-opensocial.googleusercontent.com 7
http://51elliot.blogspot.co.nz 6
http://www.sens3.com 5
http://51elliot.blogspot.com.au 5
http://51elliot.blogspot.fr 4
http://51elliot.blogspot.jp 4
http://rudyschockaert.wordpress.com 4
http://51elliot.blogspot.com.br 4
https://si0.twimg.com 3
http://51elliot.blogspot.de 3
http://51elliot.blogspot.sg 2
http://51elliot.blogspot.cz 2
http://51elliot.blogspot.ie 2
http://posterous.com 2
http://rjsvaljean.com 2
http://akshaye.posterous.com 2
http://51elliot.blogspot.it 1
http://51elliot.blogspot.ae 1
http://51elliot.blogspot.ru 1
http://51elliot.blogspot.tw 1
https://home.jolicloud.com 1
http://51elliot.blogspot.co.il 1
http://www.lmodules.com 1
http://translate.googleusercontent.com 1
http://a0.twimg.com 1
https://lanyrd.com 1
http://webcache.googleusercontent.com 1
http://51elliot.blogspot.com.ar 1
http://rxvl.lan 1
http://www.mefeedia.com 1
http://localhost 1
http://51elliot.blogspot.be 1

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 1. Evented I/O based web servers, explained using bunnies Simon Willison Part of a talk given at Full Frontal 2009
  • 2. Your Web Server (using a bunny)
  • 3. Your Web Server (using a bunny) Single threaded (one bunny), so can only handle one request at a time Happy hamster
  • 4. Your Web Server (using a bunny) (The hamsters are using web browsers to visit your site) Impatient hamsters
  • 5. Your Web Server 5 bunnies = can handle 5 requests at the same time (using threads, aka bunnies) Happy hamsters
  • 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. 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. 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. 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. 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