🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Book a DemoInstallSign in
Socket

timeoutengine

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

timeoutengine

Simple node module to find the 99%ile timeout value.

0.1.0
latest
Source
npm
Version published
Weekly downloads
2
Maintainers
1
Weekly downloads
 
Created
Source

node-timeoutengine

Simple node module to find the 99%ile timeout value.

var wreck = require('wreck');
var timeoutengine = require('timeoutengine');


var defaultTimeout = 5000;
var serviceName = 'httpbin_get';

 function makeServiceCall(callback) {
    var options = {
        timeout: timeoutengine.getSocketTimeout(serviceName) || defaultTimeout
    };
    var reqStart = Date.now();
    var req = wreck.get('http://httpbin.org/get', options, function (err, response, payload) {

        timeoutengine.addSocketDuration(serviceName, Date.now() - reqStart);    //pumping the socket duration

        if (!err && response && response.statusCode === 200 && payload) {
            //console.log(payload.toString());
            // do something this payload
        }
        callback();
    });
}

Problem statement

I am making a service call from node and hardcoding a fixed socketTimeout (or connectTimeout) value for the same. I am not sure that is the ideal value I can use?

TimeoutEngine

TimeoutEngine has API to feed the connect/socket durations and after let say N (default 100) request start returning the 99%ile + delta value. This is useful if you need adaptive timeout value based on the current server/network conditions.

API

  • configure(options) - [Optional] Use if you want a different default config.
  • addDuration(key, value) - Generic addDuration API
  • getTimeout(key) - Generic getTimeout API
  • addConnectDuration(key, value) - Call this API to feed the connect duration of a service call for successful as well as failed requests.
  • addSocketDuration(key, value) - Call this API to feed the socket duration of a service call for successful as well as failed requests.
  • getConnectTimeout(key) - Returns this 99%ile + delta connect Timeout value
  • getSocketTimeout(key) - Returns this 99%ile + delta socket Timeout value

FAQs

Package last updated on 23 Mar 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts