From 5833eecc54af1176a3bc51b4785dd94981aa41d9 Mon Sep 17 00:00:00 2001 From: Quentin De Coninck Date: Tue, 28 Feb 2017 21:08:58 +0100 Subject: [PATCH] msg: change size of messages --- src/mpExperienceMsg.py | 5 +++-- src/mpParamXp.py | 2 ++ src/msg_client.py | 8 ++++---- src/msg_server.py | 3 ++- 4 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/mpExperienceMsg.py b/src/mpExperienceMsg.py index 03c4a17..3785707 100644 --- a/src/mpExperienceMsg.py +++ b/src/mpExperienceMsg.py @@ -36,6 +36,7 @@ class MpExperienceMsg(MpExperience): self.client_sleep = self.xpParam.getParam(MpParamXp.MSGCLIENTSLEEP) self.server_sleep = self.xpParam.getParam(MpParamXp.MSGSERVERSLEEP) self.nb_requests = self.xpParam.getParam(MpParamXp.MSGNBREQUESTS) + self.bytes = self.xpParam.getParam(MpParamXp.MSGBYTES) def prepare(self): MpExperience.prepare(self) @@ -46,14 +47,14 @@ class MpExperienceMsg(MpExperience): def getMsgServerCmd(self): s = "python " + os.path.dirname(os.path.abspath(__file__)) + \ - "/msg_server.py --sleep " + self.server_sleep + " &>" + MpExperienceMsg.SERVER_LOG + "&" + "/msg_server.py --sleep " + self.server_sleep + " --bytes " + self.bytes + " &>" + MpExperienceMsg.SERVER_LOG + "&" print(s) return s def getMsgClientCmd(self): s = "python " + os.path.dirname(os.path.abspath(__file__)) + \ "/msg_client.py --sleep " + self.client_sleep + " --nb " + self.nb_requests + \ - " >" + MpExperienceMsg.CLIENT_LOG + " 2>" + MpExperienceMsg.CLIENT_ERR + " --bytes " + self.bytes + " >" + MpExperienceMsg.CLIENT_LOG + " 2>" + MpExperienceMsg.CLIENT_ERR print(s) return s diff --git a/src/mpParamXp.py b/src/mpParamXp.py index 36ff5b7..6a6538b 100644 --- a/src/mpParamXp.py +++ b/src/mpParamXp.py @@ -63,6 +63,7 @@ class MpParamXp(MpParam): MSGCLIENTSLEEP = "msgClientSleep" MSGSERVERSLEEP = "msgServerSleep" MSGNBREQUESTS = "msgNbRequests" + MSGBYTES = "msgBytes" PRIOPATH0 = "prioPath0" PRIOPATH1 = "prioPath1" BACKUPPATH0 = "backupPath0" @@ -155,6 +156,7 @@ class MpParamXp(MpParam): defaultValue[MSGCLIENTSLEEP] = "5.0" defaultValue[MSGSERVERSLEEP] = "5.0" defaultValue[MSGNBREQUESTS] = "5" + defaultValue[MSGBYTES] = "1200" defaultValue[PRIOPATH0] = "0" defaultValue[PRIOPATH1] = "0" defaultValue[BACKUPPATH0] = "0" diff --git a/src/msg_client.py b/src/msg_client.py index 9398379..3c92de2 100644 --- a/src/msg_client.py +++ b/src/msg_client.py @@ -7,7 +7,6 @@ import time BUFFER_SIZE = 2048 ENCODING = 'ascii' -MSG_SIZE = 1200 threads = {} to_join = [] @@ -16,6 +15,7 @@ parser = argparse.ArgumentParser(description="Msg client") parser.add_argument("-s", "--sleep", type=float, help="sleep time between two sendings", default=5.0) parser.add_argument("-n", "--nb", type=int, help="number of requests done", default=5) parser.add_argument("-B", "--bulk", help="if set, don't wait for reply to send another packet", action="store_true") +parser.add_argument("-b", "--bytes", type=float, help="number of bytes to send and receive", default=1200) args = parser.parse_args() @@ -41,7 +41,7 @@ delays = [] try: for i in range(args.nb): time.sleep(args.sleep) - request = string_generator(size=MSG_SIZE, chars=string.digits) + request = string_generator(size=args.bytes, chars=string.digits) start_time = datetime.datetime.now() sock.sendall(request.encode(ENCODING)) @@ -49,7 +49,7 @@ try: continue buffer_data = "" - while len(buffer_data) < MSG_SIZE: + while len(buffer_data) < args.bytes: data = sock.recv(BUFFER_SIZE).decode(ENCODING) if len(data) == 0: @@ -58,7 +58,7 @@ try: buffer_data += data - if len(buffer_data) == MSG_SIZE: + if len(buffer_data) == args.bytes: stop_time = datetime.datetime.now() delays.append(stop_time - start_time) else: diff --git a/src/msg_server.py b/src/msg_server.py index 0f9ae74..d29272b 100644 --- a/src/msg_server.py +++ b/src/msg_server.py @@ -14,6 +14,7 @@ to_join = [] parser = argparse.ArgumentParser(description="Msg server") parser.add_argument("-s", "--sleep", type=float, help="sleep time between reception and sending", default=5.0) +parser.add_argument("-b", "--bytes", type=float, help="number of bytes to send and receive", default=1200) args = parser.parse_args() @@ -95,7 +96,7 @@ conn_id = 0 while True: # Wait for a connection connection, client_address = sock.accept() - thread = HandleClientConnectionThread(connection, client_address, conn_id, 1200) + thread = HandleClientConnectionThread(connection, client_address, conn_id, args.bytes) threads[conn_id] = thread conn_id += 1 thread.start()