Monday, December 10, 2007

Merb Tidbit: Logging

Merb has it's handy built in Mongrel server, so you can easily start it up while developing with:

However, you may wonder "Why isn't it generating any log files?"

Well actually it is, but the deal is they are all being output to the command line instead of being written to a file in the log/ directory. If you want to have them written to a log file, you need to start Merb up as a daemon. This is simply done like so:
merb -d
Now your logs will be written to the log/ directory. To stop the background merb process, use the -k PORT flag. For example, if you are running on port 4000 (which is the default) you would use:
merb -k 4000
You can also control the level of detail to be logged using the -l flag. Optional logging levels which can be passed with the -l flag include: DEBUG, INFO, WARN, ERROR and FATAL.

That's today's Merb tidbit. Happy Merbing!

Thursday, November 15, 2007

Rails on Swiftiply / Mongrel

Hosting Ruby on Rails is complicated, right? Not necessarily. Let's take a look at a fast and flexible way to serve up your Rails application.

Rails on Swiftiply / Mongrel
If you have done any reading or work with Rails you have probably heard of Mongrel. According to the Mongrel site, "Mongrel is a fast HTTP library and server for Ruby".

You may not have heard of Swiftiply yet. But you will. Well, actually I guess you just did. But you will no doubt be hearing more about it. Swiftiply "is a very fast, narrowly targetted clustering proxy". The Swiftiply website says "scaling your web applications should be easy". Sounds good to me. Let's see if it is!

We will assume that you have already properly installed and configured the following:

Version Info
Here are the most recent versions tested at the time of this article.  Different versions may cause varying results.
  • OS: Ubuntu 7.10
  • Ruby: 1.8.6
  • RubyGems: 1.0.1
  • Swiftiply:
  • Mongrel: 1.1.3
  • Rails: 2.0.2

Installation: It's a breeze.
sudo gem install mongrel --include-dependencies
sudo gem install swiftiply --include-dependencies
I told you it was a breeze.

Configuration: Piece of cake.
Let's go ahead and configure Swiftiply first. Swiftiply does not install a configuration file for you, so you are creating a new blank file in the following step:
sudo vim /etc/swiftiply.conf
Here is the configuration that I used:
cluster_address: 123.45.678.9  # Use your IP here
cluster_port: 80
daemonize: true
epoll: true
epoll_descriptors: 20000
- incoming:
outgoing: # Where Mongrels will connect
default: true
docroot: /var/www/ # Rails root
cache_directory: public
redeployable: true
- htm
- html
- txt
Amazingly that is all that is required in the way of configuration. If you wanted to serve up other applications on other domains or sub-domains, simply repeat the "map:" section for each.

Start up Swiftiply with:
swiftiply -c /etc/swiftiply.conf
With Swiftiply running, now all you need to do is start Mongrel(s) from within the directory of the Rails app you wish to serve. We let the system know that we want to use the special Swiftiply version of Mongrel with the "env SWIFT=1" directive. We also tell them to connect to the IP and port that you defined in your swiftiply.conf, like so:
env SWIFT=1 mongrel_rails start -d -a -p 30000

You may also wish to include the directive "-e production", but I ran out of room on the line! ;)

Now if you want multiple mongrels serving up your app, just start another one up exactly the same. Same IP and port.

And now... your done.
And that is it. You have your basic Swiftiply / Mongrel stack setup.

Keep your eyes on Swiftiply as there will be some exciting new features be adding in the coming weeks and months.

With a blank Rails 1.2.5 application I show the following memory usages in "top":

Ruby (Mongrel): 47M
Swiftiply: 17M

For some statistics on performance of Swiftiply, please see the post "Testing Various Configurations of Rails, Merb, Swiftiply and Nginx" on Webficient.

Stuff To Know
Here are a couple things to remember about Swiftiply as you are setting it up:
  • Each application you wish to serve will be linked to ONE port.
  • All mongrels serving that application will connect to the exact same ONE port.
  • Even if you have (n) mongrels, they all connect to the exact same ONE port per application.
  • Swiftiply can serve multiple applications, just repeat the part from "map:" down in the swiftiply.conf file assigning your new application a single unique port.

Monday, November 12, 2007

Book Review: Pro Active Record

Title: Pro Active Record: Databases with Ruby and Rails.
Authors: Kevin Marshall, Chad Pytel, and Jon Yurek

Font size and layout are good. Easy on the eyes. Large and frequent sub-headings make it easier to locate information.

The book lists it's intended "User level" at "Intermediate-Advanced".

It really depends on what you are expecting. I've been using Rails and ActiveRecord for about 2 years, so I should fit into the target audience. After reading the book I think it will be a great reference book to have within arm's reach while working with ActiveRecord. To me it will serve as an API to AR. So it will be practical in that sense.

