<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">
  <channel>
    <title>asemanfar</title>
    <description>a blog about programming</description>
    <link>http://asemanfar.com/posts.rss</link>
    <atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" href="http://feeds.feedburner.com/Asemanfar" type="application/rss+xml" /><feedburner:browserFriendly></feedburner:browserFriendly><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com" /><item>
      <title>Monitoring Unicorn with Bluepill</title>
      <description>&lt;p&gt;At &lt;a href="http://seriousbusiness.com"&gt;Serious Business&lt;/a&gt;, we recently switched to using &lt;a href="http://asemanfar.com/Bluepill:-a-new-process-monitoring-tool"&gt;unicorn&lt;/a&gt; and &lt;a href="http://github.com/arya/bluepill"&gt;bluepill&lt;/a&gt;. One of the features we implemented in bluepill was the ability to monitor child processes. This was built with Unicorn's workers in mind. Here's the config file we're using to monitor our Unicorn workers:&lt;/p&gt;

&lt;p&gt;&lt;code lang="ruby"&gt;
Bluepill.application("app_name-production") do |app|
  app.process("unicorn") do |process|&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;process.pid_file = File.join(RAILS_ROOT, 'tmp', 'pids', 'unicorn.pid')
process.working_dir = RAILS_ROOT

process.start_command = "/usr/bin/env #{env_vars} unicorn -Dc config/unicorn.rb -E production"
process.stop_command = "kill -QUIT {{PID}}"
process.restart_command = "kill -USR2 {{PID}}"

process.uid = process.gid = 'deploy'

process.start_grace_time = 8.seconds
process.stop_grace_time = 5.seconds
process.restart_grace_time = 13.seconds


process.monitor_children do |child_process|
  child_process.stop_command = "kill -QUIT {{PID}}"

  child_process.checks :mem_usage, :every =&amp;gt; 10.seconds, :below =&amp;gt; 150.megabytes, :times =&amp;gt; [3,4]
  child_process.checks :cpu_usage, :every =&amp;gt; 10.seconds, :below =&amp;gt; 20, :times =&amp;gt; [3,4]
end
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;  end
end
&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;One new feature we recently implemented was the support for working_dir, similar to god's config. There is one important difference though: we also set the PWD environmental variable. This is used to reload the unicorn app with a USR2 signal. In order for Unicorn to properly reload the app with the new current symlink, the env variable needs to be set.&lt;/p&gt;

&lt;p&gt;Typically, when you chdir into a symlink'd folder, you are stuck in whatever the symlimk referenced, but if we pass the symlink as an environmental variable, unicorn chdir's into the symlink. The alternative would be to put the full path to the config file in the start command.&lt;/p&gt;

&lt;p&gt;The montioring of child processes is still fairly new, as is all of bluepill, so please report any bugs you encounter to the &lt;a href="http://github.com/arya/bluepill/issues"&gt;github repos' issue page&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="http://asemanfar.com/Bluepill:-a-new-process-monitoring-tool"&gt;Read more about Bluepill&lt;/a&gt;.&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/UnboundImagination/~4/7mDgvF8RcoY" height="1" width="1"/&gt;</description>
      <pubDate>Fri, 06 Nov 2009 09:32:22 +0000</pubDate>
      <link>http://feedproxy.google.com/~r/UnboundImagination/~3/7mDgvF8RcoY/Monitoring-Unicorn-with-Bluepill</link>
      <guid isPermaLink="false">http://asemanfar.com/Monitoring-Unicorn-with-Bluepill</guid>
    <feedburner:origLink>http://asemanfar.com/Monitoring-Unicorn-with-Bluepill</feedburner:origLink></item>
    <item>
      <title>Bluepill: a new process monitoring tool</title>
      <description>&lt;p&gt;Over the past several weeks, &lt;a href="http://github.com/entombedvirus"&gt;two&lt;/a&gt; &lt;a href="http://github.com/garru"&gt;co-workers&lt;/a&gt; and I wrote a simple process monitoring tool: bluepill, because it keeps things up. Bluepill replaces the existing process monitoring tool we were using which &lt;a href="http://asemanfar.com/Why-We-Wrote-Bluepill"&gt;we had some issues&lt;/a&gt; with.&lt;/p&gt;

