Benoit Daloze Winner RPCFN #9

In this brief interview, Satish Talim of RubyLearning talks to Benoit Daloze of Belgium, winner of the ninth Ruby Programming Challenge For Newbies.

Benoit Daloze

Satish>> Welcome Benoit and thanks for taking out time to share your thoughts. For the benefit of the readers, could you tell us something about your self?

Benoit>> I would first like to thank RubyLearning for all they have done. I am a 19 year old student in first bachelor in computer sciences (at UCL, Louvain-la-Neuve). I am studying Java at courses, but I think I did more Ruby this year. Well, I just can not stop thinking “This would be so much better in Ruby”.

Satish>> How did you get involved with Ruby programming?

Benoit>> I have been looking on Ruby for some years now. I met Ruby the first time as a scripting language in a game software when I was 15, and since then always wanted to know more about it. It took me some time to learn it, because I did not find the good resources. I feel I am getting more and more involved everyday, as does my knowledge of Ruby.

Satish>> Could you name three features of Ruby that you like the most, as compared to other languages? Why?

Benoit>>

  1. Metaprogramming: This introduces a great way to program, and allows you to make it even shorter. It gives me the feeling that I really have a control on the objects, because you can so easily manipulate them.
  2. Flexibility: Whenever you think you can mix some concepts together in Ruby, it just works, limitations are rare, and often out of imagination’s bounds. You are pretty much doing it the way you want, and Ruby lets you code that way.
  3. Blocks: Blocks is a entire way of expression, and the amount of complex methods made simple by this is awesome. Just think how you would do a #group_by, #each_slice or #partition in other languages. Most of the time it would be far more verbose and you would likely get a headache. Ruby has brought all the many useful things in the core, because it can be expressed in a simple method.

Satish>> How was experience of taking part in the Ruby Programming Challenge For Newbies (RPCFN)?

Benoit>> I’m participating since the fourth challenge, and I’m happy to participate in these interesting challenges. It is also a great way to discover other’s code, often very imaginative and original. And coding always makes you better in the language, so it is all for the best!

Satish>> You are based in Belgium. How is the Ruby and Rails scenario there?

Benoit>> People have now started noticing Rails, but this activity is mainly driven by some specific companies. Ruby is somehow not known, and sadly ignored in universities. ( But I’m trying to remedy that :) )

Satish>> What are your future plans?

Benoit>> I am going to work on Rails this summer, to discover this part of Ruby I have not used much yet. I’m also doing some Ruby everyday, for my own use, just feeling happy to code with a beautiful language.

Thank you Benoit. In case you have any queries and/or questions, kindly post your questions here (as comments to this blog post) and Benoit would be glad to answer.

Technorati Tags: , , , , ,

Improving Satan and Solaris SMF

One of the features of Solaris that we heavily rely on in our production environment at work is Service Management Facility or SMF for short. SMF can start/stop/restart services, track dependencies between services and use that to optimize the boot process and lots more. Often handy in production environment is that SMF keeps track of processes that a particular service started and if a process dies, SMF restarts its services.

One gripe I have with SMF is that its process monitoring capabilities are rather simple. A process associated with a contract (service) must die in order for SMF to get the idea that something is wrong and that the service should be restarted. In practice, more often than not a process gets into a weird state that prevents it from working properly, yet it doesn’t die. Failures might include excessive cpu or memory usage or even application level failures that

Continue reading “Improving Satan and Solaris SMF”

Improving Satan and Solaris SMF

One of the features of Solaris that we heavily rely on in our production environment at work is Service Management Facility or SMF for short. SMF can start/stop/restart services, track dependencies between services and use that to optimize the boot process and lots more. Often handy in production environment is that SMF keeps track of processes that a particular service started and if a process dies, SMF restarts its services.

One gripe I have with SMF is that its process monitoring capabilities are rather simple. A process associated with a contract (service) must die in order for SMF to get the idea that something is wrong and that the service should be restarted. In practice, more often than not a process gets into a weird state that prevents it from working properly, yet it doesn’t die. Failures might include excessive cpu or memory usage or even application level failures that can be detected only by interacting with the application (e.g. http health check). SMF in its current implementation is incapable of detecting these failures. And this is where Satan comes into the play.

Satan a small ruby script that monitors a process and following the Crash-only Software philosophy, kills it when a problem is detected. It then relies on SMF to detect the process death(s) and restart the given service. I fell in love with the simplicity of Satan (which was inspired by God) and started exploring the feasibility of using it to improve the reliability of SMF on our production servers.

