def main(): global trafficBytes1, trafficPackets1, startTime if len(sys.argv) != 4: print 'Usage: ' + sys.argv[0] + ' nClients pollInterval pubInterval' exit(1) dstIP = 'www.wsn430.pan' nClients = int(sys.argv[1]) pollInterval = float(sys.argv[2]) pubInterval = float(sys.argv[3]) if pollInterval == 0: if pubInterval == 0: dstURL = '/time/cometRand' else: dstURL = '/time/comet%ds' % pubInterval elif pollInterval == -1: if pubInterval == 0: dstURL = '/time/lpRand' else: dstURL = '/time/lp%ds' % pubInterval else: if pubInterval == 0: dstURL = '/time/timeRand' else: dstURL = '/time/time' print 'Number of clients: %d' % nClients if pollInterval == 0: print 'Comet mode' elif pollInterval == -1: print 'Long polling mode' else: print 'Polling interval: %.3f seconds' % pollInterval if pubInterval == 0: print 'Publish interval: random' else: print 'Publish interval: %.3f seconds' % pubInterval os.system('cat /proc/net/dev | grep sl0 > .net_stats') devStats = filter(lambda c: c != '', open('.net_stats', 'r').readline().split(' ')) trafficBytes1 = int(devStats[1]) + int(devStats[9]) trafficPackets1 = int(devStats[2]) + int(devStats[10]) startTime = datetime.now() benchTools.start(dstIP, dstURL, nClients, pollInterval, pubInterval) signal.signal(signal.SIGALRM, alarm_handler) signal.alarm(2) while 1: time.sleep(1)
def main(): global trafficBytes1,trafficPackets1,startTime if len(sys.argv) != 4: print 'Usage: ' + sys.argv[0] + ' nClients pollInterval pubInterval' exit(1) dstIP = 'www.wsn430.pan' nClients = int(sys.argv[1]) pollInterval = float(sys.argv[2]) pubInterval = float(sys.argv[3]) if pollInterval == 0: if pubInterval == 0: dstURL = '/time/cometRand' else: dstURL = '/time/comet%ds' %pubInterval elif pollInterval == -1: if pubInterval == 0: dstURL = '/time/lpRand' else: dstURL = '/time/lp%ds' %pubInterval else: if pubInterval == 0: dstURL = '/time/timeRand' else: dstURL = '/time/time' print 'Number of clients: %d' % nClients if pollInterval == 0: print 'Comet mode' elif pollInterval == -1: print 'Long polling mode' else: print 'Polling interval: %.3f seconds' % pollInterval if pubInterval == 0: print 'Publish interval: random' else: print 'Publish interval: %.3f seconds' % pubInterval os.system('cat /proc/net/dev | grep sl0 > .net_stats') devStats = filter(lambda c: c != '',open('.net_stats', 'r').readline().split(' ')) trafficBytes1 = int(devStats[1]) + int(devStats[9]) trafficPackets1 = int(devStats[2]) + int(devStats[10]) startTime = datetime.now() benchTools.start(dstIP,dstURL,nClients,pollInterval,pubInterval) signal.signal(signal.SIGALRM, alarm_handler) signal.alarm(2) while 1: time.sleep(1)
def main(): if len(sys.argv) != 4: print 'Usage: ' + sys.argv[0] + ' nClients pollInterval pubInterval' exit(1) dstIP = 'www.wsn430.pan' nClients = int(sys.argv[1]) pollInterval = float(sys.argv[2]) pubInterval = float(sys.argv[3]) print "Configuration %d %d %d" %(nClients, pollInterval, pubInterval) print "Timestamp %s" %datetime.now() if pollInterval == 0: if pubInterval == 0: dstURL = '/time/cometRand' else: dstURL = '/time/comet%ds' %pubInterval elif pollInterval == -1: if pubInterval == 0: dstURL = '/time/lpRand' else: dstURL = '/time/lp%ds' %pubInterval else: if pubInterval == 0: dstURL = '/time/timeRand' else: dstURL = '/time/time' benchTools.start(dstIP,dstURL,nClients,pollInterval,pubInterval) if pubInterval == 0: timeout = int(200) else: timeout = int(50 + max(3*max(pubInterval,pollInterval),nClients/2)) print 'Timeout: %d' %timeout maxInitTimer = datetime.now() + timedelta(seconds = timeout) while benchTools.toWait > 0 or benchTools.firstReceiveTime == None: if datetime.now() > maxInitTimer: print 'init error' sys.exit(1) else: time.sleep(1) if pubInterval == 0: timeToSleep = 500 else: elapsed = benchTools.timeDeltaToMillis(datetime.now() - benchTools.firstReceiveTime) / 1000. basicWait = max(150,5 * pubInterval) timeToSleep = basicWait + (pubInterval - elapsed % pubInterval - 2) os.system('cat /proc/net/dev | grep sl0 > .net_stats') devStats = filter(lambda c: c != '',open('.net_stats', 'r').readline().split(' ')) trafficBytes1 = int(devStats[1]) + int(devStats[9]) trafficPackets1 = int(devStats[2]) + int(devStats[10]) startTime = datetime.now() print 'Sleep %d' %timeToSleep time.sleep(timeToSleep) endTime = datetime.now() deltaTimeSec = benchTools.timeDeltaToMillis(endTime - startTime) / 1000. os.system('cat /proc/net/dev | grep sl0 > .net_stats') devStats = filter(lambda c: c != '',open('.net_stats', 'r').readline().split(' ')) os.remove('.net_stats') trafficBytes2 = int(devStats[1]) + int(devStats[9]) trafficPackets2 = int(devStats[2]) + int(devStats[10]) printResults((trafficBytes2 - trafficBytes1) / float(deltaTimeSec),(trafficPackets2 - trafficPackets1) / float(deltaTimeSec))