Node-RED generic throughput benchmark

The flow intends to measure the throughput of a simple message stream in the Node-RED environment.

Target throughput can be set in the first inject node from the period between message arrival.

Storing of samples can be triggered in a configurable manner (initially every 30 seconds) and stored in a local csv file as (target, achieved) values (file location needs to be set).

[{"id":"ee073ff3.acc6c8","type":"inject","z":"bf1a9230.103fc8","name":"INSERT TARGET THROUGHPUT","topic":"","payload":"{\"created_at\":\"Sun May 28 10:53:46 +0000 2017\",\"id\":868782342617354200,\"id_str\":\"868782342617354241\",\"text\":\"📸_earlgreyxx\\n\\nI’m under the gun again @ WRONG WAY BAR https://t.co/jyd4Ka8YoW\",\"source\":\"<a href=\\\"http://instagram.com\\\" rel=\\\"nofollow\\\">Instagram</a>\",\"truncated\":false,\"in_reply_to_status_id\":null,\"in_reply_to_status_id_str\":null,\"in_reply_to_user_id\":null,\"in_reply_to_user_id_str\":null,\"in_reply_to_screen_name\":null,\"user\":{\"id\":504890538,\"id_str\":\"504890538\",\"name\":\"Iris\",\"screen_name\":\"Ori_Orina\",\"location\":\"Madrid\",\"url\":\"https://www.instagram.com/welcometomordor/\",\"description\":\"Don't apologize; I hope you choke and die.\",\"protected\":false,\"verified\":false,\"followers_count\":197,\"friends_count\":342,\"listed_count\":0,\"favourites_count\":2715,\"statuses_count\":10663,\"created_at\":\"Sun Feb 26 19:30:55 +0000 2012\",\"utc_offset\":7200,\"time_zone\":\"Madrid\",\"geo_enabled\":true,\"lang\":\"es\",\"contributors_enabled\":false,\"is_translator\":false,\"profile_background_color\":\"1A1B1F\",\"profile_background_image_url\":\"http://pbs.twimg.com/profile_background_images/523930443633025024/MlHrTL-D.jpeg\",\"profile_background_image_url_https\":\"https://pbs.twimg.com/profile_background_images/523930443633025024/MlHrTL-D.jpeg\",\"profile_background_tile\":true,\"profile_link_color\":\"000000\",\"profile_sidebar_border_color\":\"FFFFFF\",\"profile_sidebar_fill_color\":\"252429\",\"profile_text_color\":\"666666\",\"profile_use_background_image\":true,\"profile_image_url\":\"http://pbs.twimg.com/profile_images/841036454893621248/HGrdFU4Q_normal.jpg\",\"profile_image_url_https\":\"https://pbs.twimg.com/profile_images/841036454893621248/HGrdFU4Q_normal.jpg\",\"profile_banner_url\":\"https://pbs.twimg.com/profile_banners/504890538/1466452683\",\"default_profile\":false,\"default_profile_image\":false,\"following\":null,\"follow_request_sent\":null,\"notifications\":null},\"geo\":{\"type\":\"Point\",\"coordinates\":[40.4264,-3.70521]},\"coordinates\":{\"type\":\"Point\",\"coordinates\":[-3.70521,40.4264]},\"place\":{\"id\":\"206c436ce43a43a3\",\"url\":\"https://api.twitter.com/1.1/geo/id/206c436ce43a43a3.json\",\"place_type\":\"city\",\"name\":\"Madrid\",\"full_name\":\"Madrid, España\",\"country_code\":\"ES\",\"country\":\"España\",\"bounding_box\":{\"type\":\"Polygon\",\"coordinates\":[[[-3.889005,40.312071],[-3.889005,40.643518],[-3.51801,40.643518],[-3.51801,40.312071]]]},\"attributes\":{}},\"contributors\":null,\"is_quote_status\":false,\"retweet_count\":0,\"favorite_count\":0,\"entities\":{\"hashtags\":[],\"urls\":[{\"url\":\"https://t.co/jyd4Ka8YoW\",\"expanded_url\":\"https://www.instagram.com/p/BUoiVMQAWTK/\",\"display_url\":\"instagram.com/p/BUoiVMQAWTK/\",\"indices\":[54,77]}],\"user_mentions\":[],\"symbols\":[]},\"favorited\":false,\"retweeted\":false,\"possibly_sensitive\":false,\"filter_level\":\"low\",\"lang\":\"en\",\"timestamp_ms\":\"1495968826332\"}","payloadType":"json","repeat":"1","crontab":"","once":false,"x":184.5,"y":118,"wires":[["b3fc19a2.fcbdf8"]]},{"id":"b3fc19a2.fcbdf8","type":"function","z":"bf1a9230.103fc8","name":"add","func":"context.global.set('counter',(context.global.get('counter')+1));\nreturn msg;","outputs":1,"noerr":0,"x":441.5,"y":119,"wires":[[]]},{"id":"4e5ead53.8f7b2c","type":"inject","z":"bf1a9230.103fc8","name":"INSERT sample interval","topic":"","payload":"1","payloadType":"num","repeat":"30","crontab":"","once":false,"x":116,"y":277,"wires":[["f05e7fa2.3db6f8"]]},{"id":"f05e7fa2.3db6f8","type":"function","z":"bf1a9230.103fc8","name":"calculate Throughput","func":"var period=msg.payload;\nmsg.payload={};\n\n\nvar now=Date.now();\n//calculate time difference\nvar diff=(now-context.global.get('startTime'))/1000;\n//calculate target msgs/sec\nmsg.payload.target=(1/period);\n//calculate actual msgs/sec\nmsg.payload.actual=(context.global.get('counter'))/diff;\n\ncontext.global.set('counter',0);\ncontext.global.set('startTime',Date.now());\n\nmsg.payload.boxes=context.global.currentBoundingBoxes.length;\nreturn msg;","outputs":1,"noerr":0,"x":336.16668701171875,"y":220.33346557617188,"wires":[["9baeb16.4e001d"]]},{"id":"9baeb16.4e001d","type":"csv","z":"bf1a9230.103fc8","name":"","sep":",","hdrin":"","hdrout":"","multi":"one","ret":"\\n","temp":"target, actual","x":514.5,"y":220.00006103515625,"wires":[["c17b1e14.8daed","26388c90.869ac4"]]},{"id":"26388c90.869ac4","type":"debug","z":"bf1a9230.103fc8","name":"","active":true,"console":"false","complete":"payload","x":680,"y":186.00006103515625,"wires":[]},{"id":"c17b1e14.8daed","type":"file","z":"bf1a9230.103fc8","name":"Store result-CONFIG PATH","filename":"/home/user/rate","appendNewline":false,"createDir":false,"overwriteFile":"false","x":730.8333129882812,"y":263.3333435058594,"wires":[]},{"id":"b2603e5c.505538","type":"comment","z":"bf1a9230.103fc8","name":"Period between messages","info":"The period interval between messages (that dictates\nthe final target throughput) should be included as\ninterval in this inject node","x":115,"y":77.85714721679688,"wires":[]},{"id":"83a0cd4e.2ccc18","type":"comment","z":"bf1a9230.103fc8","name":"Main flow","info":"The main flow accepts incoming messages and \ntries to achieve target throughput. Each message\nis looped around all registered boxes (users)\nand when this is done the global counter \nis increased.","x":358.5,"y":73.00000762939453,"wires":[]},{"id":"2a96efdd.e9462","type":"comment","z":"bf1a9230.103fc8","name":"Sample and store","info":"In each trigger, the sample flow retrieves values\nfor the counter and timestamp and calculates the \nmessage per second metric based on these, storing\nthem at a file (configuration needed for the location\nof the file). At the end it resets these counters","x":116,"y":226,"wires":[]},{"id":"a1178214.9d0128","type":"comment","z":"bf1a9230.103fc8","name":"Payload definition of sample interval","info":"For accurate inclusion of the target throughput\nyou need to insert as payload the same period\nyou have included in the \"Insert Target Throughput\"\ninject node","x":283.5,"y":321.5714416503906,"wires":[]},{"id":"855fe793.5fe6d","type":"inject","z":"bf1a9230.103fc8","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"x":84,"y":512,"wires":[["eb6ee70d.509438"]]},{"id":"eb6ee70d.509438","type":"function","z":"bf1a9230.103fc8","name":"global get","func":"msg.payload={};\nmsg.payload.counter=context.global.get('counter');\nmsg.payload.timestamp=context.global.get('startTime');\nreturn msg;","outputs":1,"noerr":0,"x":224.5,"y":509,"wires":[["2e004f67.8f0a28"]]},{"id":"2e004f67.8f0a28","type":"debug","z":"bf1a9230.103fc8","name":"","active":true,"console":"false","complete":"payload","x":385.5,"y":509,"wires":[]},{"id":"cacb8504.c18068","type":"comment","z":"bf1a9230.103fc8","name":"Initialization","info":"","x":79,"y":561.0000305175781,"wires":[]},{"id":"7b862ec1.97e2b8","type":"comment","z":"bf1a9230.103fc8","name":"Monitoring","info":"","x":86.33331298828125,"y":466,"wires":[]},{"id":"301a48ca.4d0de8","type":"inject","z":"bf1a9230.103fc8","name":"Initialization","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":true,"x":75,"y":605,"wires":[["d4713f36.ea8368"]]},{"id":"d4713f36.ea8368","type":"function","z":"bf1a9230.103fc8","name":"set global variables for throughput","func":"context.global.set('counter',0);\n\ncontext.global.set('startTime',Date.now());\nreturn msg;","outputs":1,"noerr":0,"x":329,"y":605,"wires":[[]]}]
gkousiou

Flow Info

created 2 months, 3 weeks ago

Node Types

Core
  • comment (x6)
  • csv (x1)
  • debug (x2)
  • file (x1)
  • function (x4)
  • inject (x4)

Tags

  • Benchmark
  • Performance
  • Throughput
  • messages/sec
Copy this flow JSON to your clipboard and then import into Node-RED using the Import From > Clipboard (Ctrl-I) menu option