Fix: Improved performance of REST getStatus endpoint. 78/7678/1
authorpeusterm <manuel.peuster@uni-paderborn.de>
Tue, 18 Jun 2019 14:55:26 +0000 (16:55 +0200)
committerpeusterm <manuel.peuster@uni-paderborn.de>
Tue, 18 Jun 2019 14:55:26 +0000 (16:55 +0200)
Change-Id: Ia91a896b0d0fc35901b5987b2981d91122052578
Signed-off-by: peusterm <manuel.peuster@uni-paderborn.de>
src/emuvim/api/rest/compute.py
src/emuvim/dashboard/js/main.js
src/emuvim/dcemulator/node.py

index 7a12c68..62a8f18 100755 (executable)
@@ -153,25 +153,16 @@ class ComputeList(Resource):
             if dc_label is None or dc_label == 'None':
                 # return list with all compute nodes in all DCs
                 all_containers = []
-                all_extSAPs = []
                 for dc in dcs.itervalues():
                     all_containers += dc.listCompute()
-                    all_extSAPs += dc.listExtSAPs()
-
-                extSAP_list = [(sap.name, sap.getStatus())
-                               for sap in all_extSAPs]
                 container_list = [(c.name, c.getStatus())
                                   for c in all_containers]
-                total_list = container_list + extSAP_list
-                return total_list, 200, CORS_HEADER
+                return container_list, 200, CORS_HEADER
             else:
                 # return list of compute nodes for specified DC
                 container_list = [(c.name, c.getStatus())
                                   for c in dcs.get(dc_label).listCompute()]
-                extSAP_list = [(sap.name, sap.getStatus())
-                               for sap in dcs.get(dc_label).listExtSAPs()]
-                total_list = container_list + extSAP_list
-                return total_list, 200, CORS_HEADER
+                return container_list, 200, CORS_HEADER
         except Exception as ex:
             logging.exception("API error.")
             return ex.message, 500, CORS_HEADER
index a705840..be63ed1 100755 (executable)
@@ -30,7 +30,7 @@ var ERROR_ALERT = false;
 var TIMESTAMP = 0;
 var CONNECTED = false;
 var LATENESS_UPDATE_INTERVAL = 50;
-var DATA_UPDATE_INTERVAL = 1000 * 30; // 30 seconds
+var DATA_UPDATE_INTERVAL = 1000 * 10; // 30 seconds
 var LAST_UPDATE_TIMESTAMP_CONTAINER = 0;
 var LAST_UPDATE_TIMESTAMP_DATACENTER = 0;
 
index 2a211d7..87085d8 100755 (executable)
@@ -50,6 +50,7 @@ class EmulatorCompute(Docker):
             self, name, dimage, **kwargs):
         self.datacenter = kwargs.get("datacenter")  # pointer to current DC
         self.flavor_name = kwargs.get("flavor_name")
+        self._network_state_cache = None
         LOG.debug("Starting compute instance %r in data center %r" %
                   (name, str(self.datacenter)))
         # call original Docker.__init__
@@ -71,16 +72,21 @@ class EmulatorCompute(Docker):
             intf_dict = {'intf_name': str(i), 'ip': "{0}/{1}".format(i.IP(), i.prefixLen), 'netmask': i.prefixLen,
                          'mac': i.MAC(), 'up': i.isUp(), 'status': i.status(), 'dc_portname': dc_port_name}
             networkStatusList.append(intf_dict)
-
         return networkStatusList
 
     def getStatus(self):
         """
         Helper method to receive information about this compute instance.
         """
+        # inspect container
+        cinspect = self.dcli.inspect_container(self.dc)
+        # inspect networking (slow, so do only once)
+        if self._network_state_cache is None:
+            self._network_state_cache = self.getNetworkStatus()
+        # build status
         status = {}
         status["name"] = self.name
-        status["network"] = self.getNetworkStatus()
+        status["network"] = self._network_state_cache
         status["docker_network"] = self.dcinfo['NetworkSettings']['IPAddress']
         status["image"] = self.dimage
         status["flavor_name"] = self.flavor_name
@@ -90,11 +96,10 @@ class EmulatorCompute(Docker):
         status["cpuset"] = self.resources.get('cpuset_cpus')
         status["mem_limit"] = self.resources.get('mem_limit')
         status["memswap_limit"] = self.resources.get('memswap_limit')
-        status["state"] = self.dcli.inspect_container(self.dc)["State"]
-        status["id"] = self.dcli.inspect_container(self.dc)["Id"]
-        status["short_id"] = self.dcli.inspect_container(self.dc)["Id"][:12]
-        status["hostname"] = self.dcli.inspect_container(self.dc)[
-            "Config"]['Hostname']
+        status["state"] = cinspect["State"]
+        status["id"] = cinspect["Id"]
+        status["short_id"] = cinspect["Id"][:12]
+        status["hostname"] = cinspect["Config"]['Hostname']
         status["datacenter"] = (None if self.datacenter is None
                                 else self.datacenter.label)