Skip to content

Instantly share code, notes, and snippets.

@darkhelmet
Created November 4, 2010 22:12
Show Gist options
  • Save darkhelmet/663306 to your computer and use it in GitHub Desktop.
Save darkhelmet/663306 to your computer and use it in GitHub Desktop.
What curl returns
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<!--[if lt IE 9]>
<script src="http://html5shim.googlecode.com/svn/trunk/html5.js" type="text/javascript"></script>
<![endif]--><meta name="csrf-param" content="authenticity_token">
<meta name="csrf-token" content="0shcbezUjtj007wiBxYgo7mQBAZFQKoXAHRdDmeDltw=">
<title>Find queries missing indexes in your Rails application | Verbose Logging</title>
<meta content="I help find all those pesky SQL queries without indexes by analyzing your log file." name="description">
<link href="http://localhost:3000/2010/05/14/find-queries-missing-indexes-in-your-rails-application" rel="canonical">
<link href="http://localhost:3000/opensearch.xml" rel="search" title="Verbose Logging" type="application/opensearchdescription+xml">
<link href="http://localhost:3000/sitemap.xml" rel="sitemap" title="Sitemap" type="application/xml">
<link href="/images/favicon.png?1282516201" rel="shortcut icon" type="image/png">
<link href="http://localhost:3000/feed" rel="alternate" title="Verbose Logging RSS Feed" type="application/rss+xml">
<link href="http://localhost:3000/" rel="index" title="Verbose Logging">
<link href="http://fonts.googleapis.com/css?family=Droid+Sans:regular,italic,bold,bolditalic" media="screen" rel="stylesheet" type="text/css">
<link href="http://fonts.googleapis.com/css?family=Droid+Sans+Mono" media="screen" rel="stylesheet" type="text/css">
<link type="text/css" href="/stylesheets/bundles/all/1282952839.css" rel="stylesheet" media="all">
<link href="/stylesheets/darkblog.css?1288074612" media="screen" rel="stylesheet" type="text/css">
<script type="text/javascript">
//<![CDATA[
if (top.location != self.location) { top.location = self.location.href; }
//]]>
</script><script type="text/javascript">
//<![CDATA[
var disqus_developer = 1;
//]]>
</script><link href="http://assets.skribit.com/stylesheets/SkribitSuggest.css" media="screen" rel="stylesheet" type="text/css">
<style media="print">
a#sk_tab{display:none !important;}
</style>
<link rel="stylesheet" href="https://gist.github.com/stylesheets/gist/embed.css">
</head>
<body>
<header><h1 class="left" id="title"><a href="/">Verbose Logging</a></h1>
<nav class="right"><ul>
<li><a href="/">Home</a></li>
<li><a href="/about">About</a></li>
<li><a href="/talks">Talks</a></li>
<li><a href="/contact">Contact</a></li>
<li><a href="/disclaimer">Disclaimer</a></li>
</ul></nav><div id="where">
<a href="http://twitter.com/darkhelmetlive" title="Follow me on Twitter"><img alt="Twitter Icon" src="/images/icons/twitter.png?1282539810"></a>
<a href="http://ca.linkedin.com/in/darkhelmetlive" title="Connect with me on Linkedin"><img alt="Linkedin Icon" src="/images/icons/linkedin.png?1282539817"></a>
<a href="skype:darkhelmetlive?call" title="Call on me! Call me! Call on me! Call me...on Skype"><img alt="Skype Icon" src="/images/icons/skype.png?1282539821"></a>
<a href="http://www.flickr.com/photos/darkhelmetlive/" title="My pictures on Flickr"><img alt="Flickr Icon" src="/images/icons/flickr.png?1282539825"></a>
</div>
<a href="/feed" class="rss" title="Get new articles in your RSS reader."><img alt="RSS" src="/images/rss.png?1282516201"></a>
<div id="search">
<form accept-charset="UTF-8" action="/search" method="get">
<div style="margin:0;padding:0;display:inline"><input name="utf8" type="hidden" value="✓"></div>
<input class="width_3" id="query" name="query" type="text"><input src="/images/magnifier.png?1282516201" type="image">
</form>
</div>
<div class="clear"></div>
<em id="tagline">software development with some really amazing hair</em>
</header><div class="clear"></div>
<div class="row">
<section class="col col_11" id="content"><div class="post">
<h1><a href="http://localhost:3000/2010/05/14/find-queries-missing-indexes-in-your-rails-application">Find queries missing indexes in your Rails application</a></h1>
<div class="meta">
<time datetime="2010-05-14T10:00:00-06:00">14 May 2010 10:00 AM MDT</time>
»
Posted in
<span class="category"><a href="/category/programming">Programming</a></span>
»
Tagged with
<span class="tags">
<a href="/tag/rails">rails</a>
<a href="/tag/activerecord">activerecord</a>
<a href="/tag/mysql">mysql</a>
<a href="/tag/ruby">ruby</a>
</span>
</div>
<div class="content">
<h2>Hi everybody!</h2>
<p>Okay, so don’t worry, I’m not <a href="http://en.wikipedia.org/wiki/Dr._Nick_Riviera">Dr. Nick Riviera</a>, I’m not going to take your liver out. Well, not unless you need to sell it!</p>
<p>I am going to tell how to get your NoSQL on with a little bit of Cassandra, a little bit of Chef, and a little bit of sensual.. NO NO NO! Nevermind, none of that.</p>
<h2>Seriously</h2>
<p>No really, we’re going to get some <a href="http://www.xtranormal.com/watch/6995033/">/dev/null</a> scale up <a href="http://www.explosm.net/db/files/Comics/Rob/upinthisbitch.png">in this bitch</a></p>
<p>But not with MongoDB. This setup is more suited to a Dynamo style system, and not a master-master, or replica system like CouchDB or MongoDB.</p>
<h2>No really, seriously let’s do this</h2>
<p>Okay enough shtick. Let’s do this. Before we get too far, I should tell I’m not going to teach you how to use Chef. That’s a whole other ball of wax. I’ll just show you cool stuff you can do with a really sweet feature of Chef to crank up your cluster.</p>
<h2>What’s so cool about Chef?</h2>
<p>Chef is pretty cool. It’s along the same lines as <a href="http://www.puppetlabs.com/">puppet</a> if you’ve used that. It has a central server which keeps track of hosts (nodes in Chef-speak), and the really cool feature I was talking about is the ability to search your nodes when you are setting one up. You can do some stuff like this:</p>
<pre>search(:node, 'name:db*')</pre>
<p>in a recipe to get all the nodes whose name starts with “db”. Awesome! You could set up <code>iptables</code> to only allow connections from the hosts in your network. You could…um…do some pretty cool stuff. You really can. We’re going to use this feature to setup our cluster.</p>
<h2>Searching <span class="caps">LIKE</span> A <span class="caps">BOSS</span>!</h2>
<p>With Cassandra, you setup a single node, and it has <em>seeds</em>. Well okay, it really only needs one to get started. The seeds are just nodes it <em>gossips</em> with to figure out where everything is. Then it can continue on its merry way, migrating data around, scaling your app by <a href="http://jamesgolick.com/2010/10/27/we-are-experiencing-too-much-load-lets-add-a-new-server..html">adding another server</a>.</p>
<p>So. Where does Chef search come in?</p>
<p>When we crank up another Cassandra node, we can search for and find all the other nodes in the Cassandra cluster, and set those as the sends so it can gossip like the stereotypical office secretary. It not super exciting since it will figure out where all the nodes are given just one, but it’s good stuff anyway. Cassandra also has a very open security model (was designed for situations where you control the <span class="caps">LAN</span>, <span class="caps">AFAIK</span>), so that thing I talked about before? Setting up iptables to only accept connections from a certain set of nodes? Pretty useful now, isn’t it!</p>
<h2>Show me some code already!</h2>
<p>Alright, but only a peak!</p>
<p class="rack-gist" id="rack-gist-662132" gist-id="662132" rack-gist-file="default.rb">Can't see this Gist? <a rel="nofollow" href="http://gist.github.com/662132#file_default.rb">View it on Github!</a></p>
<p>This is the relevant chunk of the <code>default.rb</code> from the Chef recipe. We search for the nodes that have similar names (I was going for the cassandra1, cassandra2 kind of setup), grab their private IP address (you can adapt this for Amazon or Rackspace, or both), and throw these in the config file for the seeds value.</p>
<p>That search is <strong>everything</strong>. I’m just using it to setup the seeds, but you can use it for iptables, for setting up replication between CouchDB or MySQL servers, or setting up an nginx load balancer. You just search for the relevant nodes you need, and away you go.</p>
<p>Maybe it’s just the wine, but I’m excited about that search. It’s not like it’s new, it didn’t just come out in a new version of Chef, but it’s damn exciting. This isn’t your dad’s <a href="http://en.wikipedia.org/wiki/DevOps">devops</a>, it’s automation cranked up to 11.</p>
</div>
<div class="clear"></div>
<a class="a2a_dd no-hover" href="http://www.addtoany.com/share_save">
<img alt="Share/Bookmark" border="0" height="16" src="http://static.addtoany.com/buttons/share_save_171_16.png" width="171"></a>
<script type="text/javascript">
//<![CDATA[
a2a_onclick = 1;
a2a_show_title = 1;
a2a_custom_services = [
[
"Hacker News",
"http://news.ycombinator.com/submitlink?u=A2A_LINKURL_ENC&t=A2A_LINKNAME_ENC",
"http://static.verboselogging.com/images/icons/ycombinator.png"
]
];
//]]>
</script><script src="http://static.addtoany.com/menu/page.js" type="text/javascript"></script><hr>
<div id="disqus_thread"></div>
<script async="async" defer src="http://disqus.com/forums/verboselogging/embed.js" type="text/javascript"></script><noscript><a href="http://verboselogging.disqus.com/?url=ref">View the discussion thread.</a></noscript>
<a class="dsq-brlink" href="http://disqus.com">
Comments powered by
<span class="logo-disqus">Disqus</span>
</a>
</div>
</section><aside class="col col_5" id="sidebar"><section id="author"><img alt="Gravatar for Daniel Huckstep" src="http://www.gravatar.com/avatar/48409ce1953c290351fcb875b20eccbb.png?s=280">
Daniel Huckstep is a software engineer (EIT) in
<a href="http://maps.google.com/maps?f=q&amp;source=s_q&amp;hl=en&amp;geocode=&amp;q=Edmonton,+Alberta,+Canada&amp;sll=53.543564,-113.490452&amp;sspn=0.456975,1.234589&amp;ie=UTF8&amp;hq=&amp;hnear=Edmonton,+Division+No.+11,+Alberta,+Canada&amp;t=h&amp;z=11">Edmonton, Alberta, Canada</a>
</section><section id="postrank"><div class="postrank-widget theDarkSide">
<script src="http://api.postrank.com/static/widget-v2.js" type="text/javascript"></script><script type="text/javascript">
//<![CDATA[
new PostRankWidget({
feed_hash: 'd97657ed1ad63565e413c2797a675064',
num: 6, theme: 'theDarkSide', hasLink: true
});
//]]>
</script><div class="powered-by-postrank-wrapper">
<div class="powered-by-postrank">
<p class="poweredByPostRank">
<a href="http://www.postrank.com/?utm_source=topposts&amp;utm_medium=widget&amp;utm_content=topposts&amp;utm_campaign=pr-1">
<span>Powered by Postrank</span>
</a>
</p>
</div>
<div class="pr_bottomCornerSet">
<div class="pr_clearBottomLeft"></div>
<div class="pr_solidSpecialMiddle"></div>
<div class="pr_clearBottomRight"></div>
</div>
</div>
</div>
</section><section id="shout_out">
Hosting by:
<br><img alt="Heroku" src="/images/heroku.png?1282542759"></section></aside><div class="clear"></div>
<footer class="col col_16"><p>
<a href="http://creativecommons.org/licenses/by-sa/2.5/ca/" no_escape="true" rel="license"><img alt="Creative Commons License" src="http://i.creativecommons.org/l/by-sa/2.5/ca/88x31.png"></a>
<br>
This work is licensed under a
<a href="http://creativecommons.org/licenses/by-sa/2.5/ca/">Creative Commons Licence</a>
<br><a href="/">Home</a>
|
<a href="/about">About</a>
|
<a href="/talks">Talks</a>
|
<a href="/contact">Contact</a>
|
<a href="/disclaimer">Disclaimer</a>
|
<a href="/sitemap.xml">Sitemap</a>
<br>
Theme
<em>darkhax2</em>
by Daniel Huckstep
</p>
</footer><div id="extras">
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.3/jquery.min.js" type="text/javascript"></script><script type="text/javascript" src="/javascripts/bundles/all/1285892439.js"></script><script src="http://ajax.googleapis.com/ajax/libs/chrome-frame/1.0.2/CFInstall.min.js" type="text/javascript"></script><script src="http://assets.skribit.com/javascripts/SkribitSuggest.js" type="text/javascript"></script><script type="text/javascript">
//<![CDATA[
CFInstall.check({
mode: 'overlay'
});
SkribitSuggest.suggest('http://skribit.com/lightbox/verbose-logging', {
placement: 'right',
color: '#333333',
text_color: 'white',
distance_vert: '32%',
distance_horiz: ''
});
//]]>
</script>
</div>
<div id="extra_footer"></div>
</div>
<a href="http://twitter.com/share" class="twitter-share-button" data-count="horizontal" data-via="darkhelmetlive">Tweet</a>
<script src="http://platform.twitter.com/widgets.js" type="text/javascript"></script><script type="text/javascript">
//<![CDATA[
$(document).ready(function() {
$('.rack-gist').each(function() {
var url = '/gist.github.com/' + $(this).attr('gist-id');
var file = false;
if (file = $(this).attr('rack-gist-file')) {
url += '/' + file;
}
$.ajax({
url: url + '.js',
dataType: 'script',
cache: true
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment