In: Computer Science
Client must support load-test mode, in this mode, echo client opens a number of concurrent connections, sends a predefined message on each connection, waits for echo message back from server, and records time. User should be able to specify total number of messages to be sent concurrently from client.
Here is an example run of new mode
$python advanced_echo.py load_test 1000
Above, should cause client to attempt 1000 connections CONCURRENTLY, send predefined message, wait for echo back and record time it took each of 1000 connections to close.
Output of client should look like:
CON-1: duration: 20ms
CON-2: duration: 19ms
Answer : Given That
Duration of CON-1 is 20ms & Duration of CON-2 is 19ms.
Using Python Code :
# import the required modules
# requests to send http requests
import requests
# time, to measure the response time
import time
# sys, to parse the cli arguments
import sys
# get the number of concurrent connections to be established
n = int(sys.argv[2])
# send request for n times
for i in range(n):
# get the current time
start = time.time()
# send the request and wait for the response
resp = requests.get('<REQUEST_URL>')
# get the current time
end = time.time()
# get duration
duration = end - start
# print message
print("CON-%s: duration: %sms" % (i+1, round(duration*1000)))
Output :
____________THE END_____________