JMeter Remote Testing on AWS EC2

Posted on

I have been trying to set up Apache JMeter remote testing the last few days. JMeter remote testing enables users to view the test results on a client machine while the traffic is generated from one or more other servers. It is useful when you want to view the test result on a lower spec server and generate huge amount of traffic with a higher spec server or a cluster.

Initially, I was hoping that I can set up the JMeter server on AWS EC2 and the client on my laptop. Unfortunately, that didn’t go well and I was having inconsistent error messages. After that, I tried to set up on both of my laptop. I have googled for solutions and tried changing the port numbers for the server and rmi, turning off the firewalls on both sides, and telnetting to each other. And I was having a socket error message. My third experiment was to set up this remote testing on two EC2 (Windows Server 2008 R2) instances and it finally works. Below are the steps that I took to set up JMeter remote testing.

  1. Launch two EC2 instances
  2. Download and install JDK, JRE, JMeter (binary package) on both instances. JMeter requires JVM 1.5 and above.
  3. On the server, double click the jmeter-server.bat in [JMETER_HOME]/bin folder. A command prompt window similar to below will pop up.
  4. On the client side, you need to add the IP address of the server to the “remote_hosts” property in the jmeter.property file in [JMETER_HOME]/bin folder. You can use either private IP address or the public IP address but the public IP address changes every time you restart your instance. To start the JMeter client with GUI, double click the jmeter.bat in [JMETER_HOME]/bin folder. After adding a simple thread group with a listener, we can start the remote testing by selecting the IP address of the JMeter server from the Remote Start menu.

    After you start the test. You should see a message similar to the one below shows up on the command prompt.
  5. On the server side, you should receive the messages for starting and finishing the test.

I am happy that I finally have it set up after many tries. I still don’t know if there are fixes for my first two tries. Please leave a comment if you have the same issues or know about how to fix them.

Full list of command line options: http://jakarta.apache.org/jmeter/usermanual/get-started.html#options


REST and JAX-RS

Posted on

REST stands for Representational State Transfer. It’s a software architectural style for Web-based systems providing Web Services. It has become a preferable architecture style because it results in better Web performance, scalability, and simplified client and server interactions.

The resources on the Internet are the documents that can be access through URIs(Uniform Resource Identifier). A RESTful API means to provide the unique access to each document. Since each response will return the same document, when the client sends a request, its browser will check the modified date and it can probably use the cached document. This increases the Web performance on client side and at the same time reduces a great amount of traffic to the server. The other major feature of REST is keep the Web state-less, which means no needs for the session management.

Different from the RPC calls, the URIs for REST API calls are supposed to be used for locating the resource only and not the operations, which should be specified by the type of the HTTP request. There are four major types of requests for RESTful Web services:
1) get – retrieved resources with known URIs
2) post – create or modify resources with known URIs
3) put – create or modify resources. The server will return an URI when allocated
4) delete – remove resources with known URIs

JAX-RS is a Java API for RESTful Web Services. It defines a set of annotations to support HTTP requests. You can create a custom annotation using an @HTTpMethod designator. Here are a list of basic annotations:
@Path – relative URI path in the Web server
@PathParm – bind the value of a URI template parameter
@FormParm – bind the value of a form parameter contained in the request
@Produces – MIME media type that the method will return to the client browser
@Consumes – MIME media type that the method accepts

For more available annotations, please check out Java EE 6 API – javax.ws.rs.

Example:


@Path("/")
public class Library {

 /**
  * Handle get requests to relative path /book
  * @param book ID extracted from the URI
  * @return Book details
  */
 @Path("/book/{id}")
 @Get 
 public Book getBook(@PathParam("id") int id) {...}

 /**
  * Handle post requests that are in json format to relative path /book
  * @param all the form data sent from the client
  * @return Book details
  */
 @Path("/book/{id}")
 @POST 
 @Consumes("application/json")    
 @Produces("application/json")    
 public Book addBook(@FormParam("") Book newBook) {...}

}