Avoid reconstructing psutil.Process repeatedly

Open
#308 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
30/100
Issue type
Refactor
Clarity
Needs clarification
Activity status
Stale
Tech stack
python
Domain
performance

Research direction

Start by locating TrackedRequest and the sampler call sites that create psutil.Process objects, then inspect how web-server forking affects process-level state. Done means reducing repeated Process construction while preserving correct behavior across forked workers; the issue provides no named tests or files.

Written by the indexing model from the issue text.

Description

A psutil.Process object is not that cheap to recreate (compared to other python objects):

In [2]: %timeit psutil.Process()
13.1 µs ± 101 ns per loop (mean ± std. dev. of 7 runs, 100000 loops each)

We use several of them - a couple of them per TrackedRequest to get current memory usage, and one per sampler call.

We should figure out some way of reducing this, by sharing an instance. A global wouldn't always work since web servers fork.

Dominant language
Python
Stars
77
Forks
19
Avg merge
1d 9h
Merged PRs (30d)
5

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from scoutapp/scout_apm_python

All issues in scoutapp/scout_apm_python

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.