Posts

Showing posts from December, 2011

Installing and configuring Cband for Apache2 on Ubuntu

Image
If you need to manage bandwidth usage on Apache web server (particularly on a per virtualhost basis) CBand could be that hero you were hoping for. Below are the steps I followed to get up and running with a basic CBand setup.



Installation

Install additional apache libraries. Only one of these two maybe required.
apt-get install apache2-prefork-dev
apt-get install apache2-threaded-dev

Download the module
wget http://dembol.org/downloads/cband/mod-cband-0.9.7.5.tgz
Untar the file
tar -xzf mod-cband-0.9.7.5.tgz
Enter newly created directory
cd mod-cband-0.9.7.5
Add -lm to the APXS OPTS in Makefile.in like so:
APXS_OPTS=-lm -Wc,-Wall -Wc,-DDST_CLASS=@DST_CLASS@
Configure and install
./configure
make
make install

Restart Apache
/etc/apache2/restart


Hopefully you should now have successfully installed Cband on your Ubuntu server.
Now let's configure it.

Configuration

In order to improve performance of Cband, add the following to /etc/apache2/mods-available/cband.conf
CBandScoreFlushPeriod 1
CBand…

Groovy safe navigation gotcha

I just came across this Groovy gotcha today while accessing a list within a chain of attributes. I had a statement like this in a gsp:
${invoice?.invoiceItems[0]?.name}
This is the (erroneous) recommended style when data binding many ended associations in Grails, but it could easily arise in other scenarios. If I try this "safe" statement where invoiceItems is null, I'll see a null pointer exception. In fact I'll even see it when invoice is null. The reason for the exception is a combination of how lists and the safe navigation work in Groovy.

Lists are much more elegant in Groovy than Java, as they share the square brackets that primitive arrays use. Creating a list is as easy as writing:
def x = [1,2,3]
Just like an array you can access the first element of this list like so:
println x[0]
However, unlike a primitive array the [] operator on a list is mapped (by some Groovy magic) behind the scenes to the getAt method of the particular List object. We can expand our exampl…