&lt;p&gt;Bluepill is now running on over a dozen of our machines with no memory leaks. It's monitoring several of our services, including long-running rake tasks, background workers, &lt;a href="http://unicorn.bogomips.org/"&gt;unicorn processes&lt;/a&gt;, and &lt;a href="http://github.com/arya/pandemic"&gt;pandemic workers&lt;/a&gt;. It's been idling at 18MB (see &lt;a href="http://asemanfar.com/Why-We-Wrote-Bluepill"&gt;related post&lt;/a&gt; for graph).&lt;/p&gt;

&lt;p&gt;Here is a sample of the DSL:
&lt;code lang="ruby"&gt;
Bluepill.application("app_name") do |app|
  app.process("process_name") do |process|&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;process.start_command = "/usr/bin/some_start_command"
process.pid_file = "/tmp/some_pid_file.pid"

process.checks :cpu_usage, :every =&amp;gt; 10.seconds, :below =&amp;gt; 5, :times =&amp;gt; 3        
process.checks :mem_usage, :every =&amp;gt; 10.seconds, :below =&amp;gt; 100.megabytes, :times =&amp;gt; [3,5]
process.checks :flapping, :times =&amp;gt; 2, :within =&amp;gt; 30.seconds, :retry_in =&amp;gt; 7.seconds
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;  end
end
&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Check the &lt;a href="http://github.com/arya/bluepill/blob/master/README.markdown"&gt;readme&lt;/a&gt; for detailed installation and usage.&lt;/p&gt;

&lt;p&gt;&lt;a href="http://github.com/arya/bluepill"&gt;read&lt;/a&gt;, &lt;a href="http://github.com/arya/bluepill"&gt;fork&lt;/a&gt;, and &lt;a href="http://github.com/arya/bluepill/issues"&gt;report bugs&lt;/a&gt;.&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/UnboundImagination/~4/h8VTlswuOto" height="1" width="1"/&gt;</description>
      <pubDate>Wed, 04 Nov 2009 06:29:02 +0000</pubDate>
      <link>http://feedproxy.google.com/~r/UnboundImagination/~3/h8VTlswuOto/Bluepill:-a-new-process-monitoring-tool</link>
      <guid isPermaLink="false">http://asemanfar.com/Bluepill:-a-new-process-monitoring-tool</guid>
    <feedburner:origLink>http://asemanfar.com/Bluepill:-a-new-process-monitoring-tool</feedburner:origLink></item>
    <item>
      <title>Why We Wrote Bluepill</title>
      <description>&lt;p&gt;At &lt;a href="http://seriousbusiness.com"&gt;Serious Business&lt;/a&gt;, we use &lt;a href="http://github.com/mojombo/god"&gt;god&lt;/a&gt; to monitor our long-running processes (mongrel, background workers, and more recently &lt;a href="http://unicorn.bogomips.org/"&gt;unicorn&lt;/a&gt;). We had a basic god config setup that only checks for memory usage, cpu usage, and request queue length (for mongrels only). God was working fine for us except for one problem: &lt;a href="http://groups.google.com/group/god-rb/browse_thread/thread/1cca2b7c4a581c2/69f69f602add7636?lnk=gst&amp;amp;q=memory+leak#69f69f602add7636"&gt;the notorious memory leak&lt;/a&gt;. If you use god you probably know it leaks memory in correlation with the number of watches on the system. This became a problem for us when god hadn't been restarted for several days; its memory usage would climb and reach several gigs, causing the machine to swap and eventually lock-up. To prevent lock-ups we needed to manually monitor god (what does that make us?) and restart god daily via cron, gross.&lt;/p&gt;

