Using ApacheBench to benchmark OpenJDK

About ApacheBench

ApacheBench (ab) is a single-threaded command line computer program for measuring the performance of HTTP web servers. ab is a tool designed to give you an impression of how your current Apache installation performs. This especially shows you how many requests per second your Apache installation is capable of serving.

Note that ApacheBench will only use one operating system thread regardless of the concurrency level.

Install latest open JDK8 from the following page

openjdk

$ mkdir -p /usr/lib/jvm/jdk/
$ cd /usr/lib/jvm/jdk/
$ wget http://openjdk.linaro.org/releases/jdk8-server-release-1508.tar.xz
$ tar -xvf jdk8-server-release-1508.tar.xz
$ export JAVA_HOME=/usr/lib/jvm/jdk/jdk8-server-release-1508
$ export PATH=$PATH:/usr/lib/jvm/jdk/jdk8-server-release-1508/bin
$ cd

Installing Tomcat

Had few issues with Tomcat 9 in debian. So using tomcat7 instead.

sudo apt-get update
apt-get install tomcat7 tomcat7-admin tomcat7-examples tomcat7-docs

Configuring Tomcat

Pointing to right JDK

After installing tomcat change the configuration to ensure tomcat is using the correct version of java and has enough memory. Open the 'tomcat7' file located /etc/default/tomcat7 using a text editor and change the following lines.

sudo vi /etc/default/tomcat7

Uncomment out the line JAVA_HOME=/usr/lib/jvm/openjdk-6-jdk and use the location of your Java 8 installation

Creating tomcat user

Creating a new user, sans password, no direct logins

sudo adduser \
  --system \
  --shell /bin/bash \
  --gecos 'Tomcat Java Servlet and JSP engine' \
  --group \
  --disabled-password \
  --home /home/tomcat \
  tomcat

.. which should result in something like this:

Adding system user 'tomcat' (UID 108) ...

Adding new group 'tomcat' (GID 113) ...

Adding new user 'tomcat' (UID 108) with group 'tomcat' ...

Creating home directory '/home/tomcat' ...

Setup Environment Variable

echo "export CATALINA_HOME=\"/var/lib/tomcat7\"" >> ~/.bashrc
source ~/.bashrc

Creating tomcat admin/manager user

sudo vi /etc/tomcat7/tomcat-users.xml

Inside, you will find a heavily commented user configuration file. Find the following tags:

<tomcat-users>
</tomcat-users>

We need to define a user and password. Please put in a password in the place of _SECRET_PASSWORD_

# user manager can access only manager section.
<role rolename="manager-gui" />
<user username="manager" password="_SECRET_PASSWORD_" roles="manager-gui" />

# user admin can access manager and admin section both.
<role rolename="admin-gui" />
<user username="admin" password="_SECRET_PASSWORD_" roles="manager-gui,admin-gui" />

Setting permissions

Set proper permissions and symbolic links for init script.

sudo chmod 755 /etc/init.d/tomcat7
sudo update-rc.d tomcat7 defaults

Create basic webpage

cd /var/lib/tomcat7/webapps/ROOT
sudo vi index.html

paste the following into it

<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
    <title>Apache Tomcat</title>
<link href="site.css" rel="stylesheet">
</head>

<body>
<div id="main">
<h1>It works !</h1>

<p>If you're seeing this page via a web browser, it means you've setup Tomcat successfully. Congratulations!</p>

<p>This is the default Tomcat home page. It can be found on the local filesystem at: <code>/var/lib/tomcat7/webapps/ROOT/index.html</code></p>

<p>Tomcat7 veterans might be pleased to learn that this system instance of Tomcat is installed with <code>CATALINA_HOME</code> in <code>/usr/share/tomcat7</code> and <code>CATALINA_BASE</code> in <code>/var/lib/tomcat7</code>, following the rules from <code>/usr/share/doc/tomcat7-common/RUNNING.txt.gz</code>.</p>

