Archive for the ‘ruby’ Category

mod_rails - the tryout - the success

Friday, September 5th, 2008

Some months ago I wrote this post: mod_rails - the tryout - the failure (for my situation) where I addressed my problems running a RoR application on a VPS using mod_rails.

In the meantime, according to their blog, the Phusion guys have addressed this issue:
In the last couple of days I took the chance to try it once again.

And today, I am a lucky guy. Having a stable webapplication running under mod_rails and Ruby Enterprise Edition.

It’s stable, phreaking fast and the memory footprint is great (even better than a mongrel system).

mod_rails really is ready for VPS enviroments!

viennastreetstyle.com

Tuesday, May 27th, 2008

ViennaStreetStyle

Some days ago my first Rails application went live:

ViennaStreetstyle.com - ViennaStreetStyle is a simple photo gallery showing people on the streets of Vienna, Austria presenting their own style of street fashion.

I developed this application for friends of mine who had the idea for ViennaStreetstyle.com.

Development was quite straight-forward without any kind of a big suprise by using the following plugins/libraries:

  • attachment_fu
    For uploading and handling the images
  • geokit
    for locating the shots on the map of Vienna
  • YM4R
    Greatest plugin for doing all the GoogleMaps stuff
  • prototip
    Javascript library for easy rendering of complex tooltips

The whole system is running on a busy 256 MB VPS under Mongrel with 2 server instances (so in best condition to get slashdotted or sth like that).
But it is somehow an experiment for me how far you can go with that low server specs.

mod_rails - the tryout - the failure (for my situation)

Monday, April 14th, 2008

Some days ago, I have introduced you to mod_rails. I totally freaked out by the idea to let RoR running inside of Apache. Just without using FCGI or proxying Mongrel.

Though, I had not much spare time this weekend, I just had to try it out!

First of all:
You guys rock!!! These guys just impressed me how well-thought a first release version can be.
The whole setup and Apache configuration is so damn easy - you can’t go wrong. The setup script even detects missing linux packages and tells you exactly what to do, depending on the hosting distribution.

So I switched one of my RoR applications to mod_rails …..

But after using it for some minutes I got heavely disappointed. It is just no good hosting option for my situation: [My server is a Debian VPS with 265MB-768MB burstable]

The memory consumption the machine went up from 280MB (wo/ mod_rails) to over 700MB. So all my applications started vomiting, because there was no memory left. Only killing apache2 processes helped me to solve the situation.

So I thought, I will be a good guy and RTFM. I stepped across this configuration parameter:

RailsMaxPoolSize <integer>

The manual recommended to set this parameter to “2″ for servers with small memory footprint.

So I did, but it was no help. Same memory consumption by all apache2 processes.

The next step was to not include the mod_rails module in apache. No help, either. So mod_rails wasn’t even running anymore and the memory consumtption was still beyond the pale!

So, the only reason I can imagine, is that one of the newly installed gems (axpr?) and not mod_rails directly is causing that big memory mayhem.

Huh, restoring a backup of my server was the only help to get rid of the situation!!!

What do you think? What might be the cause of my situation?

Phusion Passenger (a.k.a. mod_rails)

Friday, April 11th, 2008

As it seems a new star is born on the “Rails-How to-host” sky!
Phusion Passenger

After reading some posts, it seems to be a first rock-solid “mod_rails” implementation.
No Mongrel, no FCGI just a clever Apache module that hosts Rails directly out of your WebServer.

Just point your DocumentRoot to your public folder and there you go. Even restarting your application is damn easy:

touch /webapps/mycook/tmp/restart.txt

Even I can write a Capistrano recipe to do that!

And this statement is just the Killer for me:

Page caching is fully supported, without the need to configure mod_rewrite.

Unfortunately, I won’t be able to install it for the next 3 weeks, but I am looking forward to get this baby under test.

mongrel vs. FCGI

Sunday, March 9th, 2008

I am running this blog and some RoR applications (mostly for internal use or in development status) here on Vanager.
It’s cheap, it rocks, but w/ every new Mongrel instance I am more and more running out of resources.

So I was searching for a cheap, cheap hosting solution for RoR applications with expected mediocre amount of hits - and came across this site!

But nearly all hosters in these Reviews use FCGI for hosting. Hey!! Mongrel is the state-of-the-art way how to host RoR.

So I started this discussion on GoogleGroups to get an idea if people recommend going with FCGI. I asked the following:

I have a virtual root server (monthly $10) running some RoR projects
with mediocre traffic by using MONGREL.
It ROCKS.

But with every new mongrel instance, I am getting closer to run out of
system resources.

The web is full of posts like:
FCGI is dead - Mongrel is the way how to do it.
But then you see a list of great WebHosting plans like this:

http://www.rubyonrailswebhost.com/

According to the reviews, it seems that these people know how to host RoR
But they are all using: FCGI

- do you think it is a good idea to get one of these hosting plans?
- does it scale - even if you are getting more traffic as expected?
- are there any other downsides using a webspace hosting over a root
server?

what do you think?

So after getting some real professional replies I came to the following conclusion:

Hey thanks, guys!

Just to sum it up:

Serving RoR via FCGI works, and is a reliable solution to host RoR
projects.
But you can’t expect that it will perform compared to Mongrel etc.

Perhaps you should take the name “Developer plan” serious and host
your production environment not via FCGI.

That’s what came to my mind reading the above posts. … and I am fine
with that!

And what do YOU think?

sphinx vs ferret

Friday, March 7th, 2008

In the past I was not quite happy using Ferret (for example). acts_as_ferret is cool, but I would have had to tweak it quite much to please my concerns.
In the meantime I switched to simple MySQL FULLTEXT indexing and I feel fine! (Will give you a post later on!)

By coincidence I stepped across this discussion in the  Deploying Rails Google Group .

It really doesn’t leave a good spot on Ferret.
Almost everyone agrees in this long discussion, that Ferret WILL bring you into trouble while using it in production.

Sphinx seems to be the new runner-up!

Save files, folders over Capistrano deploys

Sunday, March 2nd, 2008

If you use start using Capistrano and you get it working [ok, I have a server running Debian SARGE and I first had to manually compile eg. subversion to be compliant w/ the actual Capistrano version] you will really love it.

But then I had a situation:
I use attachment_fu as to upload images.
The Rails way - they are stored under ‘public/#{model_name}’.
Ok, but after every cap:deploy these will be deleted. Or more precise, the ‘current’ application version is linked to a blank folder as checked out from SVN. These files will not be available for the ‘current’ release anymore!

Hey but why don’t store these files in the ’shared’ folder and symlink to this folder every time. This folder is meant to be used for just that!

Actually this recipe is from the RailsMachine guys (they know how to handle Rails stuff)

Paste this in your deploy.rb:

set :symlinked_public_dirs, %w( ** a list of your folders that should be saved ** )

