Thursday, February 28, 2008

Load balancing

I surprised myself when I read my old post (wrote it on 28 Feb 2008). What was I thinking? never met someone who use load balancer?? I must had a very small view of the IT world ;)

"A nice article on load balancing with apache, somehow until now I never met someone who use load balancer (even on a big project) and this makes me think... do we really need a load balancer? What are the cases where load balancer is really required?
It seems that upgrading the server is the preferred choice, personally I'm waiting for a chance where I can setup a load balancer :) One more thing that I'm looking forward to see is transparent failover, hopefully I'll see one sooner rather than later."

Now, I stand corrected, load balancer is a must and how do we have a scalable architecture without one?
For my own needs, one of the cheapest solution I believe is to use Apache httpd as a load balancer for my application servers. Here's how to set it up:

1. Edit apache's httpd.conf and below is a sample configuration


 2. Load the modules below by uncommenting them in the LoadModule section in httpd.conf:
- mod_proxy.so
- mod_proxy_balancer.so
- mod_proxy_ajp.so 
- mod_proxy_http.so
- mod_lbmethod_bytraffic.so
- mod_slotmem_shm.so
3. Make sure ajp connector is enabled in Tomcat's server.xml configuration file.
4. Restart apache httpd

I think that's all we need.


Reference:
- http://httpd.apache.org/docs/2.2/mod/mod_proxy_balancer.html
- http://httpd.apache.org/docs/2.2/mod/mod_proxy.html#proxyset

Tuesday, February 26, 2008

JSF strange behaviors

Two strange behavior of JSF (at least this is what I remembered)
1. Your backing bean only specify getter method (in my case, it returns a collection) and you're using it in h:dataTable. Submitting the form (invoking any action on the page) does nothing, no exception, no sign of anything happening... not a single clue. After one hour wasted, I found out that creating a setter method solves it. It seems that JSF try to call the setter and then fails ungracefully.

2. I have a selectOneMenu and I use a getter method for the selectItems, the List of SelectItem are created whenever the getter is invoked (I know it's not good, just hear the story :). Accessing the page yields exception complaining that there is no selectItem provided (null). Strange thing is the getter method is invoked not in render phase, why? Long story short, I add a property in the backing bean holding the List of selectItem and the getter method is still the same getter method as previously, only at this time I initialize the collection once (better pattern, rite? ;). It works! No more error.


These two strange behaviors that I remembered, are they somehow in the JSF specification?
... I guess I have to try to find out myself.