Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

using pyinstrument to log traceback of slow callbacks #2341

Merged
merged 13 commits into from
May 20, 2021

Conversation

GitHK
Copy link
Contributor

@GitHK GitHK commented May 19, 2021

What do these changes do?

During the analysis of logs coming from production there were lots of entries similar to:

servicelib.monitor_slow_callbacks:instrumented(28) - Executing <Task finished coro=<Application._handle() done, defined at /home/scu/.venv/lib/python3.6/site-packages/aiohttp/web_app.py:428> result=<Response OK not prepared>> took 7.647 seconds

Adding pyinstrument.Profiler will help format the output of the slow callbacks. A full traceback of the call will be logged.

WARNING: there is a slight performance hit for running the profiler. I think this is worth it in order to have more meaningful log messages which will help debugging the stack.

Trivia

While looking for the current solution, aioprof was considered and in part used as inspiration. Our codebase already had most of the tests and implementation in place to easily integrate pyinstrument on top of which aioprof is built.

Related issue/s

How to test

Checklist

@GitHK GitHK added the a:services-library issues on packages/service-libs label May 19, 2021
@GitHK GitHK self-assigned this May 19, 2021
@GitHK GitHK marked this pull request as draft May 19, 2021 08:41
@codecov
Copy link

codecov bot commented May 19, 2021

Codecov Report

Merging #2341 (56f5466) into master (36c96bf) will increase coverage by 0.0%.
The diff coverage is 100.0%.

Impacted file tree graph

@@          Coverage Diff           @@
##           master   #2341   +/-   ##
======================================
  Coverage    72.0%   72.1%           
======================================
  Files         509     509           
  Lines       20022   20025    +3     
  Branches     1969    1969           
======================================
+ Hits        14431   14445   +14     
+ Misses       5104    5097    -7     
+ Partials      487     483    -4     
Flag Coverage Δ
integrationtests 62.0% <ø> (+<0.1%) ⬆️
unittests 67.5% <100.0%> (+<0.1%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
...e-library/src/servicelib/monitor_slow_callbacks.py 100.0% <100.0%> (ø)
.../director/src/simcore_service_director/producer.py 61.7% <0.0%> (+1.0%) ⬆️
...ce_webserver/resource_manager/garbage_collector.py 77.6% <0.0%> (+1.8%) ⬆️
...webserver/computation_comp_tasks_listening_task.py 86.0% <0.0%> (+2.0%) ⬆️

@GitHK GitHK changed the title using pyinstrument to keep track of slow callbacks using pyinstrument to log traceback of slow callbacks May 19, 2021
@GitHK GitHK added this to the Chinchilla milestone May 19, 2021
@GitHK GitHK marked this pull request as ready for review May 19, 2021 10:53
Copy link
Member

@mguidon mguidon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like statistical profilers. I guess you checked joerick/pyinstrument#83?

Copy link
Member

@sanderegg sanderegg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the indentation to check maybe?

@GitHK GitHK requested a review from sanderegg May 19, 2021 12:09
@@ -22,6 +22,8 @@ sqlalchemy
psycopg2-binary
pyyaml

# used for monitoring of slow callbacks
pyinstrument
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since you add a new dependency in a library, you should compile the requirements of the services it includes

  1. search which services are affected by
grep --include=\*.in -nrw  -e 'packages/service-library/requirements/_base.in'
  1. compile upgrade each service
cd services/service/requirements
make touch
make reqs upgrade=pyinstrument

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice one, will do this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ran this on all packages and no other packages require extra dependencies.
There are only some dependencies which are trying to be updated, like pytest-coverage etc... Those are out of the scope of this PR, will ignore them.

Copy link
Member

@pcrespov pcrespov May 19, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

did you use upgrade=pyinstrument option?? That should not happen!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I always forget about that option, usually I end up checking stuff manually.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@GitHK Please do not forget to upgrade the requirements of the services!
Right now it works because the servicelib setup is installing pyinstrument but the frozen requirements do not show all the dependencies

@GitHK
Copy link
Contributor Author

GitHK commented May 19, 2021

I like statistical profilers. I guess you checked joerick/pyinstrument#83?

Sadly enough I've checked this. If there would be a big performance downfall I would remove the library and revert back to the previous implementation.

@GitHK GitHK requested a review from pcrespov May 19, 2021 12:40
@GitHK GitHK merged commit 94fa02b into ITISFoundation:master May 20, 2021
@GitHK GitHK added the t:maintenance Some planned maintenance work label Jun 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a:services-library issues on packages/service-libs t:maintenance Some planned maintenance work
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants