Installing The Grinder On Ubuntu 10.10

One of my development goals for this year is to learn a lot more about J2EE application performance. Gathering performance statistics for a J2EE application isn’t really difficult, but I soon realized that before I could do that, I needed to find a way to run my applications under load.

At work, we typically do this by using a non-free tool such as LoadRunner. This tool is very popular and it seems to work fairly well, but I can’t afford the license or training costs.

Luckily, I found an open source alternative called The Grinder. This tool’s workflow is similar to the one used by LoadRunner, and fit all of my requirements, including:

  • Free and open source (FOSS)
  • Cross Platform – It is written in Java and runs well for me on Linux and Windows
  • Mature – The software has been around for nearly 10 years and it is currently on version 3
  • Easily Scriptable – You can write load tests using Jython, which is a version of Python that is written in Java.
    • If you haven’t used it before, Python is a great scripting language that does a good job balancing functionality and ease-of-use.
    • Jython is also a very well-established and mature FOSS project. I was using early versions of it as far back as 2001.

The problem is that I had trouble finding many tutorials on using The Grinder. I therefore decided to write a couple of tutorials, covering the following topics:

  1. Installing The Grinder on Ubuntu 10.10
  2. Executing the Hello World test
  3. Recording and executing a test against a local web application

I’ll cover the first bullet point in this article, and I hope to have the other bullet points covered very soon in othe articles.

Installing The Grinder

The Grinder does not include an installation script or startup scripts for some strange reason. You therefore need to do all of this stuff yourself. Here’s how I did it.

Prerequsites

The only prerequisite for The Grinder is Java 1.5 or greater, but some features can only be used with Java 1.6. So let’s install it:

    $ sudo apt-get install sun-java6-jdk

Everything else that you need to run The Grinder is part of the package.

One more thing that you may want to install is the pychecker package. This tool will check your test scripts for any typos or indentation errors. Simply install it like this:

    $ sudo apt-get install pychecker

It’s not required, but it can save you some big headaches later when your script fails to run.

Installing The Package

Since the script doesn’t have a “native” installer and there isn’t an Ubuntu package, we’ll do things the hard way:

  1. Download the latest version of Grinder 3. I’m using version 3.4. This should be a zip file.
  2. Unzip this file in an arbitrary location. For me, this created a folder called grinder-3.4.
    • $ unzip grinder-3.4.zip
  3. Move this Grinder folder under the /opt folder.
    • $ sudo mv grinder-3.4 /opt
  4. To make our lives a little simpler, make yourself the owner of the /opt/grinder. My username is tom, so this is how I would do this:
    • $ sudo chown -R tom:tom /opt/grinder-3.4

Now The Grinder is officially “installed”, but it’s a little clunky to use. Let’s fix that.

Your CLASSPATH

Adding the grinder.jar file to your CLASSPATH variable will make it much easier to use The Grinder:

  1. Open your $HOME/.bash_profile file using a text editor.
  2. Look for a CLASSPATH variable.
  3. If one exists, then add /opt/grinder-3.4/lib/grinder.jar to it.
  4. If the CLASSPATH variable doesn’t exist in this file, then add the following to lines:
    • CLASSPATH=$CLASSPATH:/opt/grinder-3.4/lib/grinder.jar
    • export CLASSPATH

Now either log out and back in or source your .bash_profile file by typing the following command:

    # you should only have to do this the first time
    $ source ~/.bash_profile

Aliases

Once the grinder.jar file is in your classpath, you can start different Grinder components using their full Java path. For example, you should be able to start the Grinder Console using the following command:

    $ java net.grinder.Console

This isn’t terribly difficult, but it’s hard to remember and tedious to type. We’re therefore going to create alias shortcuts for the Console and TCPProxy commands.

Open your $HOME/.bashrc file in a text editor and add the following lines anywhere in the file:

    alias gconsole="java net.grinder.Console"
    alias gproxy="java net.grinder.TCPProxy"

Now either log out and back in or source your .bashrc file by typing the following command:

    # you should only have to do this the first time
    $ source ~/.bashrc

Finally, you can start the Grinder Console and TCPProxy components by simply typing gconsole and gproxy, respectively.

Conclusion

You should now have a working version of The Grinder that is very easy to execute. In my next tutorial, I’ll show you how to execute a hello world test so that you can start to “kick the tires” of The Grinder.

Advertisements

Installing Tomcat 6 on Ubuntu

If you are running Ubuntu and want to use the Tomcat servlet container, you should not use the version from the repositories as it just doesn’t work correctly. Instead you’ll need to use the manual installation process that I’m outlining here.

Before you install Tomcat you’ll want to make sure that you’ve installed Java. I would assume if you are trying to install Tomcat you’ve already installed java, but if you aren’t sure you can check with the dpkg command like so:

dpkg –get-selections | grep sun-java

This should give you this output if you already installed java:

sun-java6-bin                                   install
sun-java6-jdk                                   install
sun-java6-jre                                   install

If that command has no results, you’ll want to install the latest version with this command:

sudo apt-get install sun-java6-jdk

Installation

Now we’ll download and extract Tomcat from the apache site. You should check to make sure there’s not another version and adjust accordingly.

wget  http://apache.hoxt.com/tomcat/tomcat-6/v6.0.14/bin/apache-tomcat-6.0.14.tar.gz
tar xvzf apache-tomcat-6.0.14.tar.gz

The best thing to do is move the tomcat folder to a permanent location. I chose /usr/local/tomcat, but you could move it somewhere else if you wanted to.

sudo mv apache-tomcat-6.0.14 /usr/local/tomcat

Tomcat requires setting the JAVA_HOME variable. The best way to do this is to set it in your .bashrc file. You could also edit your startup.sh file if you so chose.

The better method is editing your .bashrc file and adding the bolded line there. You’ll have to logout of the shell for the change to take effect.

vi ~/.bashrc

Add the following line:

export JAVA_HOME=/usr/lib/jvm/java-6-sun

At this point you can start tomcat by just executing the startup.sh script in the tomcat/bin folder.

Automatic Starting

To make tomcat automatically start when we boot up the computer, you can add a script to make it auto-start and shutdown.

sudo vi /etc/init.d/tomcat

Now paste in the following:

# Tomcat auto-start
#
# description: Auto-starts tomcat
#  processname: tomcat
# pidfile: /var/run/tomcat.pid

export JAVA_HOME=/usr/lib/jvm/java-6-sun

case $1 in
start)
sh /usr/local/tomcat/bin/startup.sh
;;
stop)
sh /usr/local/tomcat/bin/shutdown.sh
;;
restart)
sh /usr/local/tomcat/bin/shutdown.sh
sh /usr/local/tomcat/bin/startup.sh
;;
esac
exit 0

You’ll need to make the script executable by running the chmod command:

sudo chmod 755 /etc/init.d/tomcat

The last step is actually linking this script to the startup folders with a symbolic link. Execute these two commands and we should be on our way.

sudo ln -s /etc/init.d/tomcat /etc/rc1.d/K99tomcat
sudo ln -s  /etc/init.d/tomcat /etc/rc2.d/S99tomcat

Tomcat should now be fully installed and operational. Enjoy!

Removal of Sun-java-* in Lucid Lynx Ubuntu 10.04

For Ubuntu 10.04 LTS all the sun-java6* packages, which were formerly found in the Multiverse section of Ubuntu repositories, have been removed from the repositories. We recommend that you use openjdk-6 instead. When you can not switch from the proprietary Sun JDK/JRE to OpenJDK, you can find sun-java6* packages in the Canonical Partner Repository. You can add this repository via command-line:
add-

apt-repository “deb http://archive.canonical.com/ lucid partner”
or by manually adding the archive to your /etc/apt/sources.list with your favorite editor.

Install Eclipse with Sun JDK Ubuntu