On the other hand, while reading it I never experienced any "aha!" moments where I felt like I learned something new or exciting, which I had hoped for.

If you are a beginner (never having used AR) it will definitely save you time (and eye strain) hunting down tutorials on blogs.

It's a good Active Record reference & usage tutorial(s). I would have appreciated this book even more when I was first starting to use the Ruby on Rails framework. So if you are a beginner, don't let the "Intermediate - Advanced" user level scare you off. Active Record is not a terribly complicated subject, and if you are using Rails (as a beginner or not) you will probably be using Active Record too.

I was kind of surprised when I read the Introduction to the book that it starts off with:

"Is there really enough to talk about in Active Record to fill a whole book?"

"Our answer, then and now, is, "Yes and no""

As an "Intermediate - Advanced" user, that's kind of how I felt at the end of this "Pro" book.

Wednesday, November 7, 2007

Merb & Datamapper: Getting Rolling

Today we want to take a look at Merb and DataMapper.

NOTE: I'm doing this run through on OS X. If you are using a different OS, some of the instructions may need modifications (specifically in regards to path locations). This post also assumes that you are using MySQL, which you should already have installed (including the MySQL gem).

Merb: A Web Framework.
Yesterday marked the 0.4 release of Merb. At this point it should be fairly stable. Stable enough to make it, at the very least, worth a run through. A few months have passed since the original tutorial, and since then Merb has released versions 0.4.1, 0.4.2, 0.5.0, 0.5.1, 0.5.2 and 0.5.3. Since 0.5.3 there has been a large amount of work done in putting together the 0.9.x release. At the time of this update, 0.9 is a "developer" release. I will be updating these instructions soon.

Merb, like Ruby on Rails, is an MVC web framework. The Merb project has goals of being performance oriented and providing flexibility through plugins. This should allow a developer to better mix and match available tool sets to the specific needs of any given project.

One of the areas of flexibility that Merb provides is in the use of an Object Relational Mapper (ORM). You may have heard of, or be familiar with, ActiveRecord which is the ORM provided by default within the Ruby on Rails framework. You can use ActiveRecord with Merb, but you also have other ORM options such as DataMapper and Sequel.

So let's get started.

Installation (outdated - still is 0.4 based)
First off you need to get Merb & DataMapper installed on your machine. Assuming that you already have Ruby and Gems installed on your system, installation is as simple as:

sudo gem install merb --include-dependencies
sudo gem install datamapper
sudo gem install ruby2ruby --include-dependencies
sudo gem install merb_datamapper ??
UPDATE: Merb does depend on the json gem (json_pure if you want to use it on jruby). This "should" be installed when you install "merb --include-dependencies", but some readers have reported that it wasn't. So just to be safe, run:
sudo gem install json
Lastly, we need to make sure DataObjects.rb drivers are installed. You should now be able to install as a gem:
sudo gem install do_mysql
UPDATE (12/11/07): benr75 reports: "The do_mysql gem is currently broken and refers to an absolute path for MySQL that may not exist on users systems. Fix instructions here."

Other possibly useful resources are: post on Blog::Heimidal and the DataMapper Getting Started page.

Assuming everything went smoothly for you, we are now ready to roll.

Generate & Configure Your New Merb Project (updated to 0.9)
Next we will be generating the default framework files.

Change to the directory where you wish to create your Merb project. For me that was:
cd /Users/justin/programming/projects/
Similar to Rails, to generate the framework code we simply run:
merb-gen project_name
cd project_name
As mentioned before we need to configure our Merb application to let it know that we want to use the DataMapper ORM, and setup our database. Pretty simple stuff. Just a few text edits in 2 files.

First, open config/init.rb and find and uncomment the following line as below:
### Uncomment for DataMapper ORM
use_orm :datamapper
The only other file we need to setup is our database configuration file. When you initially generated your project code Merb did not create this file. Why? Because you hadn't yet told it what ORM you wanted to use.

Since we have edited the dependencies.rb file to indicate we will be using the DataMapper ORM, all we now need to do is load the Merb framework and it will auto-generate a sample database configuration file for us. This sample file will be based on the specific requirements of the ORM we have chosen. So from the command line run:
Easy. Merb saw that you wanted to use DataMapper, but no database has been configured. Automatically the database.sample.yml file was then generated. Now let's finish up our configuration of Merb. Open config/database.sample.yml and edit it according to your specific setup. For example mine looks like:
# This is a sample database file for the DataMapper ORM
:development: &defaults
:adapter: mysql
:database: merbtest_development
:username: root
:host: localhost

<<: *defaults :database: merbtest_test :production: <<: *defaults :database: merbtest_production
Don't forget to copy or rename the file to database.yml.

