# Copyright (c) 2016, Diana Andreea Popescu
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# * Redistributions of source code must retain the above copyright notice, this
#   list of conditions and the following disclaimer.
#
# * Redistributions in binary form must reproduce the above copyright notice,
#   this list of conditions and the following disclaimer in the documentation
#   and/or other materials provided with the distribution.
#
# * Neither the name of the project, the copyright holder nor the names of its
#  contributors may be used to endorse or promote products derived from
#   this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.


This file documents the process required to run the motivation tests.
Note that the process may change between platforms and OS.

Step 1: Benchmarks Installation
======================
These instructions are valid for Ubuntu/Debian OS.

-------------------------
1. Apache benchmark (ab) for Apache web server

a. Server installation on the server machine:
sudo apt-get install apache2
a1. Disable access log in /etc/apache2/sites-available/000-default.conf by
commenting the line CustomLog ${APACHE_LOG_DIR}/access.log combined, in order 
to avoid running out of disk space. 
b. Client installation on the client machine:
sudo apt-get install apache2-utils

--------------------------
2. Memaslap benchmark for Memcached server

a. Server installation on the server machine:
sudo apt-get install memcached
b. Edit the configuration file with the server IP address in order for the 
client to be able to make requests to it over the network
vim /etc/memcached.cnf
c. Start the memcached server
sudo service memcached start
d. Client installation:
d1. Download the libmemcached library from http://libmemcached.org/libMemcached.html 
under Downloads link.
d2. Use ./configure --enable-memaslap in order to build the memaslap benchmark.
If memaslap is not built, then edit the generated Makefile manually by uncommenting
the lines that refer to memaslap.
d3. Apply the following patch to the clients/ folder in the libmemcached-1.0.18/ folder 
http://www.cl.cam.ac.uk/Research/SRG/netos/qjump/nsdi2015/patches/libmemcached-1.0.15_clients.patch
in order to log the latency of each request-response.
d4. make
d5. Install libevent-dev library:
sudo apt-get install libevent-dev
d6. In case building the source code results in failure related to pthread, edit
the LDFLAGS in the Makefile 
LDFLAGS = -L/lib64 -lpthread 
d7. sudo make install
-----------------------------
3. TPC-C benchmark for MySQL server

a. Server installation
sudo apt-get install mysql-server
a1. Clone the https://github.com/Percona-Lab/tpcc-mysql repository and follow their
installation instructions to build the program that will load the data. Our 
benchmarks used a database with 50 warehouses and the name of the database is 
tpcc50.
a2. Make the tpcc50 database accessible to a remote client by using the following
GRANT ALL ON tpcc50.* TO user@CLIENT_IP_ADDRESS IDENTIFIED BY 'userpassword';
a3. Edit /etc/mysql/my.cnf bind-address line with the SERVER_IP_ADDRESS and restart
the MySQL server.

b. Client Installation
Clone the https://github.com/Percona-Lab/tpcc-mysql repository and follow their 
installation instructions.

Step 2: NetFPGA SUME Configuration for Latency Gadget
=============================
See instructions on how to configure the latency in the delay module here:
https://github.com/NetFPGA/NetFPGA-SUME-public/wiki/Latency-Gadget:-delay_mb-Contrib-Project
and
https://github.com/NetFPGA/NetFPGA-SUME-public/wiki/Getting-Started-Guide

Step 3: Running the experiment
======================

Configure the network interfaces of the client and server that you are going to use
and edit the Makefile IP_DST and IP_SRC parameters.

Use the Makefile provided in the motivation-test/ folder to run the experiments.
You can set there the following parameters:
IP_DST = IP address of the server
IP_SRC = IP address of the client
ADDED_DELAY_NSEC = the value of the added delay using the Latency Gadget on the
server side
NUMBER_OF_RUNS = how many times the benchmark is run
SLEEP_TIME = sleep time between runs of the same benchmark
OUTPUT_DIRECTORY = the directory where the output files will be stored