Eclipse is an open source community whose projects are focused on building an open development platform comprised of extensible frameworks, tools and runtimes for building, deploying and managing software across the life cycle . A large and vibrant ecosystem of major technology vendors, innovative start-ups, universities, research institutions and individuals extend, complement and support the Eclipse platform.

Install Eclipse with Sun JDK in Ubuntu

sudo apt-get install eclipse sun-java6-jdk

This will install the required packages, however, Eclipse will run very slowly since it will be using GNU’s java, not Sun’s. We now need to make Sun’s java the default.

sudo update-java-alternatives -s java-6-sun

Next, edit the JVM configuration file

sudo -b gedit /etc/jvm

and add the following to the top of the file

/usr/lib/jvm/java-6-sun

There is a bug right now were Eclipse ignores Ubuntu’s java-common settings and uses its own (bug 45347). To work around the bug, you need to edit Eclipse’s java_home file

sudo -b gedit /etc/eclipse/java_home

and add

/usr/lib/jvm/java-6-sun

to the top of the file.

Lastly, if you have lots of memory you may want to increase the heap size (warning: If you make the heap size too large then parts of eclipse will continuously swap in and out.).The settings can be altered by editing the eclipse.ini file.

For feisty users:

sudo -b gedit /usr/lib/eclipse/eclipse.ini

The argument Xms refers to the minimum heap size and Xmx refers to the maximum heap size.

Creating your first Eclipse e4 Application

Eclipse released on the 29 July 2009 the tech preview version 0.9 of Eclipse e4, which can be downloaded here.

I wasn’t able to find a description how to create an new application based on E4. Starting from the CVS example is possible but I wanted to start from scratch. After several failed attempts to create an E4 application I believe I have found a way to create an E4 application. I assume others will have similar problems so I wanted to share my experience.

To follow this description you need to have knowledge how to develop Eclipse Plugins in Eclipse 3.5 or earlier. Check out this Eclipse Plugin Development Tutorial.

So lets get started with e4.

Download e4. Extract it and start it is similar to older Eclipse versions.

Currently there is no wizard which creates a working scaffold of an E4 application. We will therefore use the exsting plugin templates.

Create a new Plugin project “de.vogella.e4.first”. Do not select “Generate an activator”, nor “This plug-in will make contributions to the UI” nor “Would you like to create a rich client application”. Do not select a template. Press finish.

e410

This will open the Plugin Perspective, switch here to the Package Explorer to see your new project.

Create the package “de.vogella.e4.first”. The result should look like the following.

e412

Select your MANIFEST.MF and add the following dependencies to your plugin.

01 Manifest-Version: 1.0
02 Bundle-ManifestVersion: 2
03 Bundle-Name: First
04 Bundle-SymbolicName: de.vogella.e4.first;singleton:=true
05 Bundle-Version: 1.0.0.qualifier
06 Bundle-RequiredExecutionEnvironment: JavaSE-1.6
07 Require-Bundle: org.eclipse.ui,
08 org.eclipse.core.runtime,
09 org.eclipse.e4.ui.workbench;bundle-version="0.9.0",
10 org.eclipse.e4.ui.workbench.renderers.swt;bundle-version="0.9.0",
11 org.eclipse.e4.ui.workbench.renderers.swt.contributions;bundle-version="0.9.0",
12 org.eclipse.e4.ui.workbench.swt;bundle-version="0.9.0",
13 org.eclipse.e4.ui.services;bundle-version="0.9.0",
14 org.eclipse.e4.core.services;bundle-version="0.9.0"

You need (some of) these plugins for the usage of E4 features.

Add the following extension points. I noticed that for some of the features you have to modify the plugin.xml directly as the UI does not support them. But you have to create the plugin.xml via the MANIFEST.MF file; as I created it directly as a new file I received a strange system behavior.

