Rails: find controller for a path
Huh, seems simple to do :p, but I’ve been seeking for a while to find the answer and dig into rails code to find a simple method to retrieve the controller of a given path (could be useful to build a navigation). There it is:
ActionController::Routing::Routes.recognize_path(path)[:controller]
Ebb, even faster than Thin
Ebb is new server to put in front of a rackable ruby application.
Have a look to the Ebb website to get some comparison with other app servers.
sudo gem install ebb
What I needed to do before on Mac OS X (leopard with MacPorts):
sudo port install glib2
Git: Easy way to setup a private remote repository
Git is different from svn and create a private repository on a remote server too. No need of gitosis or git-daemon for this.
I start from an existing project and a server I already access to with ssh key.
First, initialize git in your project:
git init git add . git commit -m 'initial import'
[update]
Then create a git copy of your project into a git archive my_project_folder.git.
git clone —bare my_project_folder my_project_folder.git
Copy this archive the .git folder to your remote server:
scp -rp .git user@server://path/to/repositories/my_project_folder.git
Add this new repository in the config of your local project:
git remote add my_remote_repo ssh://server/path/to/repositories/my_project_folder.git
You’re done. After a change you can commit and then push your change to the remote repo:
git commit -m "message for change log" git push my_remote_repo
Use your own parameters for:
- my_project_folder with the folder of your project
- path/to/repositories with the path to your repository on the remote server
- my_project_repo with the name you want for the remote repository, usually origin
If you need a public repository, have look to gitosis or git-daemon. Best is Github.
Webby as a powerful wiki-like notebook
Introduction
I have often look at wikis, trying to find a nice tool for taking my notes and formating them. Have many ideas in my head, like to write them down and visualize it. Wiki is great for that but always a bit heavy to “deploy”.
Continuesly seeking for new ruby things, I heard about Webby, a lightweight web publishing system. Simply taking your pages (textile, html, erb, aso…) and generate a static website. Run Heel on it and you will have a perfect light but very powerful wiki-like web site. Extension are perfect for programming notes including graphiz and syntax highlighting.
Setup your notebook
sudo gem install webby
This will install several gems, included heel.
more coming…
Model inheritance with Merb
from help on irc#merb
I had recurrent issue about inherit a model class from another one in Merb, using ActiveRecord or DataMapper. As it’s ‘magicly’ done on Rails I though the same way in Merb, but the last one load model class in alpha order. then what you have to do is to load the first class with a require:
in your first file:
class Page < ActiveRecord::Base end
then in second add the require:
require 'page' class ActivePage < Page end
Simply using ruby…
Most used front end: poll results
For severals month now I put a poll about which front end people use for their website. Even if it s not a reference with only 85 votes I would like to publsih some result. Of course as the content of this website is ruby oriented, then the results will be also.
First it started with most of votes for apache. At the end Apache it’s still the first:
- 47%: apache
- 40%: nginx
- 7% : lighttpd
- 5% : others
The result for nginx is over general real stats but for the trend is here and nginx is more and more the choice for a ruby stack as I did present in my last post
Rmagick on Ubuntu
I found other libraries as librmagick but it seems to have better solution:
# libmagick9-dev ?
sudo apt-get install libmagick++9-dev ruby1.8-dev
wget ftp://ftp.fu-berlin.de/unix/X11/graphics/ImageMagick/ImageMagick-6.3.8-9.tar.gz
tar xzf
./configure —prefix=/usr
make
sudo make install
sudo gem install rmagick
Scaling a Rails app (Part 3 of 3)
This the third and last part for a summary about solutions to help better computing of your rails app
Some home made benchmarks
NB: Following benchmarks have been made to a quick look study and not for a proof of concept.
The test machine (dedibox, ubuntu 6.10) is 1 core cpu @2Ghz – 1024 Mo memory. In each case the http server uses 10 processes on a real world application (not just ‘hello world!’). Sending 500 rq with 1 or 10 concurrency req:
| conc. req. | 1 | 10 |
|---|---|---|
| apache | ||
| mongrel | 39.4s – 12.7 r/s | 21.9s – 22.8 r/s |
| thin | 37.6s – 13.3 r/s | 17.7s – 28,15 r/s |
| nginx | ||
| mongrel | 39.2s – 12.8 r/s | 22.2s – 22.5 r/s |
| thin 0.5.4 | 39.8s – 12.6 r/s | 17.7s – 28.15 r/s |
| thin 0.6.1 socket x2 | 37.6s – 13.3 r/s | 17.8s – 28.1 r/s |
Since last time, Rails world has a new nice app server: thin. Replacement of mongrel, based on rack interface, it’s also recently added a unix socket connector where usually we use IP connector. For better performance, avoid longest stuff as scripts (google analytics). Other scripts/images/css are keys in http performances also, usage of assets in recommended.
As we can see in equivalent configuration there is no major difference for http server. Thin seems to be definitly faster than mongrel when you need to server more than 1 request at a time. And of course on a 1 core cpu, having more than one app server doesnt make the content served really faster.
Memory usage
Mongrel (48 Mo) → Thin (40 Mo) less 15%
Apache (10 Mo) → Nginx (1.4 Mo) less 85%
Finally I decided to move to a nginx / thin on socket configuration because of the memory usage and the fair performances. I even moved my PHP stuff with an fcgi connector.
Other ideas of tests: Varnish, Nginx and memcached. Maybe next time :)
[update]
Please find a good benchmark about nginx vs apache on Joe’s blog
Overall conclusion
I think when we need to compare two framework, about which one is faster, we should keep in mind all these levels of optimisation to scale an application, and then the raw performance is a secondary issue.