xstress :: xk0derz SMTP Stress Testing Tool
(c) Amit Singh (aka xk0der), xk0der@users.sourceforge.net
blog.xkoder.com
SourceForge.net Logo
Tags: SMTP, E-Mail, Stress, Tool, Testing, C++, Open Source, Linux, Threads


The information out here may be outdated, please view the README file accompanying the source archive for upto-date infromation.


Disclaimer

This software and related files are licensed under GNU GPL version 2
Please visit the following webpage for more details
http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
or read the accompanying LICENSE file contained in the xstress package archive.

Special thanks to Bob Trower for the base64 utility he made
http://base64.sourceforge.net/
This utility is licensed under the MIT license
please see the b64.c source file for the complete license.

Introduction

xstress is an SMTP Stress Testing Tool. Essentially xstress
creates multiple connections to (your) mail server
and sends multiple mails repeatedly over all connections.

xstress understands only SMTP protocol. No authentication
mechanism is supported at the moment.

xstress may be used to stress test normal SMTP servers,
test Anti-Virus and Anti-Spam softwares that accept
or filter SMTP connections and the like.

using xstress you can specify a list of the following
to be used for sending mails
1) TO address list
2) FROM address list
3) SUBJECT list
4) list of BODY content files/directories
5) list of ATTACHMENT content files/directories

xstress randomly makes a combination from the available list and
sends mails to your SMTP server.

Building the binary

(xstress requires GNU GCC C/C++ compiler for source code compilation and
libc for execution).
Most linux distribution (like Fedora Core, Red Hat)
bundle these in their disribution, but distros like Ubuntu, normally do not have
these packages bundled. You'll need to download and install these packages to
compile the xstress source and run it properly.

To build the binary, uncompress the source archive using the following command

$ tar -zxvf xstress-src-n.nn-mmm-YYYYMMDD.tar.gz
where n.nn-mm-YYYYMMDD are the version and timestamp respectively.
example: xstress-src-1.00-stable-20010703.tar.gz

Now,
Switch user to root and type the following command from the directory
where you have un-compressed the xstress source archive and run the
following command to build the xstress binary.

# make

The above command will create the xtress binary in the bin folder
and copy the default xstress.conf file to the bin folder. If
the file already exists you'll be aksed if you want to over-write it
or not.

The make command also creates the base64 utility used by xstress
and copies it to the bin directory

** NOTE: base64 utility is required for xstress to send binary
attachments properly.

If you get any error while doing a `make',
run the following command befor you do make.

# make clean

Alternatively you may run the build shell script by typing

# ./build

which runs `make clean' first and then does a `make'

Usage and command line options

Move to the bin folder and type ./xstress to invoke the tool.

Syntax:
$ xstress [options]

Here options are one or more of the following...

-v, --ver, --versionDisplay xstress version and exit.
-h, --helpDisplay this help message
-t <value>, --threads <value> Set number of threads to spawn.
Range for value is 1 to 100, inclusive.
-m <value>, --mails <value> Set number of mails to send per thread.
range for value is 0 to 60000, inclusive.
* A Value of 0 for mails means unlimited mail.
-s <IP>, --server <IP> Set the mail server IP
IP is in dotted decimal format
-p <value>, --port <value> Set the mail server port
value is the port number of the mail server
--timeout <value> Set connection timeout (in seconds)
values is a non zero positive integer
--conf <filename> Configuration file to use, instead of the
default file 'xstress.conf'.
`filename` is the full path to the alternate
configuration file.
--logfile <filename> Set alternate log file to use, instead of the
default 'xstress.log' file.
`filename` is the full path to the alternate
log file.

**Note: command line options always override configuration file settings

Configuration file

By default xstress reads its configuration from the file 'xstress.conf'.
This file should be present from where you invoke the xstress program.

A typical configuration file consists of six sections. Out of these the
CONFIG section, TO section, SUBJECT section and FROM section are
compulsory.

COMMENTS start with the hash (#) sign on the 'first column only'.
Blank lines are ignored. The parser is not designed to handle extra spaces
so don't play with them.

Var = Value : will NOT work
Var=Val : will work!
   Var=Val : will NOT work

TO and FROM sections contains list of email addresses, one per line,
to be used as recipent address and sender address respectively.

SUBJECT Section contains list of subject text, one per line,
to used for e-mails being sent by xstress.

BODY Section contains list of (text) files or directory.
The content of these files is used as the mail's body text.
If a directory is specified, Content of all the files under
that directory is used as body text.

ATTACHMENT Sections contains list of (text) files or directory.
The listed files will be attached to the mails being sent out
from xstress. If a directory is specified, all files present
within that directory are used for attachment.

The file list or directory name can be prfixed by an optinal FILETYPE tag as follows.

[ATTACHMENT]
path/to/file!type
path/to/directory!type

The exclamation sign (!) separates the attachment file name from the type.
Following types ares understood by xstress.
1) bin - binary files
eg: MS Word document, compressed archives, MP3 files etc.
** Whenever in doubt use this type
2) plain - Plain text files
eg: Source Code, Text files, scripts etc.
3) html - HTML source
4) image - Image files
Any image file, treated as `bin' but disposition is inline.


CONFIG Section contains variables that configure the mail server
to be used, number of threads and the like.


Variables understood by xstress are described below

SERVER - Specify the SMTP Mail Server's IP here.
Example: 172.16.0.1

PORT - Specify the SMTP Mail Server's port number here.
This is typically 25.

THREADS - Specify number of threads to spwan
The value can range from 1 to 60,000
A Value of 15 is found to be optimum for
low end PCs.

A thread represents one connection to the Mails Server.

Higher the number of threads, more mails per second
can be sent by xstress, but the machine on which
xstress will be running might become
unresponsive.

MAILS_PER_THREAD - Speciy the number of mails to be sent per
thread. The value for this can range from
0 to 60,000.

value of ZERO means unlimited number of mails per
thread. You have to use ^C (control + C) to quit
xstress if you use ZERO for this variable.

REPORT_AFTER - Specify the number of mails, after which xstress will
print a message on screen.

A Value of ZERO means print no message.

Message Printed is in the format

Thread:: <id>: T: <num1>, S: <num2>, F: <num3>

Where
id is the thread ID
num1 is [T]otal number of mails to be sent for that thread
num2 is count of mails [S]ent succesfully
num3 is count of mails [F]ailed

LOG_FILE - Set the log file to be used if you dont want to use the
default log file 'xstress.log'

TIMEOUT - Specify connection timeout in seconds after which xstress
will give up.

TIP: If you are specifying ZERO for MAILS_PER_THREAD, put a low
value here, as you would not like xstress to wait for too long before
it sends a new mail. A low will timeout that session sonner and xstress
will try sending a new mail (taking corrective action if possible).

If you specify some amount of mails, you may like to put a large number
for TIMEOUT, so that before calling it quit, xstress will wait to see
if the server responds.

View example configuration file: xstress.conf

Example attachment and body files

The bin directory contains some example body and attachment files.
The default configuration file xstress.conf lists these files to be
used as body and attachment for the mail.

Body Files:
body1.txt - Plain Text file
body_dir/body2.txt - Plain Text file

Attachment Files:
attach_dir/images_dir/xstress.jpg- Image file
attach_dir/attach1.htm - HTML File


* The source code has been tested with GNU C/C++ compiler version 4.1.2 20070502

Local Test Result

[Test : 1]
Setup
Client Machine: Ubuntu Fiesty, Pentium Dual Core, 512MB Ram
Server: SendMail on Fedora Core 7, Pentium D (One core switched off), 1 GB RAM, 40 GB Free HDD
Average Message size: ~4KB (including attachment)
Number of threads: 10
Mails per thread: unlimited
Report After: every 5 mails (per thread)
Server Timeout: 5 seconds
Result
(a) Total Mails Sent Successfully: 10,103.
(b) Mails Failed (Server Timeout): 2010. (Average of 10 threads)
Total Mails Tried (a)+(b) = 12,113.
Time Taken: 44 minutes, 13.358 seconds
Average Mails/minute: 228.47 mails

[Test : 2]
Setup
Client Machine: Ubuntu Fiesty, Pentium Dual Core, 512MB Ram
Server: SendMail on Fedora Core 7, Pentium D (One core switched off), 1 GB RAM, 40 GB Free HDD
Average Message size: ~4KB (including attachment)
Number of threads: 25
Mails per thread: unlimited
Report After: every 5 mails (per thread)
Server Timeout: 5 seconds
Result
(a) Total Mails Sent Successfully: 10,151.
(b) Mails Failed (Server Timeout): 2000. (Average of 25 threads)
Total Mails Tried (a)+(b) = 12,151.
Time Taken: 17 minutes, 50.132 seconds
Average Mails/minute: 569.32 mails

[Test : 3]
Setup
Client Machine: Ubuntu Fiesty, Pentium Dual Core, 512MB Ram
Server: SendMail on Fedora Core 7, Pentium D (One core switched off), 1 GB RAM, 40 GB Free HDD
Average Message size: ~4KB (including attachment)
Number of threads: 100
Mails per thread: unlimited
Report After: every 5 mails (per thread)
Server Timeout: 5 seconds
Result
(a) Total Mails Sent Successfully: 12,067.
(b) Mails Failed (Server Timeout): 3000. (Average of 100 threads)
Total Mails Tried (a)+(b) = 15,067.
Time Taken: 6 minutes, 57.059 seconds
Average Mails/minute: 1736.26 mails

Notes
- Timing was done using the `time' tool.
- Both systesm were being used for normal usage (like file searching, browsing, text edititing etc) while the test was being conducted.
- To increase mail traffic on your test setup, increase the number of threads, leave your system idle :) or deploy more client machines running xstress.

If you have better stats, write to me with details at: xk0der@users.sourceforge.net