01 <?xml version="1.0" encoding="UTF-8"?>
02 <?eclipse version="3.4"?>
03 <plugin>
04 <extension
05 point="org.eclipse.e4.workbench.parts">
06 <part
07 class="de.vogella.e4.first.views.View1"
08 label="My first E4 View"
09 parentId="org.eclipse.e4.ui.tags.navigation">
10 </part>
11 </extension>
12 <extension
13 id="product"
14 point="org.eclipse.core.runtime.products">
15 <product
16 application="org.eclipse.e4.ui.workbench.swt.application"
17 name="vogella">
18 <property
19 name="appName"
20 value="vogella">
21 </property>
22 <property
23 name="applicationXMI"
24 value="de.vogella.e4.first/Application.xmi">
25 </property>
26 </product>
27
28 </extension>
29
30 </plugin>

“org.eclipse.e4.workbench.parts” is a new extension point by which you can define your view parts, formally known as views and editors.

The extension point “org.eclipse.core.runtime.products” has a new parameter “applicationXMI”. This is a parameter to the model of your UI. We came to this later. You also do not define your own application; we use “org.eclipse.e4.ui.workbench.swt.application”.

Create a product configuration called “vogella.product”. This is similar to Eclipse 3.5; see here for a description: Eclipse Product Configuration.

e420

Make sure you select “org.eclipse.e4.ui.workbench.swt.application”.

e430

Add as dependency to your product the plugin “org.eclipse.e4.ui.workbench”. Add also the plugin “de.vogella.e4.first”.
Press “add required plugins”.

Create the following two classes:

1 package de.vogella.e4.first.handlers;
2
3 import org.eclipse.e4.workbench.ui.IWorkbench;
4
5 public class ExitHandler {
6 public void execute(IWorkbench workbench) {
7 workbench.close();
8 }
9 }

and

01 package de.vogella.e4.first.views;
02
03 import org.eclipse.e4.core.services.context.IEclipseContext;
04 import org.eclipse.jface.layout.GridLayoutFactory;
05 import org.eclipse.swt.SWT;
06 import org.eclipse.swt.layout.GridData;
07 import org.eclipse.swt.widgets.Composite;
08 import org.eclipse.swt.widgets.Label;
09 import org.eclipse.swt.widgets.Text;
10 import org.eclipse.ui.services.IDisposable;
11
12 public class View1 implements IDisposable {
13
14 public View1(Composite parent, final IEclipseContext outputContext) {
15 Label label = new Label(parent, SWT.NONE);
16 label.setText("E4 is new");
17 GridData gridData = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
18 gridData.horizontalIndent = 20;
19 label.setLayoutData(gridData);
20 Text text = new Text(parent, SWT.NONE);
21 text.setText("and different");
22 GridLayoutFactory.fillDefaults().generateLayout(parent);
23 }
24
25 public void dispose() {
26
27 }
28 }

You need a model for your application. In the parameter “applicationXMI” we earlier defined that this model will be “de.vogella.e4.first/Application.xmi”. Create the file Application.xmi with the following content.

01 <?xml version="1.0" encoding="ASCII"?>
02 <application:MApplication xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:application="http://www.eclipse.org/ui/2008/Application">
03 <windows name="Main" x="100" y="100" width="800" height="600">
04 <menu>
05 <items xsi:type="application:MMenuItem" name="File">
06 <menu>
07 <items xsi:type="application:MMenuItem" id="" name="Exit" command="//@command.0"/>
08 </menu>
09 </items>
10 </menu>
11 <children policy="VerticalComposite">
12 <children xsi:type="application:MSashForm" policy="HorizontalSash">
13 <children xsi:type="application:MStack">
14 <children xsi:type="application:MContributedPart" iconURI="" name="My View" tooltip="My first View" URI="platform:/plugin/de.vogella.e4.first/de.vogella.e4.first.views.View1"/>
15 </children>
16 <weights>30</weights>
17 <weights>70</weights>
18 </children>
19 </children>
20 <handlers id="" URI="platform:/plugin/de.vogella.e4.first/de.vogella.e4.first.handlers.ExitHandler" persistedState="" command="//@command.0"/>
21 </windows>
22 <command id="application.exit" name="Exit"/>
23 </application:MApplication>

