PayPlay.FM development.log

Tuesday, March 24, 2009

metal and activerecord

I've tried to move some small actions to Metal to make it faster but it actually became even slower.

Benchmarking localhost (be patient).....done

Server Software: Mongrel
Server Hostname: localhost
Concurrency Level: 1
Complete requests: 25
Failed requests: 0
Write errors: 0
Requests per second: 0.83 [#/sec] (mean)

Percentage of the requests served within a certain time (ms)
50% 5
66% 6
75% 45
80% 5007
90% 5008
95% 5009
98% 5010
99% 5010
100% 5010 (longest request)

At first I thought something was wrong with my code (as it usually happens) but numbers show that metal became equally slow after first several super fast calls. Commenting parts of my code made clear that it has something with AR because code without find() worked fine.

The answer told by Google was to call


before returning resulting array from call.

Metal wins with ~240 req/s when ActionController was almost twice slower.

Labels: ,

Tuesday, February 10, 2009

what is Rails now?

I thought about this post long ago, but yesterday found great similar post by Josh Susser.

I started writing rails sites about four years ago. It was something like 0.12 version and I still have CHANGELOG file in RAILS_ROOT of my first working rails site. I don't mean I am a guru/old-school hacker- I'm not. I just want to say that I can see difference between Rails start and where it is now.

Rails was simple and it was its most promoted feature - you could watch screencast, read couple of brochures like "rails in 4 days" and that was all - you were able to begin working with rails. Even without seeing ruby before.

Remember picture with pack of java books against two rails manuals? Many things changed since then.

Now to start new rails app, lots of decisions need to be taken: choose template engine, choose testing suite, choose ORM, choose javascript library. Rails became a skyscraper where every stage can be different. With Rails 3.0, when merb is merged in, things will be even more complicated.

You can't specify application environment just by calling it Rails. From now you need to clarify what your Rails is (haml,mocha,datamapper,prototype) or (sequel,erb,rspec,jquery) or whatever else you want to use.

Yes, you can use default options. But you still need to know other options if you want to be competitive. I think this 'flexibility' might be scary for beginners - there are too many options, too many ways of doing similar things.

I don't want to say that freedom of choice is bad thing. I just think rails is too fragmentized now. Maybe it is growth problem and it will be solved in future with something like common interfaces or by abandoning some technologies.

Labels: ,

Monday, January 19, 2009

mediatemple: mtr start

If you see messages like this

"application started, but pid file was not found, check 'mtr status' "

when doing mtr start/restart, it could be caused by several reasons: first, you need to read RAILS_ROOT/log/*, if it does not help - check your config/environment.rb for initializing RAILS_GEM_VERSION - rails version on (mt) can be different from your dev server.

Next thing to check is whether your gs-container is capable of working with your app. When you try to run several apps on default free 64M Container (and that was my case), the earliest process will be killed and you'll get no messages but this default 'pid was not found'.

Labels: , ,

Friday, November 28, 2008

apache and %2F

If you are running rails on passenger and sometimes get apache internal 404 errors, this can be because by default apache doesn't handle urlencoded chars like '%2F' (/). In this case it won't even get to rails and will only appear in access_log with 404 status.

Solution is pretty simple - just add AllowEncodedSlashes On to virtual host section.

Labels: , ,

Friday, November 21, 2008

Mailer Callbacks: hooks for ActionMailer

I've just published tiny library that I wrote on weekend and gonna use on production.
It is an extension to ActionMailer that gives two useful callbacks for your mailer classes: before_deliver and after_deliver. "before_deliver" helps to cancel delivery under certain conditions, "after" filter is usually for saving/logging sent emails.

That was the first release but it is stable enough to work.

Labels: , ,

Tuesday, November 18, 2008


I don't think that populating @page_title in controller's action, that can be seen in almost every controller, is the 100% right thing. Why controller if it surely belongs to view?

capture helper looks much more reasonable.

Labels: ,

Tuesday, September 09, 2008


right now I'm in the middle of setting up new payplay server with completely new configuration.

For a long-long time PayPlay.FM was running under lighty + fcgi/mongrel_cluster.
It worked but had a lot of problems starting with lighty's poor mod_proxy (resulting in 100% CPU load just because it can't re-enable crushed proxy) and ending with huge memory eating. We had like 5 mongrels, 200 Mb each. Awful. If you add 1G for memcached, and 700Mb for mysqld, you'll find that you've got not so much memory as you expected.

So here is what I change now:

1. enterprise ruby authors claim it has 33% memory benefit which is great.
2. passenger aka mod_rails

Some notes for future:

1. if you can't see your assets (css,images, 403 forbidden) - just add "allow from all" to the end of your VirtualHost's Directory section.
2. remember that passenger will run under user that is owner of config/environment.rb (+ one root spawner)