&lt;p&gt;Our frustration with this issue eventually reached a point where we decided to write our own process monitoring tool. &lt;a href="http://github.com/entombedvirus"&gt;Rohith Ravi&lt;/a&gt;, &lt;a href="http://github.com/garru"&gt;Gary Tsang&lt;/a&gt;, and I got together one weekend and built a first version of what we've come to call &lt;a href="http://github.com/arya/bluepill"&gt;bluepill&lt;/a&gt;. We spent the next couple weeks massaging the DSL, expanding feature set, and fixing some bugs we found while using it for our apps. The current feature set is small but is sufficient for the most users:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;DSL for specifying processes and their respective watches&lt;/li&gt;
&lt;li&gt;Built-in support for monitoring memory usage and CPU usage&lt;/li&gt;
&lt;li&gt;Support for custom conditions to watch&lt;/li&gt;
&lt;li&gt;Daemoniziation of non-daemonized processes&lt;/li&gt;
&lt;li&gt;Monitoring child processes (especially useful for monitoring unicorn workers)&lt;/li&gt;
&lt;li&gt;Logging&lt;/li&gt;
&lt;li&gt;Support for triggers (flapping)&lt;/li&gt;
&lt;/ul&gt;


&lt;p&gt;While both &lt;a href="http://github.com/arya/bluepill"&gt;bluepill&lt;/a&gt; internal and the external interface is heavily influenced by &lt;a href="http://github.com/mojombo/god"&gt;god&lt;/a&gt;, we decided do some things differently in bluepill:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Written with long-running daemon in mind (read: low resource consumption)&lt;/li&gt;
&lt;li&gt;Simplicity over flexibility:&lt;/li&gt;
&lt;li&gt;one process per application; forces separation between multiple apps on the same box&lt;/li&gt;
&lt;li&gt;simple state machine; does only what it needs to to keep the process up&lt;/li&gt;
&lt;/ul&gt;


&lt;p&gt;This past week, we ran a test to see how well Bluepill will do in the wild compared to god, so we set up a &lt;a href="http://gist.github.com/223195"&gt;basic bluepill config file&lt;/a&gt; and the equivalent god config on two identical machines and recorded their memory usage every 30 minutes for just over 4 days.&lt;/p&gt;

&lt;p style="text-align: center"&gt;
&lt;img src="/system/bluepill_memory_usage.png" alt="bluepill vs god memory usage" title="bluepill vs god memory usage" /&gt;
&lt;/p&gt;


&lt;p&gt;In addition to the memory leak issue, we sought to improve god in a few other ways: sequential CLI command processing, improved daemonization, and monitoring child processes:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;CLI Command Processing&lt;/strong&gt;&lt;br/&gt;
In god, CLI issued commands are sent to the long-running god daemon which starts a separate thread and returns to the CLI; this led to some race cases when you issue two commands sequentially and expected them to execute in that order (i.e god stop &amp;lt;process_name&gt;; god start &amp;lt;process_name&gt;). This is fixed in bluepill by handling CLI issued commands in a single thread fed by a queue.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Improved Daemonization&lt;/strong&gt; &lt;br/&gt;
One of the things that is great about god is that it can daemonize processes for you. Meaning, for example, you can write a normal rake task that does some heavy offline work and ask god to daemonize it and viola! you have instant background workers. However, there was a problem: god did not do a good job of monitoring the processes it daemonized. God, through it's use of the &lt;em&gt;system&lt;/em&gt; Ruby method, executed command inside a &lt;em&gt;sh -c "..."&lt;/em&gt; shell and then proceeded to monitor the shell instead of the actual process that the shell spawned. Bluepill fixes this by daemonizing commands and then properly detecting the pid of the spawned process. The only catch is that you need to tell bluepill whether or not it should daemonize the process.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Monitoring Child Processes&lt;/strong&gt;&lt;br/&gt;
We recently switched in Unicorn which starts its own long-running child processes to handle requests. So in order to monitor the unicorn workers, we needed to add support for monitoring child processes. Child process monitoring differs from regular process monitoring because bluepill is not responsible for starting them back up and the PID comes from the parent process and not a PID file.&lt;/p&gt;

