22. Send an email to one user - 50 ms
28 users - 1.4 seconds
600 users - 30 seconds
Problems
23. Run cron every 5 minutes
and you can send a lot more emails
but if one run doesn’t complete...
Problems
24. <?php
$addresses = array(
'jeff@mapbox.com',
'alex@mapbox.com',
'eric@mapbox.com'
);
$message = 'I am writing to inform you of a...';
$count = 0;
foreach($addresses as $sucker) {
if (mail($sucker, 'New opportunity', $message)) {
$count++;
};
}
echo "$count messages sent";
25. var mail = require('mail');
var addresses = [
'jeff@mapbox.com',
'alex@mapbox.com',
'eric@mapbox.com'
];
var message = 'I am writing to inform you of a...';
var count = 0;
addresses.forEach(function(sucker, i) {
mail(sucker, 'New opportunity', message, function(err) {
if (!err) { count++; }
if (i == addresses.length - 1) {
console.log(count +" messages sent");
}
});
});
26. // Attempt to send email.
if (mail($sucker, 'New opportunity', $message)) {
$count++
};
// Once email is sent, get the next address.
echo 'next';
// Attempt to send email.
mail(sucker, 'New opportunity', message, function(err) {
if (!err) { count++; }
});
// Don't wait, get the next address NOW.
console.log('next');
27. Send an email ~ 5 ms processing, 45 ms waiting
28 emails ~ 140 ms to process, done 45 ms later.
600 users ~ 3 seconds to process, done 45 ms later.
Stop waiting around
44. The squid runs up and down as fast as it
can dealing with each item in turn.
It fires off any long running I/O operations
and then moves on to the next item.
When the I/O operation reports progress,
it does a little more work on behalf of the
corresponding item.
95. “The primary focus of most node modules is on
using, not extending... A big part of what makes
node modules so great is how they tend to have
really obvious entry points as a consequence of
focusing on usability and limited surface area”
Limited surface area
96. “Instead of the http server being an external
service that we configure to run our code, it
becomes just another tool in our arsenal”
Callback Austerity
97. "The upshot of this pressure is that, since
essentially every node.js library works this way,
you can pick and choose arbitrary node.js
libraries and combine them in the same
program, without even having to think about the
fact that you’re doing so."
Async by default
101. Photo credit due to these wonderful people who offer
their photos on flickr under a creative commons
license:
Spam - http://www.flickr.com/photos/olivabassa/
Cows - http://www.flickr.com/photos/lynndombrowski/
Dogs - http://www.flickr.com/photos/photosightfaces/
Squid - http://www.flickr.com/photos/laughingsquid/
Ants - http://www.flickr.com/photos/fuzzcat/
Stream - http://www.flickr.com/photos/universalpops/
Boxes - http://www.flickr.com/photos/sillydog/
Pear - http://www.flickr.com/photos/reebob/
Hammer - http://www.flickr.com/photos/kefraya
102.
103. What did you think?
Locate this session on the
DrupalCon Denver website
http://denver2012.drupal.org/program
Click the “Take the Survey” link.
Thank You!