Google App Engine adds Java support (Review)

Last night Google announced Java support on Google App Engine.

After a bit of toying around, here are my findings.

The Eclipse plugin is pretty slick. Deploying and build is simple.

The dev server that you spin up locally looks to be jetty under the hood.

Objects intended for storage are JDO annotated and after compiling, you run the .class files through the DataNucleus Enhancer which adds additional metadata so Google can map it to BigTable. The Eclipse plugin automatically performs this step for you after compiling. The examples provide a bunch of ant macros to help facilitate building/deploying.

One issue that I had was that the project was building with Java 1.6 and I would get an error after compiling:

Caused by: java.lang.UnsupportedClassVersionError: Bad version number in .class file

Even though they say they support Java 1.5 and 1.6, I guess this doesn’t work on the Java 1.6 for the Mac. Switching the build to 1.5 allows the DataNucleus Enhancer to run successfully.

Even though they are using JPA, some features have not yet been implemented or supported ( see http://code.google.com/appengine/docs/java/datastore/usingjpa.html#Unsupported_Features_of_JPA)

Overall, I like what I see so far and think this would be great for quick prototypes of web apps/services.

Going through the tutorial, my awesome Guestbook application has been created and deployed.

Google App Engine adds Java support (Review)

Eclipse Ganymede + Subclipse = Unable to load default SVN client???

I like Shiny New Things. So when I heard Eclipse Ganymede SR1 was available, I proceeded to replace the Stream Stable Build I was currently running.

This, of course, ended up causing me problems. After installing Subclipse and attempting to pull up any SVN history, I get an error dialog box that states:
“Unable to load default SVN client”

Confused, I RTFM and saw that “Subclipse 1.4.x requires Subversion 1.5.0 version of JavaHL/SVNKit”

Seeing the SVN I was running was in fact not 1.5,

  theo@notedpath~ $ svn --version
svn, version 1.4.4 (r25188)
   compiled Nov 25 2007, 08:20:33

I went here, downloaded and installed Subversion 1.5, restarted Eclipse and things are looking good now.

Stupid shiny new things.

Eclipse Ganymede + Subclipse = Unable to load default SVN client???

Breaking Java Habits: Ruby increment/decrement operators

My background in C++ and Java has instilled in me some programming habits that don’t play nice in Ruby. When I want to increment or decrement a number, my fingers instinctively go to ‘++’ and ‘–’’.

Unfortunately, this syntax is not supported by Ruby. As a language design choice, Ruby opted to not support this syntactic sugar to increment/decrement a variable.

I will have to break my habit and start going with:

// increment x
x+=1
// decrement x
x-=1

Another thing to note is that the prefix increment/decrement operators like ‘–x’ or ‘++x’ do nothing. The signs are interpreted as unary operators.

Breaking Java Habits: Ruby increment/decrement operators

Java WTF: Reflection API and Annotations

I got some exposure to custom Java 5 Annotations today and came across a noobie mistake.

Here’s my annotation:

public @interface Annotated {
}

Pretty simple, right?

Here’s a test class that uses the annotation:

import java.lang.annotation.Annotation;

@Annotated
public class Main {
    public static void main(String[] args) throws Exception {
        for(Annotation ann: Main.class.getAnnotations()) {
            System.out.println(ann);
        }
    }
}

What does this print?

Nothing!

Well, WTF?

Turns out Annotations are not run-time accessible unless you declaratively specific it via @Retention. The updated annotation looks like this:

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;

@Retention(RetentionPolicy.RUNTIME)
public @interface Annotated {

}

By default, the Retention is specified with RetentionPolicy.CLASS which, per the javadocs, “Annotations are to be recorded in the class file by the compiler but need not be retained by the VM at run time.”

RetentionPolicy.RUNTIME allows the annotation “to be recorded in the class file by the compiler and retained by the VM at run time, so they may be read reflectively.”

File this one under, RTFM.

Java WTF: Reflection API and Annotations

Java WTF: Calendar vs Date

I’ve been doing some date math at work and I came across something I thought was wack.

Check this out:

Calendar cal1 = Calendar.getInstance();
Thread.sleep(500);
Calendar cal2 = Calendar.getInstance();
Thread.sleep(500);
Date now = new Date();

System.out.println(cal1.before(cal2));
System.out.println(cal1.before(now));

What do you think this snippet prints (It compiles, I promise!)?

Looking at the code, it shows that we are getting three snapshots in time, waiting half a second between snapshots, and assigning those values to cal1,cal2, and now, respectively. I put in the Thread.sleep() to illustrate the point more clearly. The first print statement compares the first and second snapshots in time, returning true if the first is before the second. The second print statement returns true if the first is before the third snapshot.

Logically, we would expect both print statements to prints true. However, this outputs:

true
false

But, how could the first snapshot be before the second snapshot but not the third?

Putting up the javadocs, gives us our answer. The Calendar before and after methods always returns false if you don’t pass it a Calendar object. Why? I have no idea. Why not just have the method signature take a Calendar object? I mean, I guess this allows you to extend Calendar to be able to call after/before on whatever kind of classes you want to support…but does it really make sense to compare a Calendar to a Monkey class? This is what I call a Java WTF.

Java WTF: Calendar vs Date

Eclipse + Leopard = Crash?

I recently upgraded to Leopard on my work MacBook Pro. In Eclipse, one of the first things I ran into was anytime I tried to do Open Resource (Shift + APPLE + R) to open a file resource, Eclipse would crash with a nasty exception.

Exception Type: EXC_BAD_ACCESS (SIGBUS)

After doing a bit of googling, this seems to be a bug in SWT for Leopard (see here). I upgraded my Eclipse to the 3.4 Stream Stable Build found at http://download.eclipse.org/eclipse/downloads/ and my problems have seem to gone away.

It’s got a pretty cool new splash screen too 🙂


eclipse-3.4 splash screen

Eclipse + Leopard = Crash?

Using JMeter for load testing

I came across JMeter a while back but never got a chance to try it out. From the JMeter website:

Apache JMeter is a 100% pure Java desktop application designed to load test functional behavior and measure performance. It was originally designed for testing Web Applications but has since expanded to other test functions.

This weekend I was able to test load on my 256 slice which this blog is running on. Here’s what I did:

  1. Download the binary
    You can get the binary here.
  2. Unzip the tarball/zip file
    I extracted it file to /Users/theo/tools/jakarta-jmeter-2.3.1
  3. Start up JMeter
    Go to the bin directory. Run jmeter.sh (jmeter.bat if using Windows) from the command line.
  4. Create a Test Plan
    Just give a name and any description you want for your test plan.jmeter_create_test_plan
  5. Create a Thread Group
    A thread group allows you to specify the amount of load you want to simulate. Select your test plan from the left Tree view, right-click, and select Add -> Thread Group.

    Configurable fields include:

    • Number of threads – the number of connections or users you want to simulate
    • Ramp up period – the amount of time in seconds to take to reach the number of threads specified. If you choose 0, all of the threads will be created at the start of the test.
    • Loop count – you can specify to loop indefinitely or provide a number of times to run through the test.

    jmeter_create_thread_group

  6. Add a Sampler
    A sampler is a type of request you want to make. In this example, I used an HTTP request to test load to a web server. It’s good to note JMeter supports multiple types of samplers including web services, JMS, and JDBC. Add a sampler by selecting the Thread Group you just created, right-click, select Add -> Sampler -> HTTP Request.

    Configurable properties include:

    • Server Name – what the ip or url is to the server the request it to
    • Port – the port the server is listening to
    • Protocol – the protocol (http, https, etc)
    • Method – HTTP method (POST,GET, PUT, DELETE, etc)
    • Path – the URL path to request

    jmeter_create_http_request

  7. Add a Listener
    A listener allows you to collect data points and display them in some fashion like a graph or a table. I used the Graph Results listener by selecting the Thread Group, right-click, select Add -> Listener -> Graph Results.
  8. Run the test!
    Now we are ready to run the test. From the file menu bar, select Run ->Start. You will be prompted to save your test plan. You can save it or just hit “No”. You should see data points begin to be plotted on the Graph Result or whatever listener you selected.

    jmeter_graph_results
    I monitored the usage from my slice as well and this is what top showed me:

    slice_top_load_test

    You can see the 5 threads we specified in the Thread Group taking up 5 apache processes.

  9. Interpret the results
    Tests are worthless without interpreting the results. So, what the heck does this graph tell me? Pretty good documentation can be found here. Basically, given the load scenario we have setup, my slice can handle ~643 requests/minute or ~11 requests/second. I am not sure what kind of numbers I should be getting but these seem pretty good to me. One last thing to note is that JMeter is not a web browser so these metrics don’t include rendering time or execution of any JavaScript.

Overall, JMeter seems to be a great open source tool to test different kinds of load on servers. I look forward to trying it out at work. One last thing I came across is JMeter integration with your Ant build process. Check that out here. I would like to hear about other people’s experiences with JMeter, too.

Using JMeter for load testing

Installing Java SDK/Tomcat to Ubuntu Feisty (Part 2)

In the previous post, I described how to get your Java SDK installed on your machine. In this piece, I’ll lay out how to get your tomcat instance up and running.

Let’s setup our JAVA_HOME. While you can set this setting in many places, I decide to stick it in bash.bashrc.

My Java installation from apt-get put Java under /usr/lib/jvm/java-6-sun.

sudo vi /etc/bash.bashrc

Enter in:

# set JAVA_HOME environment variable
JAVA_HOME=/usr/lib/jvm/java-6-sun

Save and quit vi. Log out and log back into your console and you should be able to do

 >>echo $JAVA_HOME
/usr/lib/jvm/java-6-sun

I went through the initial attempt of installing tomcat from apt-get. This resulted in a successfully download of all the files, but I wasn’t able to get tomcat to start up. Not only that, it installed tomcat and created symbolic links everywhere and there were permission issues galore. Thanks to the beauty of slicehost, I just rebuilt my machine from my previous snapshot (luckily I made a snapshot after the previous post).

So, I decided to just download and install tomcat manually. I decided on apache-tomcat-5.5.25.

To get started, download the tarball and extract it somewhere.

wget http://apache.cs.utah.edu/tomcat/tomcat-5/v5.5.25/bin/apache-tomcat-5.5.25.tar.gz
tar xzvf apache-tomcat-5.5.25.tar.gz
cp -R apache-tomcat-5.5.5 <PATH_TO_TOMCAT_INSTALL>

You will need to go to the bin directory and set some file permissions so you can execute some of the files.

cd <PATH_TO_TOMCAT_INSTALL>/bin
sudo chmod a+x *.sh

It’s a probably good time to see if things are looking good. So try,

 >> ./version.sh
Using CATALINA_BASE:   /usr/share/tomcat
Using CATALINA_HOME:   /usr/share/tomcat
Using CATALINA_TMPDIR: /usr/share/tomcat/temp
Using JRE_HOME:       /usr/lib/jvm/java-6-sun
Server version: Apache Tomcat/5.5.25
Server built:   Aug 24 2007 05:33:50
Server number:  5.5.25.0
OS Name:        Linux
OS Version:     2.6.16.29-xen
Architecture:   amd64
JVM Version:    1.6.0-b105
JVM Vendor:     Sun Microsystems Inc.

Sexy. Let’s go ahead and try to startup tomcat.

./startup.sh

By default, tomcat should be running on port 8080. (If you tried to install from apt-get, it’s setup on port 8180)


tomcat default page

Setting up the tomcat manager

sudo vi conf/tomcat-users.xml

We need to setup a manager role to see the tomcat status page:

<tomcat-users>
  ...
  <role rolename="manager">
  ...
  <user username="admin" password="mysecretpassword" roles="tomcat,manager">
</tomcat-users>

Restart tomcat and confirm you can log into the Tomcat status page and we’re done!

TODOS:

  • I need to setup the system to run tomcat on startup
  • I need to write an init.d script
  • I need to get tomcat to proxy through apache via mod_jk
Installing Java SDK/Tomcat to Ubuntu Feisty (Part 2)

Installing Java SDK/Tomcat to Ubuntu Feisty (Part 1)

When I first got my slice, I had it setup with java and tomcat. Apparently, I updated or rebuilt my slice and forgot to install those two again. Too bad I didn’t take good notes because I totally forgot how to do it.

So this time, I’m going to document it via this post.

I am currently running Ubuntu Feisty (v. 7.04). You can find out what version you’re running by running the following command:

cat /etc/issue

The usual apt-get command allows me to install sun-j2re1.4. That’s not very helpful if I want to compile java code off of my slice or set it up to be a continuous build server. I remember that I had to add a specific repository in order to be able to install the Java SDK via apt-get. After some digging around, I came up with the following:

sudo vi /etc/apt/sources.list

Paste the following into the file:

deb http://archive.ubuntu.com/ubuntu feisty universe multiverse
deb-src http://archive.ubuntu.com/ubuntu feisty universe multiverse

The Ubuntu docs recommend enabling the universe/multiverse security/updates repositories to prevent version mismatches during installs or upgrades but I didn’t run into any issues proceding without them.

Save and exit out of vi.

Next, run

sudo apt-get update

apt-get should be pulling down an updated list of installable packages. So if you type

sudo apt-get install sun-j

and then hit TAB, you should get a list of installable sun packages.

I decided to install Java 6.0 SDK.

sudo apt-get install sun-java6-sdk

It will begin to download and install the SDK. You will have to accept a license. Just hit TAB to get select “OK” and hit enter.

Once it completes, you should be able to confirm the JDK was installed successfully.

  >> javac -version
javac 1.6.0

The next post will lay out steps to install Apache Tomcat.

Installing Java SDK/Tomcat to Ubuntu Feisty (Part 1)