Skip to main content

pyuwsgimemhog

https://img.shields.io/pypi/v/pyuwsgimemhog.svg https://github.com/xrmx/pyuwsgimemhog/actions/workflows/ci.yml/badge.svg

Do you want to find out which path of your application running under uWSGI is leaking memory?

pyuwsgimemhog parses uWSGI logs to point out which paths contributes to uWSGI processes RSS memory increase.

Installation

pip install pyuwsgimemhog

Requirements

In order to have the needed information you have to run uWSGI with the memory-report enabled.

Please note that it’s possible to have meaningful results only if you are using one thread per process.

Use from the command line

You need to pass a single uWSGI log file to pyuwsgimemhog:

pyuwsgimemhog --logfile /path/to/log
/api 975 200 4.9
/another-api 502 2 251

That means that /api contributed to increase the memory usage by 975 MB, it has been accounted 200 times and it contributed 4.9 MB per call. /another-api contributed 502 MB in two occurences so 251MB per call.

Use as a library

In addition to using pyuwsgimemhog as a command line utility, it can also be used as a library. This allows passing a custom path normalization function into the log analyzer in order to group requests based on that URL path.

A trivial example of using the Django URL resolver in order to normalize URLs would be the following:

from django.urls import resolve, Resolver404
from pyuwsgimemhog.pyuwsgimemhog import normalize_path, uwsgimemhog
from urllib.parse import urlparse

def normalize(url):
    try:
        return resolve(urlparse(url).path).view_name
    except Resolver404:
        # This view was not handled by Django so fall back to the default
        # normalization. Use normalize_path_with_nums to normalize numbers
        # in path to 0.
        return normalize_path(url)

with open(logfile, 'r') as f:
    for view, memory, count in uwsgimemhog(
            f, threshold * 1_000_000, normalize):
        print('{} {} {} {:.1f}'.format(
            view, memory // 1_000_000, count, memory / count / 1_000_000
        ))

License

MIT license

Credits

This package was created with Cookiecutter and the audreyr/cookiecutter-pypackage project template.

History

0.3.0 (2021-04-24)

  • Make it possible to pass a custom normalization function (Terence D. Honles)

  • Fix regular expression to require RSS (Terence D. Honles)

  • Use Github actions instead of Travis (Terence D. Honles)

0.2.0 (2020-01-10)

  • Count and show occurrences and per call leak count.

0.1.0 (2019-04-12)

  • First release on PyPI.

Metadata

Release files for pyuwsgimemhog 0.3.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pyuwsgimemhog 0.3.0
File Size Uploaded Provenance Actions
pyuwsgimemhog-0.3.0.tar.gz 6.6 kB Without provenance Details for pyuwsgimemhog-0.3.0.tar.gz

Release files / pyuwsgimemhog-0.3.0.tar.gz

Download URL pyuwsgimemhog-0.3.0.tar.gz
Size 6.6 kB
Tags Source
SHA-256 checksum
How to use checksums
5309f4d16ad2a930273895c3594ba3825aba508e755a22e0415bba5280b8f02a
BLAKE2b-256 checksum
How to use checksums
decea70ff4cedb08441a6f741d0a3f3ec152584dfdae9cb066e63dbbc70c3d79
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.3.0 pkginfo/1.4.2 requests/2.24.0 setuptools/52.0.0 requests-toolbelt/0.9.1 tqdm/4.57.0 CPython/3.9.2

Security for pyuwsgimemhog 0.3.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.3.0 This release

1 release file No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page