Log connection cpu time usage for non io heavy commands

This commit is contained in:
shortcutme 2016-11-07 23:19:17 +01:00
parent 7ffd897653
commit c727443ea3

View file

@ -65,16 +65,27 @@ class FileRequest(object):
if not RateLimit.isAllowed(event): # There was already an update for this file in the last 10 second if not RateLimit.isAllowed(event): # There was already an update for this file in the last 10 second
time.sleep(5) time.sleep(5)
self.response({"ok": "File update queued"}) self.response({"ok": "File update queued"})
# If called more than once within 20 sec only keep the last update # If called more than once within 15 sec only keep the last update
RateLimit.callAsync(event, max(self.connection.bad_actions, 20), self.actionUpdate, params) RateLimit.callAsync(event, max(self.connection.bad_actions, 15), self.actionUpdate, params)
else: else:
func_name = "action" + cmd[0].upper() + cmd[1:] func_name = "action" + cmd[0].upper() + cmd[1:]
func = getattr(self, func_name, None) func = getattr(self, func_name, None)
if cmd not in ["getFile", "streamFile"]: # Skip IO bound functions
s = time.time()
if self.connection.cpu_time > 0.5:
self.log.debug("Delay %s %s, cpu_time used by connection: %.3fs" % (self.connection.ip, cmd, self.connection.cpu_time))
time.sleep(self.connection.cpu_time)
if self.connection.cpu_time > 5:
self.connection.close()
if func: if func:
func(params) func(params)
else: else:
self.actionUnknown(cmd, params) self.actionUnknown(cmd, params)
if cmd not in ["getFile", "streamFile"]:
taken = time.time() - s
self.connection.cpu_time += taken
# Update a site file request # Update a site file request
def actionUpdate(self, params): def actionUpdate(self, params):
site = self.sites.get(params["site"]) site = self.sites.get(params["site"])