Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Pump, Cedric
lab-tracing
Commits
149d9567
Commit
149d9567
authored
Dec 27, 2020
by
Nane Kratzke
Browse files
parallelized space
parent
7fa78358
Changes
2
Show whitespace changes
Inline
Side-by-side
space/requirements.txt
View file @
149d9567
...
...
@@ -2,3 +2,4 @@ flask
requests
opentracing
jaeger-client
joblib
\ No newline at end of file
space/service.py
View file @
149d9567
...
...
@@ -6,6 +6,8 @@ import traceback
import
os
import
json
from
joblib
import
Parallel
,
delayed
# A very boring and basic space-service to demonstrate
# observability via tracing.
...
...
@@ -24,6 +26,10 @@ tracer = config.initialize_tracer()
def
index
():
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'
)
def
space
():
with
tracer
.
start_span
(
operation_name
=
"space"
)
as
parent_span
:
...
...
@@ -40,10 +46,13 @@ def space():
"passtime"
:
f
"http://api.open-notify.org/iss-pass.json?lat=
{
lat
}
&lon=
{
lon
}
"
}
result
=
{}
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
)
#result = {}
results
=
Parallel
(
n_jobs
=
3
)(
delayed
(
load_url
)(
url
,
key
,
parent_span
)
for
key
,
url
in
queries
.
items
())
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
)
return
jsonify
(
result
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment