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

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Evented I/O based web servers, explained using bunnies

31,403

Published 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.

Published in: Technology, Business
1 Comment
65 Likes
Statistics
Notes
No Downloads
Views
Total Views
31,403
On Slideshare
0
From Embeds
0
Number of Embeds
26
Actions
Shares
0
Downloads
298
Comments
1
Likes
65
Embeds 0
No embeds

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

×