The Blog

Merb: A Memo

You may or may not have heard about the lightweight Ruby web framework Merb http://merbivore.com/. Merb stands for Mongrel + Erb, but it's a whole lot more than the name might imply. I've been using it over the past few weeks to build a file upload app which will coincide with the main application built in Rails.

It's worth asking what the main distinctions are between the frameworks and why you might want to use one over the other. Whereas Rails is the framework that has lowered the barrier to entry for many people, Merb brings performance and purity to a clever but sometimes obfuscated world. If you're an MVC buff like me, you'll appreciate the attention given in making each of the parts (Model, View, and Controller) independent and therefore replaceable. A great example of this can be found in the choices of supported ORM (Object Relational Mapping) libraries; something Rails doesn't offer out of the box. Merb also provides you with a straightforward way to use any template engine you'd like, very similar to Rails' implementation.

Unlike Rails, Merb is thread-safe. To illustrate the difference, imagine a one-way road with a single lane (a process). In a non thread-safe environment, cars can only travel down the road single-file, one after the other (each car being a thread). Having a thread-safe environment simply means that our road can handle more than one lane and allow cars to travel alongside one another (share process resources simultaneously). In practical terms, this means a single Mongrel instance can handle multiple file uploads simultaneously.

Merb is truer to Ruby than it is to making sure web development doesn't hurt. I'm not saying building an application with Merb is painful, but you will need a bit more Ruby prowess than Rails demands. Tradeoffs are a fact of life, so in many cases learning more Ruby and using Merb can mean far better performance.

Using the right tool for the right job is important. I highly recommend checking out Merb and using it when applicable.

Jordan Fowler

sciĀ·on

Etymology can be an extremely interesting subject. Today, while researching various things for work, I came across a reference to the word 'scion.' In all honesty I had never heard the word used outside of the context of the car company Scion.

I decided to look up the definition of the word and found out it means: "A short length of stem, taken from one plant which is then grafted onto the rootstock of another plant." * You may or may not know that the company Scion is owned by Toyota but maintains an entirely different brand/image. Someone at Toyota got a raise for that one :).

See, aren't words interesting when you dive a little deeper!

* Glossary of Gardening

Ruby on Rails Stack (Part 1)

I've had some difficulty pulling together disparate pieces of information from questionable sources across the internet on the best way to go about building a Ruby on Rails stack on top of Debian 3.1 (Sarge). This operating system is widely considered one of the best for web servers. After banging my head against the wall for a while, I decided I'd just start from scratch and build this stack from the ground up.

Web Host and Operating System

Choosing the right host can be difficult. Shared Hosting has for the most part gone by the wayside and virtualization-based (VPS) hosting has become a cost-competitive replacement with plenty of added benefits. RimuHosting offers great VPS options with many OSes to choose from.

Through my experience with various flavors of Linux, Debian based systems have proven to be solid and reliable. Debian 3.1 (Sarge) is my preferred choice of OS for web application server stacks for its proven robustness and security. Whether you go with RimuHosting or not, the rest of this post assumes you're using Debian 3.1.

Virtualization at home

One thing that can be helpful in putting together a server stack, is having a sandbox to play around in. With the multitude of options available in the virtualization space today, it's becoming easier and easier to run any number of virtual machines on a single physical computer. Since I'm on a Mac, I run Parallels Desktop and mess with a local virtual machine before ever touching my production system.

Starting from a Debian 3.1 (Sarge) base install

At this point, I will assume you have a Debian 3.1 (Sarge) base system installed and you are comfortable installing software from source code. The first thing we need to do is add some source locations for Debian. Open the file @/etc/apt/sources.list@ in your favorite editor and replace the contents with the following:

deb http://http.us.debian.org/debian sarge main contrib non-free
deb http://non-us.debian.org/debian-non-US sarge/non-US main contrib non-free
deb http://security.debian.org sarge/updates main contrib non-free

