Ylan Segal

Killing Me Softly

Every once in a while, a process is stuck and doesn’t want to respond. I usually just found the process id by using ps and then ran kill -9 <pid>. Why? Cargo-culting, mostly.

Recently a friend and co-worker shared with me a little bash function that will attempt to send less destructive signals to the process to allow it to have time to clean-up after itself. Eventually it ends up just sending the KILL signal, equivalent to -9.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
function mercy_kill() {
  pid=$1
  for signal in TERM INT HUP KILL; do
    cmd="kill -s ${signal} $pid"
    echo $cmd
    eval $cmd
    for i in {0..19}; do
      if [ $(ps -p $pid|wc -l) -lt 2 ]; then
        echo "pid $pid no longer exists"
        return 0
      fi
      sleep 0.1
    done
  done
}

Use Multiple Ruby Engines in the Same Project

One of the biggest pains of using jruby is the slow startup time.

For a trivial rails application, the startup is really painful:

1
2
3
4
5
$ rvm current
jruby-1.7.11
$ time rails runner "puts 'Hello'"
Hello
rails runner "puts 'Hello'"  24.82s user 0.83s system 223% cpu 11.457 total

Compare to the same project running MRI:

1
2
3
4
5
$ rvm current
ruby-2.1.1
$ time rails runner "puts 'Hello'"
Hello
rails runner "puts 'Hello'"  1.14s user 0.19s system 98% cpu 1.355 total

MRI is more than 20 times faster!

The REPL: Issue 1

Today, I am starting a new feature for this blog. I am calling it The REPL. It’s pretty much a link page of interesting reading I have done around the web in the last week (or, more than likely, since the last issue). Of course, this is not a new idea, but I still think there might be some value to it. I will try to avoid this becoming an echo chamber and instead I will try to focus on material that has got me thinking about software engineering.

The Circuit Breaker Pattern

Martin Fowler explains the circuit breaker pattern. Coincidentally at work, we have been discussing using something like this for building in fault tolerance in our interactions with other services. Netflix has a library (in java) for this sort of thing and has blogged about it’s use. Embracing that failure will happen and properly preparing for it turns how you design your code on its head.

Using Interactors To Clean Up Rails

The fellows at Grouper explain how they are using the interactor gem to extract business logic from controllers and models. Again, this is a pattern that we adopted at work not too long ago. DHH gave it some flak on the hacker news comments, but it has given our team a convention on where and how to code business logic.

Store Data Not Types

A cautionary tale on why it’s important to set clear boundaries between your system and the libraries and frameworks that you use.

2014 LA Ruby Conf

Last Saturday I had the pleasure to attend LA Ruby Conf for the first time. The conference has two days of workshops, which I did not attend and one day of single-track talks.

I had a great time and think the organizers did a great job. The talks were varied and interesting, with enough breaks to also take advantage of the “hallway track”. It’s always great to talk to the other developers.

Confreaks taped videos of the talks, but they are not yet available.

See you next year, @larubyconf