&lt;p&gt;We're going to continue working on it to improve its feature set and iron outs any bugs that we find.&lt;/p&gt;

&lt;p&gt;Read the &lt;a href="http://github.com/arya/bluepill/blob/master/README.markdown"&gt;readme&lt;/a&gt; for usage information. Read the &lt;a href="http://github.com/arya/bluepill/blob/master/DESIGN.markdown"&gt;design file&lt;/a&gt; for technical details.&lt;br/&gt;
Fork and contribute: &lt;a href="http://github.com/arya/bluepill"&gt;http://github.com/arya/bluepill&lt;/a&gt;&lt;br/&gt;
Report bugs: &lt;a href="http://github.com/arya/bluepill/issues"&gt;http://github.com/arya/bluepill/issues&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/UnboundImagination/~4/t3FJQt8vhxY" height="1" width="1"/&gt;</description>
      <pubDate>Sat, 31 Oct 2009 19:49:33 +0000</pubDate>
      <link>http://feedproxy.google.com/~r/UnboundImagination/~3/t3FJQt8vhxY/Why-We-Wrote-Bluepill</link>
      <guid isPermaLink="false">http://asemanfar.com/Why-We-Wrote-Bluepill</guid>
    <feedburner:origLink>http://asemanfar.com/Why-We-Wrote-Bluepill</feedburner:origLink></item>
    <item>
      <title>search.facebook</title>
      <description>&lt;p&gt;Today, Facebook announced their new Open Graph API. The Open Graph API allows any website to have &lt;a href="http://wiki.developers.facebook.com/index.php/Roadmap_Open_Graph_API"&gt;all the features of a Facebook Page&lt;/a&gt;. So you'll be able to "Become a Fan" of any site, make comments, have discussions, and receive updates published by fanned sites. Think &lt;a href="http://www.amazon.com/wishlist/get-button"&gt;Amazon's Universal Wishlist&lt;/a&gt; but not just for things you can buy.&lt;/p&gt;

&lt;p&gt;This leads to some interesting business opportunities for Facebook. Facebook will be able to capture socially relevant information from anywhere on the Internet. Facebook will collect information about "what's on your mind" from everywhere on the Web, not just on facebook.com.&lt;/p&gt;

&lt;p&gt;Now let's take that and see how Facebook can profit from that: they can do exactly what Google does but &lt;em&gt;enhanced&lt;/em&gt; by your social graph. They will be able to give you Web Search Results but unlike Google, they'll be able to tell you that "Joe Smith likes this" and what was "on his mind" when he visited that site. Not only that, but they'll maybe even cross some privacy boundaries that Google couldn't and use that information to target ads.&lt;/p&gt;

&lt;p&gt;The challenges Facebook will face in the coming months/year will be dealing with privacy issues and adoption of the Open Graph API. I suspect something similar to a bookmarklet, browser toolbar, or full-blown "socially enhanced" browser will be used in order to gain traction and bootstrap their social indexing efforts. I'm also interested to see how well they'll execute on search results with social graph information and if they can complete with Google's myriad of well-tested and proven search ranking algorithms.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Arya likes this.&lt;/em&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/UnboundImagination/~4/3TTGa6Muzn4" height="1" width="1"/&gt;</description>
      <pubDate>Thu, 29 Oct 2009 05:43:57 +0000</pubDate>
      <link>http://feedproxy.google.com/~r/UnboundImagination/~3/3TTGa6Muzn4/searchfacebook</link>
      <guid isPermaLink="false">http://asemanfar.com/searchfacebook</guid>
    <feedburner:origLink>http://asemanfar.com/searchfacebook</feedburner:origLink></item>
  </channel>
</rss>
