Skip to content

Commit

Permalink
Don't use jsonpath_ng in the monitor loop
Browse files Browse the repository at this point in the history
Each jsonpath expression usage cause a storm of fstat() for no good reason.
As the monitor loop is ran frequently, optimize that by not using jsonpath.

Anyway, jsonpath was just a dev convenience here. Did nothing tricky to do
without this lib.
  • Loading branch information
cvaroqui committed Sep 6, 2019
1 parent 0588583 commit 1e3c53f
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions lib/osvcd_mon.py
Expand Up @@ -27,7 +27,6 @@
list_services, svc_pathcf, fmt_path, \
resolve_path, factory
from freezer import Freezer
from jsonpath_ng import jsonpath, parse

STARTED_STATES = [
"n/a",
Expand Down Expand Up @@ -2140,12 +2139,17 @@ def service_started_instances_count(self, path):
"""
Count the number of service instances in 'started' local expect state.
"""
jsonpath_expr = parse("*.services.status.'%s'.monitor.local_expect" % path)
count = 0
try:
count = len([True for match in jsonpath_expr.find(shared.CLUSTER_DATA) if match.value == "started"])
for node, ndata in shared.CLUSTER_DATA.items():
try:
local_expect = ndata["services"]["status"][path]["monitor"]["local_expect"]
except Exception:
continue
if local_expect == "started":
count += 1
return count
except Exception as exc:
self.log.warning(exc)
return 0

def up_service_instances(self, path):
Expand Down

0 comments on commit 1e3c53f

Please sign in to comment.