This is the EMF model which defines your UI. Eclipse should display this model in a EMF editor so that you can investigate it. In this model you find your view and command definition. The content can be viewed via the properities view.

e450

Now start your application from your vogella.product. Starting it directly from the plugin.xml will not work (easily).

If you receive the error “org.eclipse.core.runtime.AssertionFailedException: null argument:-applicationXMI argument missing” check you plugin.xml. E4 created in several cases twice the products entry.

You should be rewarded ;-) with this user interface:

e460

With this first application I hope you can started using the E4 advanced features, e.g. CSS styling, etc.

My final thoughts: Eclipse e4 has already amazing capabilities for a tech review release. The new modeled UI removes the need for a lot of boilerplate code.

More Information

http://www.vogella.de/articles/EclipseE4/article.html#overview

Eclipse e4 new look and feel – Around the world

Eclipse e4 M4 has introduce a new look and feel for the tabs in the workbench. See Eclipse e4 M4 New and Noteworthy. Unfortunately the news and noteworthy document did not give information how to enable this feature.

The e4 mailing list has recently discussed this topic and Remy Suen was kind enough to provide this information. To turn this feature on you have to add the tag “newtablook” to your PartStack.

For example if you create an new e4 application with the e4 wizard you can add this tag via:

1 <children xsi:type="application:PartSashContainer" xmi:id="_vTa8kiuFEd-PeMLywHTM-g" id="_vTa8kiuFEd-PeMLywHTM-g">
2 <children xsi:type="application:PartStack" xmi:id="_vTa8kyuFEd-PeMLywHTM-g" id="_vTa8kyuFEd-PeMLywHTM-g">
3 <tags>newtablook</tags>
4 <children xsi:type="application:Part" xmi:id="_vTa8lCuFEd-PeMLywHTM-g" id="_vTa8lCuFEd-PeMLywHTM-g" label="Main"/>
5 </children>

This lead to the following result:

Compared to the “old” look and feel.

For this topic see also Bug 305147 which discusses to move this feature to the CSS styling capabilities.

Tomcat in Eclipse

There are many plug-ins available for the integration of tomcat with eclipse but most simple among them is “ Sysdeo Tomcat plugin ”. This can be downloaded from http://www.eclipsetotale.com/tomcatPlugin.html .

Step wise process to integrate tomcat using this plug-in is as follows:

  1. Tomcat should be pre-installed on the system. For further details click here.
  2. First step towards this process is, Download and unzip this plug-in in your eclipse plug-in directory.
  3. When you restart Eclipse IDE, Tomcat options(start, stop, restart) will start appearing on the Pane and in Menu.
  4. This plugin launches Tomcat using the default JRE selected in Eclipse “ Preferences ” window. To set a JDK as default JRE for Eclipse open the preference window: “ Window ” – > “ Preferences ” – > “ Java ” – > “ Installed JREs ”. The selected JRE must be a JDK (Tomcat require JDK to compile files instead of JRE).
  5. Next step involve setting of tomcat path at “ Window ” – > “ Preferences ” – > “ Tomcat”.
  6. Now it is ready to be used. To test our integration we can make a Servlet or JSP. Select “ File ” – > “ New ” – > “ Project ” and select the new entry Tomcat Project under Java, then press “ Next ”.
  7. Give project a name.
  8. Select the context and finish it. Now create a new file in this project, By selecting “ File ” – > “ New ” – > “ File ” option and give it the name “ Test.jsp”.
  9. Write this simple code in file and save it.
  10. <%@ page language = "java" %>
    <%@ page contentType = "TEXT/HTML" %>
    
    

    If this page is being seen in a web browser, it means integration of Tomcat and Eclipse is complete.

  11. Now start tomcat from menu “ Tomcat” – >“ Start ”. Its logo will start appearing in Eclipse console.
  12. Open a web browser and go to the URL. A page will load and you will get the figure like this.