Save the file and run the following commands (after calling su, you'll need to enter your root password):

su
apt-get update
apt-get upgrade

It's a good idea to install @sudo@ so that you don't have to always be running around your system as the root user. Bad things can happen when you're root and you type in an unintentional command. Having @sudo@ means you only use the power of root on a per-command bases, i.e. less possibility of error. Here's what to do:

su
apt-get install sudo

Now, open up @/etc/sudoers@ and add yourself like so:

your_username   ALL=(ALL) ALL

Save the file and you are now a sudoer.

Your Debian system should now be ready to handle the forthcoming stack.

Nginx front-end web server

For a front-end web server, I've chosen to use nginx. Despite its relative obscurity, it has proven to be a lightweight, high performance replacement for something like Apache. You can however run whatever front-end web server you like.

Dependencies

We'll be downloading/compiling/installing three libraries (pcre, zlib, and openssl) before we install nginx:

apt-get install zlib1g-dev libgcrypt11-dev libpcre3-dev libssl-dev

Installation

Now it's time to install nginx. I will be installing from source, so you'll need to be comfortable with this. If there is a newer version of this source code (since this writing), feel free to get that instead. Here we go:

wget http://sysoev.ru/nginx/nginx-0.5.30.tar.gz
tar zxvf nginx-0.5.30.tar.gz
cd nginx-0.5.30
./configure --pid-path=/usr/local/nginx/logs/nginx.pid --sbin-path=/usr/local/sbin/nginx --with-md5=/usr/lib --with-sha1=/usr/lib --with-http_ssl_module --with-http_dav_module
make
sudo make install

Startup/Shutdown script

We'll need to add the startup/shutdown script for nginx:

wget http://notrocketsurgery.com/files/nginx -O /etc/init.d/nginx
sudo chmod 750 /etc/init.d/nginx

And let's make sure nginx is started upon a system reboot:

update-rc.d nginx defaults

Ruby, RubyGems, Rails, and Mongrel

Ruby 1.8.6

It's time to install ruby. I chose do do this from source so that you'll have the latest version 1.8.6. Here we go:

wget ftp://ftp.ruby-lang.org/pub/ruby/1.8/ruby-1.8.6.tar.gz
tar xzvf ruby-1.8.6.tar.gz
cd ruby-1.8.6
./configure
make
sudo make install

RubyGems

Next we'll need a Ruby package manager called RubyGems. This will be our gateway to installing Ruby on Rails as well as a whole plethora of other libraries. I've chosen to install this from source for the same reason as Ruby, here's how:

wget http://rubyforge.org/frs/download.php/20989/rubygems-0.9.4.tgz
tar xzvf rubygems-0.9.4.tgz
cd rubygems-0.9.4
sudo ruby setup.rb
sudo gem update --system

Ruby on Rails

Last but certainly not least, time to install Ruby on Rails. It's pretty simple too:

sudo gem install rails --include-dependencies

Mongrel

Mongrel will be our Application Server(s). The way it works is, you'll start up a cluster of Mongrel instances (bootstrapping your Rails app). Nginx will then proxy requests to one of these instances (once we've configured everything). This is the last piece to a great stack upon which we can place our rails web applications:

sudo gem install mongrel mongrel_cluster --include-dependencies

Mongrel Startup/Shutdown script

Just as we've done with nginx above, we need a script that will handle starting and stopping our mongrel_cluster:

sudo ln -s /usr/local/lib/ruby/gems/1.8/gems/mongrel_cluster-0.1.3/resources/mongrel_cluster /etc/init.d/mongrel_cluster

Let's also make sure our clusters are started after a system reboot:

sudo /usr/sbin/update-rc.d mongrel_cluster defaults

To be continued...

This concludes Part 1. Very soon, I will complete Part 2, which will guide you through installing Capistrano for deployment as well as Mongrel, Capistrano and nginx configuration. Cheers!

The Shire

Whenever I describe my hometown of Missoula, Montana to people, I always refer to it as "The Shire." This place has never, in all my years lost its charm nor its place in my heart. Many famous authors have written passages and entire novels recounting its ethereal beauty and allure. One such novel, A River Runs Through It by Norman Maclean was later adapted to screenplay and made into a film. Starring Craig Sheffer and Brad Pitt, the film went on to be nominated for three Oscars, winning Best Cinematography (1993).

There is most definitely more picturesque and stunning places to go in the state, but that's not what makes this place so special. Sure, it has a river running through it, bike trails everywhere, and plenty of other reasons to never stay inside, but this still doesn't quite explain it.

The simple fact is that, no matter how incredible a place is on the outside, it's the feeling one gets that will make a lasting impression. In other words, the people who inhabit a place and whose values become impressed therein are what make something truly valuable and worth noting.

Here in the Shire, it's not quantity that matters, it's quality. And that is what I believe makes this place so special.

Shared Hosting vs VPS

When I initially launched this new site, it was being hosted on a TextDrive Shared Hosting plan (so slow). As of last night, I've switched to my Rimu Hosting VPS plan (snappy). I've left the caching I setup in place, but now I'm wondering about other ways to tune for speed.

Here's my setup:

  • Nginx frontend web server
  • Mongrel clusters (3) for application servers
  • Full page caching for /, /about, /contact, /gallery

I would like to get a discussion going here or elsewhere about tuning a server for speed. Leave a comment with relevant links, comments, etc.

Daring Fireball, Apple's Free Marketing

I'll admit it, I read Daring Fireball. It was one of two default feeds I actually kept when I installed NetNewsWire. As I was reading a more recent post of his (Josh Quittner Returns His iPhone), it suddenly struck me. This guy would literally buy a shit pancake from Apple (and defend it) if they sold one.

Don't get me wrong, I am a huge Apple fan and have been one since I was 8 years old. It is the only kind of computer I own and the only computer I see myself owning in the foreseeable future: so long as OS X exists. You might ask, "Why don't you defend Apple with the same conviction and irreverence then?" I'll tell you why. Apple is just a company, who's goal is to generate incredible buzz and then make optimal profits off of you and me.

DF, however, approaches the situation as if he's Gandhi, defending the oppressed people of an occupied nation. In reality, Apple customers are far from oppressed peoples. The fact is that they are pretty well-to-do if they can afford to buy an iPhone.

Call me bitter, but I'm just calling it how I see it, and I was annoyed by what I saw. In closing, DF, Apple should be paying you. They sure as hell don't need free marketing.

Using CSS Vertical Rhythm

I've updated this site to use a technique known as CSS Vertical Rhythm. This method makes web pages far easier to read and scale perfectly to text resizing. The approach is based on simple proportionality in order to form a rhythm.

If you simply focus your eyes on how the spacing of the lines of text are proportional to the spacing between the lines and paragraphs, you'll begin to see the rhythm. Though I am not a designer, it is clear to me how effective these techniques can be. Here are some helpful links: