run_timer_tests.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. ////////////////////////////////////////////////////
  2. //
  3. // Usage : node run_tests.js [nb user keys] [nb packets to send per user] [nb Requests Before Wait] [wait time in seconds]
  4. //
  5. // Example : node run_tests.js 5 50 20 10
  6. // It will generate 5 userKeys and will send 50 packet for each userKey.
  7. // The process will wait 10 secons every 20 requests
  8. //
  9. //
  10. var dgram = require('dgram'),
  11. util = require('util');
  12. var DEBUG = true;
  13. /////////////////////////////////////////////////////////////////////////////
  14. // Send packets to statsd for each userKeys randomly
  15. // Open udp socket
  16. var client = dgram.createSocket("udp4");
  17. var send = function(host, port, message, closeSocket) {
  18. client.send(message, 0, message.length, port, host, function(err, bytes) {
  19. if(err) {
  20. client.close();
  21. process.stdout.write("\n");
  22. console.log("Error when sending packet ! Exit...");
  23. process.exit(-1);
  24. }
  25. if(closeSocket) {
  26. process.stdout.write("\n");
  27. console.log('Done sending packets.');
  28. client.close();
  29. }
  30. //console.log("Packet sent: " + message);
  31. });
  32. }
  33. console.log("Start sending...");
  34. var message = new Buffer("test_timer:256|ms");
  35. if(DEBUG) console.log(" - packet: " + message);
  36. // Send packet to statsd for this userKey
  37. process.stdout.write(".");
  38. send("localhost", 8125, message, true);