<p>You might consider installing the following packages, if you haven't already done so:</p>

<p><b>tomcat7-docs</b>: This package installs a web application that allows to browse the Tomcat 7 documentation locally. Once installed, you can access it by clicking <a href="docs/">here</a>.</p>

<p><b>tomcat7-examples</b>: This package installs a web application that allows to access the Tomcat 7 Servlet and JSP examples. Once installed, you can access it by clicking <a href="examples/">here</a>.</p>

<p><b>tomcat7-admin</b>: This package installs two web applications that can help managing this Tomcat instance. Once installed, you can access the <a href="manager/html">manager webapp</a> and the <a href="host-manager/html">host-manager webapp</a>.<p>

<p>NOTE: For security reasons, using the manager webapp is restricted to users with role "manager-gui". The host-manager webapp is restricted to users with role "admin-gui". Users are defined in <code>/etc/tomcat7/tomcat-users.xml</code>.</p>

<footer id="foot01"></footer>


</div>

<script src="script.js"></script>

</body>
</html>

Configure port

sudo apt-get install iptables
sudo iptables -A INPUT -i eth0 -p tcp --dport 80 -j ACCEPT
sudo iptables -A INPUT -i eth0 -p tcp --dport 8080 -j ACCEPT
sudo iptables -A PREROUTING -t nat -i eth0 -p tcp --dport 80 -j REDIRECT --to-port 8080

Validate port

sudo vi /var/lib/tomcat7/conf/server.xml

make sure the connector port is 80 and also add address element

    <Connector port="80" protocol="HTTP/1.1"
               connectionTimeout="20000"
               address="127.0.0.1"
               URIEncoding="UTF-8"
               redirectPort="8443" />

Edit tomcat7 file. Uncomment and change #AUTHBIND=no to yes

sudo vi /etc/default/tomcat7

Install authbind

sudo apt-get install authbind

Run the following commands to provide tomcat7 read+execute on port 80

sudo touch /etc/authbind/byport/80
sudo chmod 500 /etc/authbind/byport/80
sudo chown tomcat7 /etc/authbind/byport/80

JVM parameters

make sure tomcat points to right JAVA and has right JVM parameters

sudo vi /etc/default/tomcat7

Change the memory option on the line JAVA_OPTS="-Djava.awt.headless=true -Xmx128m -XX:+UseConcMarkSweeGC"

If you wish to designate a specific location for ThreadFix's temporary scratch folder, simply add "-Dthreadfix.scratchFolder=<Path/to/Scratch/Folder>", where "<Path/to/Scratch/folder>" is the location where temp files will be stored during scan uploads. The full JAVA_OPTS will then be: JAVA_OPTS="-Djava.awt.headless=true -Xmx128m -XX:+UseConcMarkSweeGC -Dthreadfix.scratchFolder=<Path/to/Scratch/Folder>"

startup scripts

startup and shutdown scripts can be found in: /usr/share/tomcat7/bin

We should restart Tomcat in order to implement our changes

sudo /etc/init.d/tomcat7 restart

Check Tomcat status

sudo service tomcat7 status

Validate port 8080

nc 127.0.0.1 8080 &> /dev/null; echo $?

this should output 0, showing 8080 is open. If 1 is returned then there is an issue with port 8080

Validate localhost

Validate if localhost is working fine

sudo apt-get install curl
curl -g -6 "http://localhost:8080/"

Installing Apache Bench

sudo apt-get install apache2-utils

on CentOS

yum install httpd-tools

Running Apache Bench

ab -c 60 -n 100000 http://localhost:8080/index.html

Running Apache Bench using scripts

Please see attached two scripts. (ab.sh and benchmark.sh) ab.sh will take two parameters 1. requests 2. concurrency

running ab.sh will produce data in data folder. running benchmark.sh inside of data folder will loop through all .tsv files and generate graphs.

LEG/Engineering/BigData/ApacheBench (last modified 2016-04-25 00:16:18)