Amazon EC2 Basic Monitoring

Amazon has recently added basic monitoring to all Amazon EC2 instances. Before this change, you had to sign-up for Amazon CloudWatch to get any monitoring. Basic monitoring allows you to view and track metrics like CPU usage, disk IO and network traffic every five minutes. To get more information, you can sign-up for Amazon CloudWatch Detailed Monitoring. This gives you data every minute for $0.015 per instance-hour.

Another feature that was recently added to CloudWatch are alarms. Using the CloudWatch API, you can use these alarms to notify you of issues or trigger auto scaling of your EC2 instances. Visit the Amazon CloudWatch page for more information.


Firefox Memory Restart

Firefox has a history of using up a lot of memory when used for a long time or when used with many open tabs. Mozilla support and mozillaZine both recommend the periodic restart of Firefox.

Firefox’s memory usage may increase if it’s left open for long periods of time. A workaround for this is to periodically restart Firefox. You can configure Firefox to save your tabs and windows so that when you start it again, you can start where you left off. See Session Restore for details. – Mozilla

If you find that Firefox’s memory usage continues to grow after long periods of being open, you may want to consider periodically restarting Firefox to bring the memory usage back to reasonable levels. Close Firefox and select the Save and Quit option to reopen your tabs when Firefox restarts. – mozillaZine

There is now a Firefox add-on that makes this easy. Memory Restart is a new Firefox add-on that displays Firefox memory usage in the status bar. If it reaches a configurable memory threshold, the memory display color will turn red. When you are ready to restart, just click on the red memory display and Firefox will restart. Use with Firefox’s session restore feature so you don’t lose your current tabs.

There are a few tips from Mozilla on how to make Firefox use less memory. If all else fails, just restart using Memory Restart!


Migrating from HttpClient 3.1 to HttpClient 4.0

We were using Apache HttpClient 3.1 for some time now and have decide to bite the bullet and migrate over to HttpClient 4.0.3. It’s usually painless to¬†update Apache libraries, but HttpClient 4 was a complete rewrite and is not backward compatible. It’s also now a top level Apache project and no longer part of Apache Commons. Here are the things we had to change to migrate over to the latest HttpClient. This is a mini HttpClient 4 tutorial for those moving to the latest version. The time it takes you to migrate depends on how many references you have to change. It took us less than 30 minutes to do it on our project.

1. Replace commons-httpclient-3.1.jar with the latest httpclient-4.0.3.jar and httpmime-4.0.3.jar. You will also need httpcore-4.0.1.jar.

2. Change your import statements from org.apache.commons.httpclient.* to import org.apache.http.*. For example, change:

import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpStatus;
import org.apache.commons.httpclient.HttpException;
import org.apache.commons.httpclient.methods.GetMethod;
import org.apache.commons.httpclient.ConnectTimeoutException;

to

import org.apache.http.client.HttpClient;
import org.apache.http.HttpStatus;
import org.apache.http.HttpException;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.conn.ConnectTimeoutException;
import org.apache.http.HttpResponse;
import org.apache.http.impl.client.DefaultHttpClient;

Notice the addition of HttpResponse and DefaultHttpClient, which will be used next.

3. Change your code from the old HttpClient interface to the new.

HttpClient 3.1:

HttpClient client = new HttpClient();
GetMethod method = new GetMethod(url);
int statusCode = client.executeMethod(method);
if (statusCode == HttpStatus.SC_OK) {
	InputStream is = method.getResponseBodyAsStream();
	// do something with the input stream
}
method.releaseConnection();

HttpClient 4.0:

HttpClient client = new DefaultHttpClient();
HttpGet method = new HttpGet(url);
HttpResponse httpResponse = client.execute(method);
int statusCode = httpResponse.getStatusLine().getStatusCode();
if (statusCode == HttpStatus.SC_OK) {
	InputStream is = httpResponse.getEntity().getContent();
	// do something with the input stream
}

We certainly did not use the full functionality of HttpClient, and most of our changes were similar to those listed above. For a complete examples on how to use HttpClient 4, visit the HttpClient 4.0.3 Tutorial. Do you have any other tips for HttpClient 3 to 4 migration?