Speeding up Page Load Times by Using the Starling Queue Server

15,294 views

Published on

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
15,294
On SlideShare
0
From Embeds
0
Number of Embeds
3
Actions
Shares
0
Downloads
4
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Speeding up Page Load Times by Using the Starling Queue Server

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

×