Faster Response Times
By using the Starling Queue Server




               Erik Osterman
               Launch 10 Labs LLC
               http://launch10.com
What is the problem?

● You want to write a lot of data quickly
   ○ e.g. tons of INSERTs & UPDATEs
   ○ Bursts exceed capacity
   ○ No ability to throttle requests
● Requests that modify stored data are slow / timeout
   ○ Reduced page impressions
   ○ Reduced revenues (CPM)
   ○ Customers bail
   ○ You look bad!
● Added Memcache, but it's still slow (duh?)!
   ○ Memcache only speeds up reads, not writes
What is the solution?

● Don't write to the database!
● Create jobs in the queue instead of writes to the DB
● Writing objects to queue is FAST
● Use a multi-threaded batch processor to run the jobs
  "As fast as you can"
● Jargon (queue, job, batch processor)
Why use Starling?

● Used in massive production environments
● Lightweight, Extremely FAST
● Persistent (crash recoverable)
● Trivial to scale; scales just like memcached
● Handles hundreds of thousands of items
● Thousands of queue inserts per second
● Speaks Memcache protocol (very simple! very portable!)
● Minimal code changes*
● Named Queues
● Performance metrics / stats
● GNU LGPL License (= Free software!)
● (Not Java)
Everyone's doing it.....

● The Dot Game & Paradigm (starling)
● Twitter (starling)
● Friends For Sale (starling)
● FiveRuns (starling)
● Causes on Facebook (beanstalkd)
● ShareThis (SQS)
● Alexa (SQS)
● Insert your company here

                 Maybe you should too!
What do I need to use Starling?

Not much!
 ● Server with Ruby to run Starling
 ● # gem install starling
 ● Memcache Client
 ● Configure application to add jobs to the queue
 ● Batch process to run the jobs in the queue
PHP Example (request)

// index.php
<?php
$memcache = new Memcache();
$memcache->addServer('localhost', 22122);
$memcache->set('last_seen', Array('user_id'
=>                                  $_SESSION['user_id'],
'timestamp' => time()));
?>
PHP Example (batch)
<?php
// process-jobs.php
$memcache = new Memcache();
$memcache->addServer('localhost', 22122);
while(true)
{
   if($job = $memcache->get('last_seen'))
   {
      // Process $job
   } else {
      // Queue empty!
      sleep(1);
   }
}
?>
What are my alternatives?

● Increase I/O capacity (expensive!)
● Use a faster DB solution
● Shard your database (hard!)
● Master-master replication (tricky!)
● Memcache (Wrong answer! not applicable)
● Use a simple queue table (slow!)
● Optimize tables / reduce FKs & indexes / change engine
● Write less

     Best solution? As many optimizations as you can.
Other Queue Servers
 ● Starling (LGPL)
 ● BeanStalk (GNU GPL v3)
 ● Open Message Queue(CDDL / GPL v2)
 ● Apache Active MQ (Apache 2.0 License)
 ● Rabbit MQ (Mozilla Public License)
 ● Sparrow (MIT License)
 ● Scarling (ISC license)
 ● MySQL Home brewed solution

Not so free
 ● Amazon SQS (Pay per Query)
 ● Microsoft Message Queue Server
 ● IBM WebSphere MQ
Q&A


   What did I miss?



tinyurl.com/L10-starling

             Erik Osterman
          www.launch10.com
   eosterman@launch10.com

Speeding up Page Load Times by Using Starling

  • 1.
    Faster Response Times Byusing the Starling Queue Server Erik Osterman Launch 10 Labs LLC http://launch10.com
  • 2.
    What is theproblem? ● You want to write a lot of data quickly ○ e.g. tons of INSERTs & UPDATEs ○ Bursts exceed capacity ○ No ability to throttle requests ● Requests that modify stored data are slow / timeout ○ Reduced page impressions ○ Reduced revenues (CPM) ○ Customers bail ○ You look bad! ● Added Memcache, but it's still slow (duh?)! ○ Memcache only speeds up reads, not writes
  • 3.
    What is thesolution? ● Don't write to the database! ● Create jobs in the queue instead of writes to the DB ● Writing objects to queue is FAST ● Use a multi-threaded batch processor to run the jobs "As fast as you can" ● Jargon (queue, job, batch processor)
  • 4.
    Why use Starling? ●Used in massive production environments ● Lightweight, Extremely FAST ● Persistent (crash recoverable) ● Trivial to scale; scales just like memcached ● Handles hundreds of thousands of items ● Thousands of queue inserts per second ● Speaks Memcache protocol (very simple! very portable!) ● Minimal code changes* ● Named Queues ● Performance metrics / stats ● GNU LGPL License (= Free software!) ● (Not Java)
  • 5.
    Everyone's doing it..... ●The Dot Game & Paradigm (starling) ● Twitter (starling) ● Friends For Sale (starling) ● FiveRuns (starling) ● Causes on Facebook (beanstalkd) ● ShareThis (SQS) ● Alexa (SQS) ● Insert your company here Maybe you should too!
  • 6.
    What do Ineed to use Starling? Not much! ● Server with Ruby to run Starling ● # gem install starling ● Memcache Client ● Configure application to add jobs to the queue ● Batch process to run the jobs in the queue
  • 7.
    PHP Example (request) //index.php <?php $memcache = new Memcache(); $memcache->addServer('localhost', 22122); $memcache->set('last_seen', Array('user_id' => $_SESSION['user_id'], 'timestamp' => time())); ?>
  • 8.
    PHP Example (batch) <?php //process-jobs.php $memcache = new Memcache(); $memcache->addServer('localhost', 22122); while(true) { if($job = $memcache->get('last_seen')) { // Process $job } else { // Queue empty! sleep(1); } } ?>
  • 9.
    What are myalternatives? ● Increase I/O capacity (expensive!) ● Use a faster DB solution ● Shard your database (hard!) ● Master-master replication (tricky!) ● Memcache (Wrong answer! not applicable) ● Use a simple queue table (slow!) ● Optimize tables / reduce FKs & indexes / change engine ● Write less Best solution? As many optimizations as you can.
  • 10.
    Other Queue Servers ● Starling (LGPL) ● BeanStalk (GNU GPL v3) ● Open Message Queue(CDDL / GPL v2) ● Apache Active MQ (Apache 2.0 License) ● Rabbit MQ (Mozilla Public License) ● Sparrow (MIT License) ● Scarling (ISC license) ● MySQL Home brewed solution Not so free ● Amazon SQS (Pay per Query) ● Microsoft Message Queue Server ● IBM WebSphere MQ
  • 11.
    Q&A What did I miss? tinyurl.com/L10-starling Erik Osterman www.launch10.com eosterman@launch10.com