Upon a code review of the script, I noticed several things that I wished were implemented differently. Here are some:

  • Satan watches processes rather than services as defined via SMF
  • One Satan instance is designed to watch many different processes for different services, which adds unnecessary complexity and lacks isolation
  • Satan is merciless (what a surprise! 🙂 ) and uses kill -9 without a warning
  • Satan has no test suite!!! 🙁 (i.e. I must presume that it doesn’t work)

Thankfully the source code was out there on GitHub and licensed under BSD license so it was just a matter of a few keystrokes to fork it (open source FTW!). By the time I was done with my changes, there wasn’t much of the original source code left, but oh well 🙂

I’m happy to present to you http://github.com/IgorMinar/satan for review and comments. The main changes I made are the following:

  • One Satan instance watches single SMF service and its one or more processes
  • The single service to monitor design allows for automatic monitoring suspension via SMF dependencies while the monitored service is being started, restarted or disabled
  • Several bugfixes around how rule failures and recoveries are counted before a service is deemed unhealthy
  • At first Satan tries to invoke svcadm restart and only if that doesn’t occur within a specified grace period, it uses kill -9 to kill all processes for the given contract (service)
  • Satan now has decent RSpec test suite (more on that in my previous post)
  • Improved HTTP condition with a timeout setting
  • New JVM free heap space condition to monitor those pesky JVM memory leaks
  • Extensible design now allows for new monitoring conditions (rules) to be defined outside of the main Satan source code

As always there are more things to improve and extend but, I’m hoping that my Satan fork will be a decent version that will allow us to keep our services running more reliably. If you have suggestions, or comments feel free to leave feedback.

Interesting Ruby Tidbits #32: DataMapper, Screencasts, IP Addresses, Euruko 2010 and more

The latest installment of my series of roundup posts, covering some of my latest findings in the world of all things Ruby. Why two “tidbits” posts in a row? Well, I’m radically redesigning/reworking Ruby Inside to be more interesting, both to you and me. This coupled with work on my new startup coder.io have reduced my available time a lot but, rest assured, everything will be crazy on Ruby Inside again within a week or so 🙂

For now, enjoy!

DataMapper 1.0.0 RC3 Released

The third release candidate of popular Ruby ORM DataMapper has been released. I’ve become a bit of a MongoMapper and Redis guy myself lately, but ORMs like DataMapper and Sequel provide great alternatives to the ever-popular ActiveRecord ORM. 1.0 is considered a major release for most projects nowadays in terms of stability and support, so seeing DataMapper edging closer to that landmark is encouraging.

ThinkCode.TV Screencasts from Antonio Cangiano

ThinkCode.TV is a new screencast company from Antonio Cangiano (of Ruby benchmarking fame). Antonio got in touch with me so I could review a couple of his screencasts. I haven’t had time, but I’ve seen good words about them and the productions seem tight. Of most relevance to Rubyists will be Introduction to MacRuby (recommended by Matt Aimonetti and Laurent Sansonetti of the MacRuby team!) and Guide to TDD. There’s also an upgrading to Rails 3 video if that’s your cup of tea.

Euruko 2010 Summaries

Markus Prinz has been summarizing the goings on at Europe’s premier Ruby conference, Euruko – this year being held in Poland. He has a round up of day one and day two including notes on the presentations. I plan to do a big roundup post of Euruko on Ruby Inside in the next couple of weeks, but this is great for now.

RubyRow – Ruby Blog Advertising Network – Relaunch

James Avery, the mastermind behind .Net’s popular The Lounge ad network, has announced the relaunch of his RubyRow advertising network. RubyRow is the biggest advertising network in the Ruby space, covering blogs from RailsTips, Thoughtbot, Giles Bowkett, Dr Nic, Jamis Buck, Obie Fernandez, Geoffrey Grosenbach and… yes, Ruby Inside, Rails Inside, and RubyFlow.

If you have something to advertise to the Ruby world, head on over to RubyRow.net and get in touch with James. I’d love to see your logo on the sidebar here or on RubyFlow 😉 (tip: RubyFlow is cheaper and the audience typically more technical, if that suits you better)

Real World Ruby and Cassandra

If you’ve been following the “NoSQL” debates lately, you might have heard of Apache Cassandra, a “highly scalable” distributed database system built around a column storage model. Despite Cassandra starting to become a household name with developers, it’s often seen as being harder to get into than things like MongoDB and CouchDB, so Mike Subelsky has put together a blog post titled Real World Ruby and Cassandra to demonstrate how he uses Cassandra from Ruby, and what other pages you should read.

IPAddress – Handle IPv4 and IPv6 Addresses from Ruby

IPAddress is a new Ruby library by Marco Ceresa that goes beyond Ruby’s “IPAddr” library and offers both powerful and easy handling of IP (v4 and v6) addresses from Ruby. It’s fully object oriented and has some pretty extensive document with lots of examples. You can store IP addresses including a prefix (e.g. /24) or submask, determine the class of IP addresses, work with broadcast addresses, special formats (bits, IPv4→IPv6, long IP) and more. This is the sort of hard working cornerstone library that we could do with more of.

The Difference Between Ruby Procs and Lambdas

Alan Skorkin has written Ruby Procs and Lambdas which is a code heavy blog post that demonstrates what it says in its title. Alan’s blog has been a common sight on the front page of Hacker News lately, and for good reason – he writes well and this post is no exception. You’ll learn something from this.

RubyRags.com (Ruby Clothing Site) For Sale

Ryan Norbauer is selling his RubyRags.com, Ruby-related clothing site. In the last 2 years, it’s taken in about $16K and fulfilment, etc, is handled by a third party. There’s more information relating to the sale.

Phashion: A “Perceptual Hash” Library Wrapper

Phashion is a Ruby wrapper around the open source pHash library that provides “perceptual hashing” functionality. What’s a perceptual hash? Well:

A perceptual hash is a fingerprint of a multimedia file derived from various features from its content. Unlike cryptographic hash functions which rely on the avalanche effect of small changes in input leading to drastic changes in the output, perceptual hashes are “close” to one another if the features are similar.

Interesting.

By the way, if you have a minute, drop over to coder.io and if it looks interesting, drop your e-mail in the box. It’s very close to a beta launch and if you’re into reading programming news like the above, you should get a lot out of it.

Testing matters, even with shell scripts

A few months ago, we migrated out production environment at work from Solaris 10 to OpenSolaris. We loved the change because it allowed us to take advantage of the latest inventions in Solaris land. All was good and dandy until one day one of our servers ran out of disk space and died. WTH? We have monitoring scripts that alert us long before we get even close to running out of space, yet no alert was issued this time. While investigating the cause of this incident, we found out that our monitoring scripts that work well on Solaris 10, didn’t monitor the disk space correctly on OpenSolaris. When I asked our sysadmins if they didn’t have any tests for their scripts that could validate their functionality, they laughed at me.

Fast forward a few months. A few days ago I started looking at Satan, to augment the self healing

Continue reading “Testing matters, even with shell scripts”

Testing matters, even with shell scripts

A few months ago, we migrated out production environment at work from Solaris 10 to OpenSolaris. We loved the change because it allowed us to take advantage of the latest inventions in Solaris land. All was good and dandy until one day one of our servers ran out of disk space and died. WTH? We have monitoring scripts that alert us long before we get even close to running out of space, yet no alert was issued this time. While investigating the cause of this incident, we found out that our monitoring scripts that work well on Solaris 10, didn’t monitor the disk space correctly on OpenSolaris. When I asked our sysadmins if they didn’t have any tests for their scripts that could validate their functionality, they laughed at me.

Fast forward a few months. A few days ago I started looking at Satan, to augment the self healing capabilities of Solaris SMF (think initd or launchd on stereoids). At first sight I loved the simplicity of the solution, but one thing that startled me during the code review was that there were no tests for the code, except for some helper scripts that made manual testing a bit less painful. At the same time, I spotted several bugs that would have resulted in an unwanted behavior.

Satan relies on invoking solaris commands from ruby and parsing the output and acting upon it. Thanks to its no BS nature, ruby makes for an excellent choice when it comes to writing programs that interact with the OS by executing commands. There are several ways to do this, but the most popular looks like this:

ps_output = `ps -o pid,pcpu,rss,args -p #{pid}`

All you need to do is to stick the command into backticks and optionally use #{variable} for variable expansion. To get a hold of the output, just assign the return value to a variable.

Now if you stick a piece of code like this in the middle of the ruby script you get something next to untestable:

module PsParser
 def ps(pid)
   out_raw = `ps -o pid,pcpu,rss,args -p #{pid}`
   out = out_raw.split(/\n/)[1].split(/ /).delete_if {|arg| arg == "" or arg.nil? }
   { :pid=>out[0].to_i,
     :cpu=>out[1].to_i,
     :rss=>out[2].to_i*1024,
     :command=>out[3..out.size].join(' ') }
 end
end

With the code structured (or unstructured) like this, you’ll never be able to test if the code can parse the output correctly. However if you extract the command execution into a separate method call:

module PsParser
 def ps(pid)
   out = ps_for_pid(pid).split(/\n/)[1].split(/ /).delete_if {|arg| arg == "" or arg.nil? }
   { :pid=>out[0].to_i,
     :cpu=>out[1].to_i,
     :rss=>out[2].to_i*1024,
     :command=>out[3..out.size].join(' ') }
 end

 private
 def ps_for_pid(pid)
   `ps -o pid,pcpu,rss,args -p #{pid}`
 end
end

You can now open the module and redefine the ps_for_pid in your tests like this:

require 'ps_parser'

PS_OUT = {
 1 => "  PID %CPU    RSS ARGS
12790   2.7 707020 java",
 2 => "  PID %CPU    RSS ARGS
12791  92.7 107020 httpd"
}

module PsParser
 def ps_for_pid(pid)
   PS_OUT[pid]
 end
end

And now you can simply call the pid method and check if the fake output stored in PS_OUT is being parsed correctly. The concept is the same as when mocking webservices or other complex classes, but applied to running system command and programs.

To conclude, what makes you more confident about a software you want to rely on. An empty test folder:
Or all green results from a test/spec suite?

#216 Generators in Rails 3

Generators in Rails 3 have been completely rewritten to be more modular. This allows you to customize any generator to fit your specific preferences.

#216 Generators in Rails 3

Generators in Rails 3 have been completely rewritten to be more modular. This allows you to customize any generator to fit your specific preferences.

Arithmetic with Liquid

The Liquid templating language is quite limited due to concerns about the safety of user supplied code. However, it introduces issues when some basic actions, such as arithmetic, are required.
One issue is that you can’t perform an operation on integers and assign it to a new integer variable in one statement. […]

Dribbble: Dan Cederholm and Rich Thornett – Ruby on Rails Podcast

The designer and developer of the Dribbble social design network talk about its implementation and the ideas behind it.

Mentioned

Dribbble: Dan Cederholm and Rich Thornett – Ruby on Rails Podcast

The designer and developer of the Dribbble social design network talk about its implementation and the ideas behind it.

Mentioned

#118: Bug Free

In this episode, Jason and Dan go over the latest, completely bug free releases of Rails and talk more about some of the latest and greatest from the ruby and rails communities.

Inventables is hiring a software engineer with ruby, rails, and agile experience. View the listing at Genius Pool or browse all jobs.

Links for this episode:

May 28, 2010: Friday Friday Friday

Short today, but preparing some longer, more rant-y bits for the future…

Book status

Not much forward motion for the next few days, as I have a lot of other stuff to do, including preparing for Chicago Ruby on June 1 and doing a bit of touch-up on Obtiva’s 4-Day Ruby on Rails/TDD boot camp. All fun, but time consuming.

Some Links

A quick tutorial by Peter Cooper on setting up JQuery in Rails 3.

This isn’t the first time I’ve seen something like this, but this article by Alan Skorkin on Ruby Procs and Lambdas is well done and it’s worth refreshing from time to time.

We always say that Ruby methods can’t have spaces in them, but technically that’s a lie, as shown in Joon You’s screencast.

Rails Dispatch this week is by José Valim. It’s kind of rambling, but a very interesting look at plugins that mess with Rails 3 features like Responders and Generator.

Filed under: Chicago Ruby, JQuery, Metaprogramming, Obtiva, Plugins, Rails, Rails 3, Ruby

Join the zsh revolution

I love the OhMyZsh community. Let’s grow it a little more this next Tuesday.

<a href="http://twitter.com/ohmyzsh/status/14812098501"><img src="http://img.skitch.com/20100527-pnc2xtigq9xerriem7txddwi7s.preview.jpg" alt="Twitter / Oh My Zsh: Declaring that next Tuesda ..." /></a>


<p><a href="http://github.com/robbyrussell/oh-my-zsh">Join the Zsh revolution here&#8230;</a></p><div class="feedflare">