Skip to content

CPU performance is degraded on version 0.22.1 #1114

Description

@osd42

Hello
I spent days searching for CPU issue in my Dynatrace Python extension (which is basicaly a prometheus scraper for a Solace prometheus exporter).

I finally noticed a big performance gap between versions 0.21.1 and 0.22.1.

0.22.1 consumes 4 times more CPU than 0.21.1. I finally downgraded to 0.21.1 and my CPU is back to normal state.

Here is my usage:

# Prometheus parser: https://prometheus.github.io/client_python/parser/forprometheus_lineinutf8_lines:
forfamilyintext_string_to_metric_families(prometheus_line):
forsampleinfamily.samples:
skip=False# By default, no metric is skipped unless we filter itifsample.nameinwanted_solace_metrics:
found_metrics+=1# self.logger.info("line: " + prometheus_line)# print("Name: {0} Labels: {1} Value: {2}".format(*sample))# NaN detection with math libraryifmath.isnan(sample.value):
invalid_metrics+=1self.logger.info("NaN value skipped "+sample.name)
# If the value is NaN, we ignore itbreakelse:
valid_metrics+=1dims= {**sample[1], "node": nodename, "clustername": clustername}
# Remove unwanted dimensions#define the keys to removekeys= ['client_name', 'client_address', 'client_profile', 'flow_id', 'acl_profile']
forkeyinkeys:
result_pop=dims.pop(key, None)
ifsample.namenotincensored_metrics_listandresult_popisnotNone:
# print("DETECTED")censored_metrics_list.append(sample.name)
# parse exporter errorsif"error"indims.keys():
solace_prometheus_exporter_error=str(dims["error"]).replace('\"',"").strip()
sanitized_solace_prometheus_exporter_error={ "error": solace_prometheus_exporter_error}
dims.update(sanitized_solace_prometheus_exporter_error)
# Remove unwanted queue protocols or modify queue names patternsif"queue_name"indims.keys():
# avoid the ingestion issue with bad queue names with trailing \nqueue_name=str(dims["queue_name"]).strip()
sanitized_queue_name= { "queue_name": queue_name }
# update the queue_name in the dims payloaddims.update(sanitized_queue_name)
queue_name_lower=queue_name.lower()
ifqueue_name_lower.startswith('#mqtt') orqueue_name_lower.startswith('#cfgsync') orqueue_name_lower.startswith('#p2p') orqueue_name_lower.startswith('#pq') orqueue_name_lower=="":
# if queue_name_lower.startswith('#cfgsync') or queue_name_lower.startswith('#p2p') or queue_name_lower.startswith('#pq') or queue_name_lower == "":skip=True# Manage non skipped metricsifskipisFalse:
# Keeps queue quota calcuted metricsifsample.name=="solace_queue_spool_usage_bytes":
queue_usage.append({ "metric_name": sample.name, "md5_dims": hashlib.md5(str(dims).encode("utf-8")).hexdigest(), **dims, "METRICvalueMETRIC": sample.value})
ifsample.name=="solace_queue_spool_quota_bytes": # we store this metrics in a separate table to calculate disk usage laterqueue_quota.append({ "metric_name": sample.name, "md5_dims": hashlib.md5(str(dims).encode("utf-8")).hexdigest(), **dims, "METRICvalueMETRIC": sample.value})
# send valid points (with dimensions strings as md5 if necessary)ifsample.namenotincensored_metrics_list:
# Append valid pointsvalid_points.append( { "metric_name": sample.name, **dims, "METRICvalueMETRIC": sample.value})
else:
# if the metric is aggregated we add a md5sum of "all the dimensions" as an index to find duplicates and ease "groupby" without pandasvalid_points.append( { "metric_name": sample.name, "md5_dims": hashlib.md5(str(dims).encode("utf-8")).hexdigest(), **dims, "METRICvalueMETRIC": sample.value})

If this code is still correct in 0.22.1, I think there is an issue in newer versions 0.22.x.

Best regards,
Charles

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions