ITISFoundation / osparc-simcore

🐼 osparc-simcore simulation framework
https://osparc.io
MIT License
44 stars 26 forks source link

🎨 Improve profiling middleware #5935

Closed bisgaard-itis closed 2 weeks ago

bisgaard-itis commented 3 weeks ago

What do these changes do?

The problem (in a nutshell) which this PR tries to solve

When we run our endpoints via run_sequentially_in_context they are run in a different context (in the sense of https://docs.python.org/3/library/contextvars.html#contextvars.Context). This has several downsides. One is that tools for monitoring concurrent code (such as pyinstrument's profiler) are not compatible with. The way they track the handling of a request is by tracking the context. A second downside is that run_sequentially_in_context creates an asyncio task which (potentially) handles several requests. However, when an asyncio task is created it "inherrits" a copy of the context in which it is created. Because of this one request can influence how another request is handled: If the task is created when the first request is handled, then the second request will be handled within (a copy of) the context of the first request. That seems unfortunate. See e.g. https://stackoverflow.com/a/63131230

Related issue/s

How to test

Dev-ops checklist

codecov[bot] commented 3 weeks ago

Codecov Report

Attention: Patch coverage is 31.53153% with 76 lines in your changes missing coverage. Please review.

Project coverage is 87.5%. Comparing base (cafbf96) to head (3964920). Report is 266 commits behind head on master.

Additional details and impacted files [![Impacted file tree graph](https://app.codecov.io/gh/ITISFoundation/osparc-simcore/pull/5935/graphs/tree.svg?width=650&height=150&src=pr&token=h1rOE8q7ic&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=ITISFoundation)](https://app.codecov.io/gh/ITISFoundation/osparc-simcore/pull/5935?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=ITISFoundation) ```diff @@ Coverage Diff @@ ## master #5935 +/- ## ========================================= + Coverage 84.5% 87.5% +2.9% ========================================= Files 10 1110 +1100 Lines 214 48342 +48128 Branches 25 725 +700 ========================================= + Hits 181 42317 +42136 - Misses 23 5862 +5839 - Partials 10 163 +153 ``` | [Flag](https://app.codecov.io/gh/ITISFoundation/osparc-simcore/pull/5935/flags?src=pr&el=flags&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=ITISFoundation) | Coverage Δ | | |---|---|---| | [integrationtests](https://app.codecov.io/gh/ITISFoundation/osparc-simcore/pull/5935/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=ITISFoundation) | `64.7% <ø> (?)` | | | [unittests](https://app.codecov.io/gh/ITISFoundation/osparc-simcore/pull/5935/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=ITISFoundation) | `85.1% <31.5%> (+0.6%)` | :arrow_up: | Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=ITISFoundation#carryforward-flags-in-the-pull-request-comment) to find out more. | [Files](https://app.codecov.io/gh/ITISFoundation/osparc-simcore/pull/5935?dropdown=coverage&src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=ITISFoundation) | Coverage Δ | | |---|---|---| | [...ages/service-library/src/servicelib/async\_utils.py](https://app.codecov.io/gh/ITISFoundation/osparc-simcore/pull/5935?src=pr&el=tree&filepath=packages%2Fservice-library%2Fsrc%2Fservicelib%2Fasync_utils.py&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=ITISFoundation#diff-cGFja2FnZXMvc2VydmljZS1saWJyYXJ5L3NyYy9zZXJ2aWNlbGliL2FzeW5jX3V0aWxzLnB5) | `91.2% <89.4%> (ø)` | | | [...rary/src/servicelib/aiohttp/profiler\_middleware.py](https://app.codecov.io/gh/ITISFoundation/osparc-simcore/pull/5935?src=pr&el=tree&filepath=packages%2Fservice-library%2Fsrc%2Fservicelib%2Faiohttp%2Fprofiler_middleware.py&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=ITISFoundation#diff-cGFja2FnZXMvc2VydmljZS1saWJyYXJ5L3NyYy9zZXJ2aWNlbGliL2Fpb2h0dHAvcHJvZmlsZXJfbWlkZGxld2FyZS5weQ==) | `0.0% <0.0%> (ø)` | | | [...brary/src/servicelib/utils\_profiling\_middleware.py](https://app.codecov.io/gh/ITISFoundation/osparc-simcore/pull/5935?src=pr&el=tree&filepath=packages%2Fservice-library%2Fsrc%2Fservicelib%2Futils_profiling_middleware.py&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=ITISFoundation#diff-cGFja2FnZXMvc2VydmljZS1saWJyYXJ5L3NyYy9zZXJ2aWNlbGliL3V0aWxzX3Byb2ZpbGluZ19taWRkbGV3YXJlLnB5) | `42.8% <42.8%> (ø)` | | | [...rary/src/servicelib/fastapi/profiler\_middleware.py](https://app.codecov.io/gh/ITISFoundation/osparc-simcore/pull/5935?src=pr&el=tree&filepath=packages%2Fservice-library%2Fsrc%2Fservicelib%2Ffastapi%2Fprofiler_middleware.py&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=ITISFoundation#diff-cGFja2FnZXMvc2VydmljZS1saWJyYXJ5L3NyYy9zZXJ2aWNlbGliL2Zhc3RhcGkvcHJvZmlsZXJfbWlkZGxld2FyZS5weQ==) | `0.0% <0.0%> (ø)` | | ... and [1104 files with indirect coverage changes](https://app.codecov.io/gh/ITISFoundation/osparc-simcore/pull/5935/indirect-changes?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=ITISFoundation)
sonarcloud[bot] commented 2 weeks ago

Quality Gate Passed Quality Gate passed

Issues
0 New issues
0 Accepted issues

Measures
0 Security Hotspots
No data about Coverage
0.0% Duplication on New Code

See analysis details on SonarCloud