Also, the databases that you just configured in database.yml need to actually exist, so if you haven't done so already please take a moment to create them now.

That's It!
With those two simple configuration steps, our bare bones application should now be ready to roll. To start up, from within your application directory type:
By default Merb is setup to run on port 4000 of host So open up your browser and point it to:
You should now see the Merb default page before you.

If you wish to adjust the IP address or port number that Merb runs on, that is configurable from the config/merb.yml config/init.rb file.

That's it for this post. In the next post we will actually make our Merb app do something.

Until then you can get some basic ideas of how to wire things together in this post on

Tuesday, August 28, 2007

Package Tracking & RSS: A Natural Fit?

I have a badly needed printer on it's way.

It is being shipped by UPS. If you are like me, and have some obsessive compulsive type tendencies, you probably check the package tracking more often than necessary.

As I refreshed the UPS page today for the 2nd or 3rd time to find out that still nothing has changed since yesterday, I thought:

"Wouldn't this be a good fit for RSS?"

What do you think?

If you had a choice of a personalized RSS feed that automatically updated in your favorite RSS reader as your package's status changed, would you chose and use that over a web page?

Any other seemingly obvious fits for RSS that you have stumbled upon?

Love to hear your thoughts!!

In a short period of time I recieved a comment from "SAI" providing a link to the "Universal Package Tracking" offered on

According to the site it will accept tracking numbers from UPS, FedEx, USPS, or DHL/AirBorne. I entered my UPS tracking number, and it worked as advertised. A RSS feed was created for my shipment, and a Google Map showing each location that it stopped at as it progressed to delivery.

Great find SAI! And next time you have a package to track, check out iSnoop's tool.

Tuesday, June 5, 2007

Time Inventory: Do you keep track?

Every business sells something.

For many businesses this "something" is a physical object. For instance, when I was 16 I worked at a deli in the North East. We sold things like sandwiches, coffee and soda.

What do you sell?

If you are reading this blog most likely you provide some service. In essence you sell your time.

Back at the deli (or any business that sell physical goods) a regular inventory was kept. This helped to keep track of ordering needs, but also could be used to make sure that product wasn't getting stolen and to otherwise double check sales numbers.

Do you keep an inventory of your time?

To do so you need to keep track of 2 basic things.
  1. Time Coming In (X)
    How many hours are you going to work a week? If you have a set 40 hour schedule, then your business "receives" 40 hours every week. If you don't have a set work schedule, then you will need to track how many hours you spend "working" (whether you actually are or not).

  2. Actual Time Sold (Y)
    Simply keep track of your billable hours.
Once you track these two numbers it is beneficial to do a weekly (or at least monthly) "inventory" check.

You had X hours come in, and although all X hours are now gone from your inventory - only Y hours were sold.

At the deli it wasn't expected that every single item would be sold. Some inventory items were required to keep things running: bags, napkins, condiments, straws, etc. Also, the employees were allowed free drinks and food while on the job. That was a perk. As a 16 year old guy free roast beef sandwiches were more important than 401K plans!

Likewise, you shouldn't expect that you will be able to sell every hour of your inventory of time on a weekly basis. You have other non-billable tasks to take care of and the occasional job perk (time you use freely as you please). But by regularly reviewing these numbers it can reveal disturbing trends.

What does your inventory reveal?

Does your inventory analysis show that you are losing an unacceptable amount of time to non-billable activities? Are you being robbed blind? If so, you may need to put forth some serious effort to identify those time thiefs and develop a security measures to protect yourself against them.

Finally by recording these numbers on a long-term basis you can analyze larger trends. Are your billable hours going up, down or staying level over the last 3 to 6 months? By introducing new Product-X or Methodology-Y what was the impact on your billable time?

Technorati Tags: , , ,

Wednesday, May 16, 2007

Ever wanted to bounce something off someone?

As a web worker I find on occasion the desire to bounce an idea off of someone else. Being that I generally work by myself there often isn't someone physically there to discuss with. IRC and forums can help in that regard.

Today I found an interesting site that allows you to present a short question, and receive responses from the world at large. You have no idea who will respond, so responses should probably be taken with a grain of salt. Nevertheless it allows you an opportunity to tap into the "crowd" and see if perhaps it will give you a fresh outlook.

Site: BrainReactions

Technorati Tags:

Tuesday, May 15, 2007

Ruby on Rails vs The World

Ruby on Rails may not be perfect, but it sure lives up to it's tag line "Web development that doesn't hurt."

The guys over at Rails Envy are putting together 4 "Hello I'm a Mac" parodies for Ruby on Rails.


#1) RoR vs Java
#2) RoR vs PHP

Check their website for the final two, which will be presented tomorrow (May 16) and Thursday (May 17).

Technorati Tags: ,