Skip to content

Commit

Permalink
adding performance, sharing functions between them, better error hand…
Browse files Browse the repository at this point in the history
…ling
  • Loading branch information
EvanDietzMorris committed Oct 10, 2024
1 parent 5ca3ec3 commit e4bc15d
Show file tree
Hide file tree
Showing 5 changed files with 152 additions and 41 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ __pycache__
.log
kubernets
*coverage
.idea
.idea
/deploy/performance_results
88 changes: 88 additions & 0 deletions deploy/performance.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
import os
import yaml
import json
import time
import random
import requests

from validate import send_cypher_query, send_trapi_query


def quick_jsonl_file_iterator(json_file):
with open(json_file, 'r', encoding='utf-8') as fp:
for line in fp:
try:
yield json.loads(line)
except json.decoder.JSONDecodeError as j:
yield {}


def run_performance_analysis(deployments_to_validate=None, performance_spec=None, iterations=3):

graph_deployment_spec_path = os.path.join(os.path.dirname(__file__), 'deployment_spec.yaml')
with open(graph_deployment_spec_path) as graph_deployment_spec_file:
deployment_spec = yaml.safe_load(graph_deployment_spec_file)
plater_performance_results = {}
for deployment in deployment_spec['deployments']:
deployment_env = deployment['deployment_environment']
automat_url = deployment['automat_url']
if not deployments_to_validate or deployment_env in deployments_to_validate:
print(f'Running performance analysis for environment: {deployment_env}')
for plater, query_details in performance_spec.items():
if plater not in plater_performance_results:
plater_performance_results[plater] = {}
plater_performance_results[plater][deployment_env] = {}
url = automat_url + plater + "/" if "localhost" not in automat_url else automat_url
query_files = query_details["files"]
queries = query_details["queries"] if "queries" in query_details else None
for q_file in query_files:
for performance_query in quick_jsonl_file_iterator(f'./{q_file}'):
if not performance_query:
continue
query_name = performance_query.pop('name')
if queries and query_name not in queries:
continue
plater_performance_results[plater][deployment_env][query_name] = {'success_duration': [],
'errors': []}
for i in range(iterations):
print(f'Sending query {query_name} to {deployment_env}: {plater}, iteration {i+1}')
start_time = time.time()
try:
trapi_response = send_trapi_query(url,
performance_query,
profile=False,
validate=False)
num_results = len(trapi_response['message']['results'])
# print(trapi_response)
duration = time.time() - start_time
print(f'Got back {num_results} in {duration}.')
plater_performance_results[plater][deployment_env][query_name]['success_duration'].append(duration)
except requests.exceptions.HTTPError as e:
duration = time.time() - start_time
print(f'Error occured after {duration} seconds: {e}.')
plater_performance_results[plater][deployment_env][query_name]['errors'].append(str(e))

average = sum(plater_performance_results[plater][deployment_env][query_name]['success_duration']) \
/ len(plater_performance_results[plater][deployment_env][query_name]['success_duration'])
print(f'Average time for {query_name} to {deployment_env}, {plater}: {average}')
with open(f'./performance_results/performance_analysis_results_{random.randrange(100000)}.json', 'w') as p_out:
p_out.write(json.dumps(plater_performance_results, indent=4))


if __name__ == '__main__':

# environments = ['exp', 'dev', 'robokop']
environments = ['robokop']

performance_spec = {
"robokopkg": {"files": ["./performance_queries/robokopkg_performance_queries.jsonl"],
"queries": ["gene_to_chemical_qualifier_40"]}
# "hmdb": {"files": ["./performance_queries/hmdb_performance_queries.jsonl"]}
}

# to run for only certain environments
run_performance_analysis(environments, performance_spec, iterations=3)

# or all of them
# run_performance_analysis()

1 change: 1 addition & 0 deletions deploy/performance_queries/hmdb_performance_queries.jsonl
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"query_name":"hmdb_example_1", "message":{"query_graph":{"nodes":{"n0":{"categories":["biolink:Pathway"],"ids":["SMPDB:SMP0000044"]},"n1":{"categories":["biolink:SmallMolecule"]}},"edges":{"e01":{"subject":"n0","object":"n1","predicates":["biolink:has_participant"]}}}},"workflow":[{"id":"lookup"}]}
14 changes: 14 additions & 0 deletions deploy/performance_queries/robokopkg_performance_queries.jsonl
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{"name": "gene_to_chemical_1", "message":{"query_graph":{"nodes":{"source":{"categories":["biolink:ChemicalEntity"],"set_interpretation":"BATCH","constraints":[],"member_ids":[]},"i":{"ids":["NCBIGene:6868"],"categories":["biolink:Gene","biolink:Protein"],"set_interpretation":"BATCH","constraints":[],"member_ids":[]}},"edges":{"edge_1":{"subject":"source","object":"i","predicates":["biolink:affects"],"attribute_constraints":[],"qualifier_constraints":[]}}}},"bypass_cache":true,"submitter":"infores:aragorn"}
{"name": "gene_to_chemical_5", "message":{"query_graph":{"nodes":{"source":{"categories":["biolink:ChemicalEntity"],"set_interpretation":"BATCH","constraints":[],"member_ids":[]},"i":{"ids":["NCBIGene:6868","NCBIGene:1557","NCBIGene:3738","NCBIGene:5141","NCBIGene:3754"],"categories":["biolink:Gene","biolink:Protein"],"set_interpretation":"BATCH","constraints":[],"member_ids":[]}},"edges":{"edge_1":{"subject":"source","object":"i","predicates":["biolink:affects"],"attribute_constraints":[],"qualifier_constraints":[]}}}},"bypass_cache":true,"submitter":"infores:aragorn"}
{"name": "gene_to_chemical_10", "message":{"query_graph":{"nodes":{"source":{"categories":["biolink:ChemicalEntity"],"set_interpretation":"BATCH","constraints":[],"member_ids":[]},"i":{"ids":["NCBIGene:6868","NCBIGene:1557","NCBIGene:3738","NCBIGene:5141","NCBIGene:3754","NCBIGene:2908","NCBIGene:2350","NCBIGene:6573","NCBIGene:1723","NCBIGene:8698"],"categories":["biolink:Gene","biolink:Protein"],"set_interpretation":"BATCH","constraints":[],"member_ids":[]}},"edges":{"edge_1":{"subject":"source","object":"i","predicates":["biolink:affects"],"attribute_constraints":[],"qualifier_constraints":[]}}}},"bypass_cache":true,"submitter":"infores:aragorn"}
{"name": "gene_to_chemical_20", "message":{"query_graph":{"nodes":{"source":{"categories":["biolink:ChemicalEntity"],"set_interpretation":"BATCH","constraints":[],"member_ids":[]},"i":{"ids":["NCBIGene:6868","NCBIGene:1557","NCBIGene:3738","NCBIGene:5141","NCBIGene:3754","NCBIGene:2908","NCBIGene:2350","NCBIGene:6573","NCBIGene:1723","NCBIGene:8698","NCBIGene:7099","NCBIGene:1565","NCBIGene:90134","NCBIGene:151","NCBIGene:148","NCBIGene:5150","NCBIGene:151306","NCBIGene:5142","NCBIGene:6532","NCBIGene:4306"],"categories":["biolink:Gene","biolink:Protein"],"set_interpretation":"BATCH","constraints":[],"member_ids":[]}},"edges":{"edge_1":{"subject":"source","object":"i","predicates":["biolink:affects"],"attribute_constraints":[],"qualifier_constraints":[]}}}},"bypass_cache":true,"submitter":"infores:aragorn"}
{"name": "gene_to_chemical_30", "message":{"query_graph":{"nodes":{"source":{"categories":["biolink:ChemicalEntity"],"set_interpretation":"BATCH","constraints":[],"member_ids":[]},"i":{"ids":["NCBIGene:6868","NCBIGene:1557","NCBIGene:3738","NCBIGene:5141","NCBIGene:3754","NCBIGene:2908","NCBIGene:2350","NCBIGene:6573","NCBIGene:1723","NCBIGene:8698","NCBIGene:7099","NCBIGene:1565","NCBIGene:90134","NCBIGene:151","NCBIGene:148","NCBIGene:5150","NCBIGene:151306","NCBIGene:5142","NCBIGene:6532","NCBIGene:4306", "NCBIGene:53637","NCBIGene:14396","NCBIGene:367","NCBIGene:1576","NCBIGene:3569","NCBIGene:2904","NCBIGene:338442","NCBIGene:2902","NCBIGene:59340","NCBIGene:5144"],"categories":["biolink:Gene","biolink:Protein"],"set_interpretation":"BATCH","constraints":[],"member_ids":[]}},"edges":{"edge_1":{"subject":"source","object":"i","predicates":["biolink:affects"],"attribute_constraints":[],"qualifier_constraints":[]}}}},"bypass_cache":true,"submitter":"infores:aragorn"}
{"name": "gene_to_chemical_40", "message":{"query_graph":{"nodes":{"source":{"categories":["biolink:ChemicalEntity"],"set_interpretation":"BATCH","constraints":[],"member_ids":[]},"i":{"ids":["NCBIGene:6868","NCBIGene:1557","NCBIGene:3738","NCBIGene:5141","NCBIGene:3754","NCBIGene:2908","NCBIGene:2350","NCBIGene:6573","NCBIGene:1723","NCBIGene:8698","NCBIGene:7099","NCBIGene:1565","NCBIGene:90134","NCBIGene:151","NCBIGene:148","NCBIGene:5150","NCBIGene:151306","NCBIGene:5142","NCBIGene:6532","NCBIGene:4306", "NCBIGene:53637","NCBIGene:14396","NCBIGene:367","NCBIGene:1576","NCBIGene:3569","NCBIGene:2904","NCBIGene:338442","NCBIGene:2902","NCBIGene:59340","NCBIGene:5144","NCBIGene:6531","NCBIGene:140","NCBIGene:2556","NCBIGene:3269","NCBIGene:3766","NCBIGene:774","NCBIGene:1813","NCBIGene:1903","NCBIGene:24947","NCBIGene:135"],"categories":["biolink:Gene","biolink:Protein"],"set_interpretation":"BATCH","constraints":[],"member_ids":[]}},"edges":{"edge_1":{"subject":"source","object":"i","predicates":["biolink:affects"],"attribute_constraints":[],"qualifier_constraints":[]}}}},"bypass_cache":true,"submitter":"infores:aragorn"}
{"name": "gene_to_chemical_qualifier_1", "message":{"query_graph":{"nodes":{"source":{"categories":["biolink:ChemicalEntity"],"set_interpretation":"BATCH","constraints":[],"member_ids":[]},"i":{"ids":["NCBIGene:6868"],"categories":["biolink:Gene","biolink:Protein"],"set_interpretation":"BATCH","constraints":[],"member_ids":[]}},"edges":{"edge_1":{"subject":"source","object":"i","predicates":["biolink:affects"],"attribute_constraints":[],"qualifier_constraints":[{"qualifier_set":[{"qualifier_type_id":"biolink:object_aspect_qualifier","qualifier_value":"activity_or_abundance"},{"qualifier_type_id":"biolink:object_direction_qualifier","qualifier_value":"decreased"}]}]}}}},"bypass_cache":true,"submitter":"infores:aragorn"}
{"name": "gene_to_chemical_qualifier_5", "message":{"query_graph":{"nodes":{"source":{"categories":["biolink:ChemicalEntity"],"set_interpretation":"BATCH","constraints":[],"member_ids":[]},"i":{"ids":["NCBIGene:6868","NCBIGene:1557","NCBIGene:3738","NCBIGene:5141","NCBIGene:3754"],"categories":["biolink:Gene","biolink:Protein"],"set_interpretation":"BATCH","constraints":[],"member_ids":[]}},"edges":{"edge_1":{"subject":"source","object":"i","predicates":["biolink:affects"],"attribute_constraints":[],"qualifier_constraints":[{"qualifier_set":[{"qualifier_type_id":"biolink:object_aspect_qualifier","qualifier_value":"activity_or_abundance"},{"qualifier_type_id":"biolink:object_direction_qualifier","qualifier_value":"decreased"}]}]}}}},"bypass_cache":true,"submitter":"infores:aragorn"}
{"name": "gene_to_chemical_qualifier_10", "message":{"query_graph":{"nodes":{"source":{"categories":["biolink:ChemicalEntity"],"set_interpretation":"BATCH","constraints":[],"member_ids":[]},"i":{"ids":["NCBIGene:6868","NCBIGene:1557","NCBIGene:3738","NCBIGene:5141","NCBIGene:3754","NCBIGene:2908","NCBIGene:2350","NCBIGene:6573","NCBIGene:1723","NCBIGene:8698"],"categories":["biolink:Gene","biolink:Protein"],"set_interpretation":"BATCH","constraints":[],"member_ids":[]}},"edges":{"edge_1":{"subject":"source","object":"i","predicates":["biolink:affects"],"attribute_constraints":[],"qualifier_constraints":[{"qualifier_set":[{"qualifier_type_id":"biolink:object_aspect_qualifier","qualifier_value":"activity_or_abundance"},{"qualifier_type_id":"biolink:object_direction_qualifier","qualifier_value":"decreased"}]}]}}}},"bypass_cache":true,"submitter":"infores:aragorn"}
{"name": "gene_to_chemical_qualifier_20", "message":{"query_graph":{"nodes":{"source":{"categories":["biolink:ChemicalEntity"],"set_interpretation":"BATCH","constraints":[],"member_ids":[]},"i":{"ids":["NCBIGene:6868","NCBIGene:1557","NCBIGene:3738","NCBIGene:5141","NCBIGene:3754","NCBIGene:2908","NCBIGene:2350","NCBIGene:6573","NCBIGene:1723","NCBIGene:8698","NCBIGene:7099","NCBIGene:1565","NCBIGene:90134","NCBIGene:151","NCBIGene:148","NCBIGene:5150","NCBIGene:151306","NCBIGene:5142","NCBIGene:6532","NCBIGene:4306"],"categories":["biolink:Gene","biolink:Protein"],"set_interpretation":"BATCH","constraints":[],"member_ids":[]}},"edges":{"edge_1":{"subject":"source","object":"i","predicates":["biolink:affects"],"attribute_constraints":[],"qualifier_constraints":[{"qualifier_set":[{"qualifier_type_id":"biolink:object_aspect_qualifier","qualifier_value":"activity_or_abundance"},{"qualifier_type_id":"biolink:object_direction_qualifier","qualifier_value":"decreased"}]}]}}}},"bypass_cache":true,"submitter":"infores:aragorn"}
{"name": "gene_to_chemical_qualifier_30", "message":{"query_graph":{"nodes":{"source":{"categories":["biolink:ChemicalEntity"],"set_interpretation":"BATCH","constraints":[],"member_ids":[]},"i":{"ids":["NCBIGene:6868","NCBIGene:1557","NCBIGene:3738","NCBIGene:5141","NCBIGene:3754","NCBIGene:2908","NCBIGene:2350","NCBIGene:6573","NCBIGene:1723","NCBIGene:8698","NCBIGene:7099","NCBIGene:1565","NCBIGene:90134","NCBIGene:151","NCBIGene:148","NCBIGene:5150","NCBIGene:151306","NCBIGene:5142","NCBIGene:6532","NCBIGene:4306","NCBIGene:53637","NCBIGene:14396","NCBIGene:367","NCBIGene:1576","NCBIGene:3569","NCBIGene:2904","NCBIGene:338442","NCBIGene:2902","NCBIGene:59340","NCBIGene:5144"],"categories":["biolink:Gene","biolink:Protein"],"set_interpretation":"BATCH","constraints":[],"member_ids":[]}},"edges":{"edge_1":{"subject":"source","object":"i","predicates":["biolink:affects"],"attribute_constraints":[],"qualifier_constraints":[{"qualifier_set":[{"qualifier_type_id":"biolink:object_aspect_qualifier","qualifier_value":"activity_or_abundance"},{"qualifier_type_id":"biolink:object_direction_qualifier","qualifier_value":"decreased"}]}]}}}},"bypass_cache":true,"submitter":"infores:aragorn"}
{"name": "gene_to_chemical_qualifier_40", "message":{"query_graph":{"nodes":{"source":{"categories":["biolink:ChemicalEntity"],"set_interpretation":"BATCH","constraints":[],"member_ids":[]},"i":{"ids":["NCBIGene:6868","NCBIGene:1557","NCBIGene:3738","NCBIGene:5141","NCBIGene:3754","NCBIGene:2908","NCBIGene:2350","NCBIGene:6573","NCBIGene:1723","NCBIGene:8698","NCBIGene:7099","NCBIGene:1565","NCBIGene:90134","NCBIGene:151","NCBIGene:148","NCBIGene:5150","NCBIGene:151306","NCBIGene:5142","NCBIGene:6532","NCBIGene:4306","NCBIGene:53637","NCBIGene:14396","NCBIGene:367","NCBIGene:1576","NCBIGene:3569","NCBIGene:2904","NCBIGene:338442","NCBIGene:2902","NCBIGene:59340","NCBIGene:5144","NCBIGene:6531","NCBIGene:140","NCBIGene:2556","NCBIGene:3269","NCBIGene:3766","NCBIGene:774","NCBIGene:1813","NCBIGene:1903","NCBIGene:24947","NCBIGene:135"],"categories":["biolink:Gene","biolink:Protein"],"set_interpretation":"BATCH","constraints":[],"member_ids":[]}},"edges":{"edge_1":{"subject":"source","object":"i","predicates":["biolink:affects"],"attribute_constraints":[],"qualifier_constraints":[{"qualifier_set":[{"qualifier_type_id":"biolink:object_aspect_qualifier","qualifier_value":"activity_or_abundance"},{"qualifier_type_id":"biolink:object_direction_qualifier","qualifier_value":"decreased"}]}]}}}},"bypass_cache":true,"submitter":"infores:aragorn"}


Loading

0 comments on commit e4bc15d

Please sign in to comment.