Girish Ramakrishnan 1 year ago
parent
commit
c5cebea279
3 changed files with 38 additions and 27 deletions
  1. 31 0
      load
  2. 0 21
      nodeload.js
  3. 7 6
      package-lock.json

+ 31 - 0
load

@@ -0,0 +1,31 @@
+#!/usr/bin/env node
+
+'use strict';
+
+const async = require('async'),
+      program = require('commander'),
+      request = require('request');
+
+program
+  .version('0.1.0')
+  .usage('-n total -c concurrency')
+  .option('-n, --total <total>', 'Total requests', parseInt)
+  .option('-c, --concurrency <concurrent>', 'Concurrent requests', parseInt)
+  .parse(process.argv);
+
+const totalRequests = program.total || 100, concurrency = program.concurrency || 10;
+
+console.log(`Making ${totalRequests} with a concurrency of ${concurrency}`);
+
+const coll = Array(totalRequests).fill().map((x,i)=>i);
+
+async.mapLimit(coll, concurrency, function makeRequest(i, iteratorDone) {
+    request('http://test.smartserver.space', function (error, response, body) {
+        iteratorDone(null, { error: error, statusCode: response && response.statusCode });
+    });
+}, function (error, results) {
+    console.log('Errored:', results.filter((x) => x.error).length);
+    console.log('OK:', results.filter((x) => x.statusCode === 200).length);
+    console.log('done', results.length);
+});
+

+ 0 - 21
nodeload.js

@@ -1,21 +0,0 @@
-'use strict';
-
-const async = require('async'),
-      request = require('request');
-
-const totalRequests = 100, concurrency = 10;
-
-const coll = Array(totalRequests).fill().map((x,i)=>i);
-
-async.mapLimit(coll, concurrency, function makeRequest(i, iteratorDone) {
-    request('http://test.smartserver.space', function (error, response, body) {
-        // console.log('error:', error); // Print the error if one occurred
-        // console.log('statusCode:', response && response.statusCode); // Print the response status code if a response was received
-        // console.log('body:', body); // Print the HTML for the Google homepage.
-        iteratorDone(null, { error: error, statusCode: response && response.statusCode });
-    });
-}, function (error, results) {
-    console.log(error);
-    console.log('done', results.length);
-});
-

+ 7 - 6
package-lock.json

@@ -50,7 +50,6 @@
       "version": "1.0.1",
       "resolved": "https://registry.npmjs.org/bcrypt-pbkdf/-/bcrypt-pbkdf-1.0.1.tgz",
       "integrity": "sha1-Y7xdy2EzG5K8Bf1SiVPDNGKgb40=",
-      "optional": true,
       "requires": {
         "tweetnacl": "0.14.5"
       }
@@ -81,6 +80,11 @@
         "delayed-stream": "1.0.0"
       }
     },
+    "commander": {
+      "version": "2.15.1",
+      "resolved": "https://registry.npmjs.org/commander/-/commander-2.15.1.tgz",
+      "integrity": "sha512-VlfT9F3V0v+jr4yxPc5gg9s62/fIVWsd2Bk2iD435um1NlGMYdVCq+MjcXnhYq2icNOizHr1kK+5TI6H0Hy0ag=="
+    },
     "core-util-is": {
       "version": "1.0.2",
       "resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.2.tgz",
@@ -121,7 +125,6 @@
       "version": "0.1.1",
       "resolved": "https://registry.npmjs.org/ecc-jsbn/-/ecc-jsbn-0.1.1.tgz",
       "integrity": "sha1-D8c6ntXw1Tw4GTOYUj735UN3dQU=",
-      "optional": true,
       "requires": {
         "jsbn": "0.1.1"
       }
@@ -222,8 +225,7 @@
     "jsbn": {
       "version": "0.1.1",
       "resolved": "https://registry.npmjs.org/jsbn/-/jsbn-0.1.1.tgz",
-      "integrity": "sha1-peZUwuWi3rXyAdls77yoDA7y9RM=",
-      "optional": true
+      "integrity": "sha1-peZUwuWi3rXyAdls77yoDA7y9RM="
     },
     "json-schema": {
       "version": "0.2.3",
@@ -370,8 +372,7 @@
     "tweetnacl": {
       "version": "0.14.5",
       "resolved": "https://registry.npmjs.org/tweetnacl/-/tweetnacl-0.14.5.tgz",
-      "integrity": "sha1-WuaBd/GS1EViadEIr6k/+HQ/T2Q=",
-      "optional": true
+      "integrity": "sha1-WuaBd/GS1EViadEIr6k/+HQ/T2Q="
     },
     "uuid": {
       "version": "3.2.1",