1 __author__ = "Reinaldo Penno"
2 __copyright__ = "Copyright(c) 2014, Cisco Systems, Inc."
3 __license__ = "New-style BSD"
5 __email__ = "repenno@cisco.com"
10 # Incrementally PUT(s) more and more list elements up to numputreq
11 # while computing the number of req/s and successful requests
13 # Then measure the number of GET request/sec up to numgetreq
14 # while computing the number of successful requests
16 # For the default values it is estimated you will consume about
17 # 1.5GB of heap memory in ODL
25 def __init__(self, verbose=False):
26 self.verbose = verbose
29 self.start = time.time()
32 def __exit__(self, *args):
33 self.end = time.time()
34 self.secs = self.end - self.start
35 self.msecs = self.secs * 1000 # millisecs
37 print ("elapsed time: %f ms" % self.msecs)
39 # Parametrized PUT of incremental List elements
44 "ip-mgmt-address": "20.0.0.11",
45 "type": "service-function:napt44",
51 putheaders = {'content-type': 'application/json'}
52 getheaders = {'Accept': 'application/json'}
54 ODLIP = "127.0.0.1:8080"
55 # We fist delete all existing service functions
56 DELURL = "http://" + ODLIP + "/restconf/config/service-function:service-functions/"
57 GETURL = "http://" + ODLIP + "/restconf/config/service-function:service-functions/service-function/%d/"
58 # Incremental PUT. This URL is for a list element
59 PUTURL = "http://" + ODLIP + "/restconf/config/service-function:service-functions/service-function/%d/"
61 # You probably need to adjust this number based on your OS constraints.
62 # Maximum number of incremental PUT list elements
64 # Maximum number of GET requests
66 # We will present PUT reports every 10000 PUTs
68 # We will present GET reports every 10000 PUTs
71 # Incrementally PUT list elements up to numputreq
73 s = requests.Session()
74 print ("Starting PUT Performance. Total of %d requests\n" % numputreq)
75 for numreq in range(0, numputreq, numputstep):
78 for i in range(numreq, numreq + numputstep):
79 r = s.put((PUTURL % i),data = (JSONPUT % i), headers=putheaders, stream=False )
80 if (r.status_code == 200):
82 print ("=> %d elapsed requests" % (numreq + numputstep))
83 print ("=> %d requests/s in the last %d reqs" % ((numputstep)/t.secs, numputstep))
84 print ("=> %d successful PUT requests in the last %d reqs " % (success, numputstep))
87 # Delete all service functions
89 print ("Deleting all Service Functions")
90 r = requests.delete(DELURL, headers=getheaders)
91 if (r.status_code == 200) or (r.status_code == 500):
92 print ("Deleted all Service Functions \n")
95 print ("Delete Failed \n")
99 # Retrieve list elements
101 s = requests.Session()
102 print ("Starting GET Performance. Total of %d requests \n" % numgetreq)
103 for numreq in range(0, numgetreq, numgetstep):
106 for i in range(numreq, numreq + numgetstep):
107 r = s.get((GETURL % i), stream=False )
108 if (r.status_code == 200):
110 print ("=> %d elapsed requests" % (numreq + numgetstep))
111 print ("=> %d requests/s in the last %d reqs" % ((numgetstep)/t.secs, numgetstep))
112 print ("=> %d successful GET requests in the last %d reqs " % (success, numgetstep))
116 if __name__ == "__main__":