Tuesday, December 26, 2006

Why I abandoned ruby on rails

I have been a java developer for quite some time. I started doing my website in Perl (even writing my own modules ) because I wanted a cheap hosting option. As you know , java hosting is not cheap. my initial goal was to go online with yahoo's 10$ hosting plan. That plan had support only for few perl / PHP modules . since I had done some perl and *no* PHP , I decided to stick with Perl. But the kind of web application i am doing is very difficult to do with HTML::Template and few basic modules. At one point , I became sick and tired of writing everything by hand. That just takes lot of time. I needed a better framework and thats why I decided to switch to rails. I switched to rails because I did not want to write all and sundry stuff myself.

The switch was okay for me. I like playing around with scripting languages and I had gone through the pragmatic programmer's guide already. Ruby on Rails (ROR) is as such a nice framework. Nothing against the framework. It works neat and nice. My only problem was working with ActiveRecord. I did not like it in full so I was writing all my SQL by hand. I have been playing with rails for last 1 month or so. All my development was done using the built-in webrick server. Few days back, I decided to check out the rails production deployment options. However when I looked at the production deployment options for rails , I came back to square one. There is not much material for deploying rails.

Looks like that in rails world , the way to go fast is to go with fastCGI. However, I do not have a linux box right now and I could not locate fastCGI for windows. I could have looked hard but then i was just scanning the field. According to sources fastCGI development is not active. (But again there were some links refuting this assertion so take everything with a pinch of salt). That prompted me to look at SCGI. But the version number, 0.4.3 of SCGI did not inspire much confidence. All the rails crowd is heavily biased towards lighttpd whereas I am a hard core apache fan. lighttpd in itself looks good but I am not sure how good or bad FCGI or SCGI clusters would be. The available literature is not much and I could not locate any benchmarks. That sort of prompted me to look back at my original intentions.

why did i start with Perl? Because i wanted cheap hosting. why did i ditch perl? because it was time consuming to write an interactive web application with few basic modules. So cheap hosting was now out of window. Take it, if you want new/ your own stuff , you just can not do it with cheap web hosting. That is good only for hosting static HTML pages. But why did i switch to rails and not java frameworks? Because i had heard a lot about rails and I like experimenting with new things. I was okay with ruby and more than anything else I was not sure if i could host a java app on anything less than a dedicated server. I had increased my budget to go with a VPS and do my rail deployment there.

Couple of things happened last week that forced me to re-look at my framework decision. First, I came to know of Rimuhosting.com that provides java hosting on VPS plans. So cost wise it works okay. My budget was 100$ / month and it looks like I can do my java hosting within my budget. Second, I asked a friend to do some work on my website. This guy was not so sure that he wanted to work with ruby/rails because he is a java developer. He said he can churn out things much quickly in java because he knows how things work in that world. Basically he would like to play to his strengths. That convinced me too because I know all the things in java world. I do not have to learn anything new. I have already done everything that is there to be done for a web application. I can work much quicker there.

Final nail came after looking at the rails deployment options. I much familiar with apache 2 and tomcat deployments and can do any level of tuning there. i am not so sure about fastCGI / SCGI clusters. To summarize, I have decided to abandon ROR because
  • It is possible to host java application in a VPS budget. I do not require a dedicated server
  • I may be interested in RUBY but other people are not
  • I am familiar with Java and most of the guys around me would prefer to work in java so there is no learning curve
  • I have already done apache 2 and tomcat deployments so I can save time there as well
  • whatever people may say, the production deployment of rails is not covered in detail right now, so deploying It would be like getting in untested waters.
Maybe I should have given PHP a spin after all ;o)

Wednesday, December 20, 2006

Down with Flu

No updates. Nothing at all in last 10-12 days. Point is , I was down with flu and did not feel like doing anything. Last week was more or less spent sleeping in bed. You feel no energy. Even now my system is not restored to normal, I guess , this is a side effect of all those anti-biotics I took. There is nothing new or exciting to do at workplace. Same old stuff. One question though is to do file caching. I need to research that a bit. I am not sure if just putting squid in front of apache would solve my problem. I should also look at lighty. (http://www.lighttpd.net) I will set myself some  tasks when I recover fully.

Saturday, December 09, 2006

JSON data with ruby rails

My requirement is to fetch the JSON data from rails server and use it to update the place marks on a google map. I start with a view form that submits the user query. I am submitting this query form using the form_remote_tag

 

<%= form_remote_tag (:update =>; 'searchMapResults',:loading =>; "Element.show('spinner')",:complete =>; " Element.hide('spinner') ; ",
:id =>; 'searchMapForm' ,
:url =>; {:action =>; :searchMap}) %>;

Next, we go to the controller action that handles this request. searchMap action should fire a SQL query, load some data in instance variables and return part of data as JSON string to the UI. The controller action looks like




def searchMap
 # get the area and search token
 filter = params[:filter]
 binds = Hash.new 

 sql = { some sql ..... }
 @pmarks = Pmark.find_by_sql [sql, binds] payload = Hash.new
 points = Array.new

 @pmarks.each do |pmark|
 point = Hash.new
 point[:latitude] = pmark.latitude
 point[:longitude] = pmark.longitude
 point[:name] = pmark.name

 point[:description] = pmark.description 
 points.push(point)
 end
 payload[:markers] = points 
 @jsonData = payload.to_json
 logger.debug( " gloo : markers json data" + @jsonData);
 render(:layout => false )

end

We fire a SQL query and load the results. Next we create a Hash (payload) of arrays (markers) of hash (point). we convert this payload RUBY data structure to JSON string using the Active support JSON gem. I installed this gem using command


$gem install json

This gem provides a ready made to_json method. Next step is to use this JSON data string inside our view and javascript files. Our searchMap.html (view for this action looks like:)
 


<script>
loadPoints('<%= @jsonData %>');
</script>

And finally inside a loadPoints javascript function we evaluate the JSON data and use it.
 

function loadPoints(content){
 var jsonData = eval('(' + content + ')');
  for (var i=0; i<>
   alert(jsonData.markers[i].name);

  }
 }



Wednesday, December 06, 2006

How to kill your hung oracle session

Use v$session to find the logged in users and their sessions.



SQL> SELECT s.sid,
2 s.serial#,
3 s.osuser,
4 s.program
5 FROM v$session s;


Then kill the session using the alter system command 

SQL> alter system kill session '34,3464'; [sid, serial#] 
© Life of a third world developer
Maira Gall