Codementor Events

Server testing with Siege

Published Jan 28, 2019Last updated Feb 02, 2019
Server testing with Siege

Introduction:
As a developer, you can have an exhausting list of possible toolkits for better development, however, if your tool kit has got no load testing utility, your kit is far from been complete.

A load testing utility helps to determine how much load your server could handle requests hitting the server with a configurable number of simulated clients.
To this testing utility, siege comes in handy.

Siege is an HTTP load testing and benchmarking utility. Its main purpose s for developers to subject their code to various degrees of duress and monitor how it will respond up to load on the internet. Siege supports basic authentication, cookies, HTTP, HTTPS, and FTP protocols.

Prerequisites

  1. An already existing server
  2. A working computer

Tools:

  1. Homebrew
  2. Seige
  3. NPM
  4. MongoDB

Steps:

  1. Install Siege
  2. Start your server
  3. Run siege command

Install Siege:
Siege installations differ from operating systems. For the sake of this tutorial, I'll be using a "Homebrew", a free and open-source software package management system that simplifies the installation of software on Mac OS.

To install on a Mac OS, run

 brew install siege

After this done, run

 siege.config

This will create the ~/.siegerc config file.
Optionally, to see the current settings in that file, run

 siege -C
  1. If you have an existing server hosted in the cloud proceed to step 3
    else clone a sample server hosted on git by running on your terminal
 git clone https://github.com/generalgmt/RESTfulAPITutorial.git 

After this, change your current location to the cloned repository(folder)

 cd RESTfulAPITutorial

Install all dependencies in the repository as specified in it's package.json.

 npm install

Start your MongoDB

 mongod

After all of these, we can then start the server by running

 npm run start

This should print out couple of info on your terminal.
Screen Shot 2019-01-29 at 12.36.25 AM.png
Now that our server is up and running, let's find out if it's good to go!

  1. Running Siege command
    The basic format for siege command: siege <options> and siege <options> [url]
    After starting our server, we would be testing one of the server’s endpoints “/tasks”, which is used to retrieve saved tasks by running
 siege -d1 -c10 -t1S localhost:3000/tasks

Where
-d is the delay before each request default: 3
-c is the number of concurrent users default: 10
-t is the time specified for the testing. This could be in seconds(S), minutes(M), or hour(H) eg: –t1H for a one hour test.
Check here for detailed instruction on the siege commands.
Screen Shot 2019-01-27 at 4.48.40 PM.png

Conclusion
It is always better to be on the safe side by testing your server performance and make the necessary adjustments if need be before your production deployment.
NOTE: The more the stress on your server the higher the concurrency value. Click here on how to calculate your concurrency.

Note: You can clear the Deprecation warning by adding

{useNewUrlParser: true} to the connect option in server.js such as
mongoose.connect('mongodb://localhost/Tododb', {useNewUrlParser: true});

Discover and read more posts from Olatunde Michael Garuba
get started
post commentsBe the first to share your opinion
Show more replies