# this will create the shared folder at 'cap deploy:setup'
task :after_setup, :roles => [:app, :web] do
symlinked_public_dirs.each { |dir| run “mkdir -p #{shared_path}/public/#{dir}” }
end

#this will create the symlink after 'cap deploy'
task :after_symlink, :roles => [:app, :web] do
symlinked_public_dirs.each { |dir| run “ln -nfs #{shared_path}/public/#{dir} #{current_path}/public/#{dir}” }
end

Using YM4R/GM

Wednesday, February 20th, 2008

In my actual RoR project I have a heavy usage of Google Maps. For gecoding I use the well known geokit plugin. But for rendering the maps I stepped across YM4R/GM.

It is so damn easy to render maps by writing Ruby code - and much more DRY than manually building your Javascript code!
From my point of view it is nearly a 1:1 Ruby mapping of what you can do with the GMap2 API.

While writing my first lines of YM4R/GM code I got a little bit nevous - what I wanted to do was just not working. YM4R/GM is quite well documented, but left out the hint for my actual problem. Finally I managed it, so I want to share my Heureka! with you:

The Situation:
I just wanted to create a map, initially add a Marker to it and add an event listener to this Marker …

My first code was:

@map = GMap.new(”map”)
@map.control_init(:map_type => false, :small_zoom => true)
@map.center_zoom_init(@shot.lat_lng, 15)
@marker = GMarker.new(@shot.lat_lng)
@map.overlay_init(@marker)
@map.event_init(@marker,:click, “function(){window.location.href =’#{shot_url(@shot)}’;}”)

and the output was:

map = new GMap2(document.getElementById(”map”));
map.setCenter(new GLatLng(48.221131,16.371907),15);
map.addOverlay(new GMarker( new GLatLng(48.221131,16.371907)));
GEvent.addListener(new GMarker( new GLatLng(48.221131,16.371907)) ,click”,
function(){window.location.href = ‘http://localhost:3002/shots/2-Peter’;});
map.addControl(new GSmallZoomControl());

So, as you can see, this code produced a Marker for adding to the map but a different Marker for assigning the event.

This code works:

@map = GMap.new(”map”)
@map.control_init(:map_type => false, :small_zoom => true)
@map.center_zoom_init(@shot.lat_lng, 15)
@marker = GMarker.new(@shot.lat_lng)
@map.declare_init(@marker, “marker_var_name”)
@map.overlay_init(@marker)
@map.event_init(@marker, :click,
“function(){window.location.href = ‘#{shot_url(@shot)}’;}”)

 

The bold line says YM4R to handle the variable @marker as a javascript variable further on!

the correct output:

map = new GMap2(document.getElementById(”map”));
map.setCenter(new GLatLng(48.221131,16.371907),15);
var marker_var_name = new GMarker(new GLatLng(48.221131,16.371907));
map.addOverlay(marker_var_name);
GEvent.addListener(marker_var_name,”click”,
function(){window.location.href = ‘http://localhost:3002/shots/2-Peter’;});
map.addControl(new GSmallZoomControl());

In the next couple of days I will try out the built in RJS magic to update Markers after changing the view of the map. Will get back to you with some new experiences.

Rails development will continue

Wednesday, February 6th, 2008

In my prior post I got quite rude on the whole Rails/Ruby system.

I won’t apologize for that ’cause I still believe these dependencies to 3rd party frameworks make it quite hard to trust a running Rails system. “Pray, while upgrading to a newer Rails version”

But hey, Rails development is too much fun that I will be able to quit it. Did some new  (sophisticated, sic!) hacks this weekend and everything worked fine just from the beginning.

I love Rails, no I hate Rails

Thursday, January 31st, 2008

To learn and to review Rails I started a project some time ago.
At the moment I really don’t know if this was a good decision. Don’t get me wrong -I really appreciate Rails and the whole development was fun. It’s amazing what you can do with some lines of code and how smart the whole framework is built.

Actually, I would really say Rails, considered as it is, is a quite mature platform - especially speaking about Rails2.0. But coming form rock-solid Java development, in comparison Rails development with all it’s dependencies is negligent immature.

Huh, what am I talking about:
I am talking about Rails and their dependencies, more exact: gems and plugins you want to use ’cause they seem to be well done and seem to save you a lot of work.
But while my development goes on the opposite seems to be true: Every one of the used plugins I had to rewrite or bugfix after searching the Internet for other fellow sufferers who had the same problem.

See my prior post about ferret!

And now, beside others I hate working with the award-winning attachment_ fu plugin. It would be great w/o having its dependencies.

  1. After updating Rails and other gems and ImageMagick just to be work on the actual versions, thumbnailing was not working anymore. The reason I have installed a ImageMagick version that lacked jpeg support. Ok! I was my fault! But that attachment_fu absorbs all exceptions made me go grazy. You won’t see this in Java.
  2. As RMagick is known to cause memory leaks I switched to mini_magick. And soon I had the next big problem. Should I try out ImageScience now and wait for the next bugs to fix?

And that is my problem with Rails. I have to fix well-known bugs in an immature environment and loose so much time. Perhaps staying on the Java platform would take a longer development time but I can rely on 3rd party libs.