GithubHelp home page GithubHelp logo

pyuwsgimemhog's Introduction

pyuwsgimemhog

image

image

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.

pyuwsgimemhog's People

Contributors

xrmx avatar terencehonles avatar dependabot[bot] avatar

Stargazers

 avatar Krzysztof Szularz avatar Constantin Hong avatar Michael Benin avatar Carlos Pavanetti avatar Docker avatar Vlad avatar Robert Graham avatar Dmitrii Smirnov avatar Sukanya Sahoo avatar Albert Strasheim avatar امیر | amir  avatar Ernesto avatar Michael Corrado avatar Amirali Esfandiari avatar Matthew avatar  avatar Silviu Tantos avatar Andy Woods avatar Junshoong avatar Mark Sampson avatar Vishes avatar Anton Larkin avatar  avatar Matt Strayer avatar Nikolaus Schlemm avatar  avatar Eugene Morozov avatar mgd020 avatar  avatar hu wentao avatar Dimitris Rudas avatar Jeff Carpenter avatar Dmitry Ishutkin avatar Mirco Grillo avatar Alexander avatar Vladimir Ulupov avatar Fogmoon avatar  avatar Flavio Curella avatar

Watchers

 avatar James Cloos avatar Kuba Kołaczkowski avatar

pyuwsgimemhog's Issues

have set arg to logfile , but can not run

can not run , i have set arg to logfile , but can not run

/opt/install/uwsgi-2.0.15-preonline/uwsgi -s 127.0.0.1:3032 -M -p 50 --harakiri=3600 --pythonpath /opt/XENController/PreOnline --chdir /opt/XENController/PreOnline --wsgi-file XenInvoke.py --close-on-exec --log-maxsize=1000000 --daemonize /var/log/vpc_preonline/xeninvoke.log --pidfile=/opt/XENController/PreOnline/uwsgi.pid --buffer-size 655360

[root@testing_pool_api vpc_preonline]# pyuwsgimemhog --logfile xeninvoke.log
Traceback (most recent call last):
File "/usr/bin/pyuwsgimemhog", line 11, in
load_entry_point('pyuwsgimemhog==0.3.0', 'console_scripts', 'pyuwsgimemhog')()
File "/usr/lib/python2.7/site-packages/pkg_resources/init.py", line 489, in load_entry_point
return get_distribution(dist).load_entry_point(group, name)
File "/usr/lib/python2.7/site-packages/pkg_resources/init.py", line 2852, in load_entry_point
return ep.load()
File "/usr/lib/python2.7/site-packages/pkg_resources/init.py", line 2443, in load
return self.resolve()
File "/usr/lib/python2.7/site-packages/pkg_resources/init.py", line 2449, in resolve
module = import(self.module_name, fromlist=['name'], level=0)
File "/usr/lib/python2.7/site-packages/pyuwsgimemhog/cli.py", line 22
hogs = uwsgimemhog(f, threshold * 1_000_000, normalize)
^
SyntaxError: invalid syntax

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.