Commit 149d9567 authored by Nane Kratzke's avatar Nane Kratzke
Browse files

parallelized space

parent 7fa78358
...@@ -2,3 +2,4 @@ flask ...@@ -2,3 +2,4 @@ flask
requests requests
opentracing opentracing
jaeger-client jaeger-client
joblib
\ No newline at end of file
...@@ -6,6 +6,8 @@ import traceback ...@@ -6,6 +6,8 @@ import traceback
import os import os
import json import json
from joblib import Parallel, delayed
# A very boring and basic space-service to demonstrate # A very boring and basic space-service to demonstrate
# observability via tracing. # observability via tracing.
...@@ -24,6 +26,10 @@ tracer = config.initialize_tracer() ...@@ -24,6 +26,10 @@ tracer = config.initialize_tracer()
def index(): def index():
return redirect('/space') return redirect('/space')
def load_url(url, key, ctx):
with tracer.start_span(operation_name=key, child_of=ctx) as span:
return key, json.loads(requests.get(url).content)
@app.route('/space') @app.route('/space')
def space(): def space():
with tracer.start_span(operation_name="space") as parent_span: with tracer.start_span(operation_name="space") as parent_span:
...@@ -40,10 +46,13 @@ def space(): ...@@ -40,10 +46,13 @@ def space():
"passtime": f"http://api.open-notify.org/iss-pass.json?lat={ lat }&lon={ lon }" "passtime": f"http://api.open-notify.org/iss-pass.json?lat={ lat }&lon={ lon }"
} }
result = {} #result = {}
for key, url in queries.items():
with tracer.start_span(operation_name=key, child_of=parent_span) as span: results = Parallel(n_jobs=3)(delayed(load_url)(url, key, parent_span) for key, url in queries.items())
result[key] = json.loads(requests.get(url).content) result = { key: content for key, content in results }
#for key, url in queries.items():
# with tracer.start_span(operation_name=key, child_of=parent_span) as span:
# result[key] = json.loads(requests.get(url).content)
print(result) print(result)
return jsonify(result) return jsonify(result)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment