DEV Community

Ameed Jamous for TelecomsXChange

Posted on • Edited on

NodeJS SMPP Stress Tester with configurable parameters

This script allows you to perform sending high number of SMS messages towards an SMPP server and configure parameters to control it's behavior.

It's easy to setup and works.

I hope you find it useful.

Installation

  • Clone repository to your machine

# git clone https://github.com/telecomsxchange/smpp-client-nodejs.git

Enter fullscreen mode Exit fullscreen mode

cd /smpp-client-nodejs/

Enter fullscreen mode Exit fullscreen mode
  • Install node modules

# npm install

# npm install system-sleep

Enter fullscreen mode Exit fullscreen mode
  • Open smpp-stress-tester.js in your code editor and configure SMPP HOST, PORT, USER, PASS, MESSAGES COUNT etc..


const nanoid = require('nanoid')
const sleep = require('system-sleep')

var smpp = require('smpp');

// define SMPP host and port

var session = smpp.connect('smpp://YOUR-SMPP-IP-OR-DOMAIN:PORT');

// If you're using TelecomsXChange as provider, this TLV will show the //price per message being sent out. 
// if you do not require it, you can comment it.

smpp.addTLV('billing_price', {
    id: 0x1520,
    type: smpp.types.tlv.string
});

// Configure test parameters

const test_sms_count = 5000;                // Number of SMS messages to send.
const req_sec_limit = 65;                   // Number of messages per second
const sleep_time = 1/req_sec_limit*1000;    // Sleep time / Wait for x secs
let i = 0
let test_end = 0
let start_test_ts = Math.floor(new Date() / 1000)
let end_test_ts
let failed_count = 0
var success_count = 0
let last_sms_sent_time = 0


session.bind_transceiver({

        //SMPP Credintials used during the test.

        system_id: 'ENTER SMPP USERNAME',
        password: 'ENTER SMPP PASSWORD'

}, function(pdu) {
    if (pdu.command_status == 0) {
        // Successfully bound
        start_test_ts = Math.floor(new Date() / 1000)
        for(i=0; i<test_sms_count; i++) {
            sleep(sleep_time)
            session.submit_sm({
                destination_addr: '{ENTER TO Number}',         // To Phone Number
                source_addr: '{ENTER FROM Number}',             // From Number or Sender ID
                registered_delivery: 1, 
                message_id: nanoid(24),
// Generate random verification code for every message. 
short_message: 'Your verification code is SS: ' + nanoid(4) ,    



// Uncomment below if your SMPP server supports message_payload for long text messages.

// message_payload: 'verification code AAA:' + nanoid(4)  

            }, function(pdu) {
                if (pdu.command_status == 0) {
                    // Message successfully sent
                    //console.log("message sent OK")
                    success_count++
                    end_test_ts = Math.floor(new Date() / 1000)
                } else {

          //console.log("message sending failed");
                    failed_count++
                    end_test_ts = Math.floor(new Date() / 1000)
                }
            });
            last_sms_sent_time = Math.floor(new Date() / 1000)
        }
    }
});


sleep(sleep_time * test_sms_count)
console.log("Finished sending, sleeping 30 secs");
const end_send_ts = Math.floor(new Date() / 1000);
sleep(10000)

// Console log the final report

console.log("Sent " + success_count + " SMS. Failed: " + failed_count + ". Total req/sec:" + (success_count / ( end_test_ts - start_test_ts)) + ". Waited for " + (end_test_ts - last_sms_sent_time) + " sec for last SMS" );
process.exit()

Enter fullscreen mode Exit fullscreen mode
  • Now, let's start SMPP test

#node smpp-stress-tester.js

Enter fullscreen mode Exit fullscreen mode
  • Sample Response

Finished sending, sleeping 30 secs
Sent 5000 SMS. Failed: 0. Total req/sec:50.5555555555555556. 

Waited for 1 sec for last SMS

Enter fullscreen mode Exit fullscreen mode

Top comments (0)