Tools to analyze Django DB sessions
Project description
This is a Django management command (as in https://docs.djangoproject.com/en/dev/howto/custom-management-commands/) that analyzes and reports on the size of sessions in the DB. It is intended to make it easier to understand how much space session data takes up.
Why?
I noticed that a relatively small number of sessions in my Django app were consuming 50+KiB of data each, and wanted to understand why. It isn’t feasible or appealing to analyze large numbers of Django sessions by hand, and I couldn’t find any existing tools that did batch analysis, so I wrote this tool.
Installation
Install the distribution from PyPI, e.g. pip install django-analyze-sessions
Then, add analyze_sessions to INSTALLED_APPS in your Django project.
That’s it. You can now run django-admin.py and confirm that the command shows up.
Example Uses
Break down the space usage of all sessions with more than 15KB of session data::
django-admin.py analyze-sessions --bigger-than=15000 Processed 2 sessions out of 5125 total sessions Average size was 16885.50 bytes Saw the following keys: foo (2 times, avg. size 15723.00 bytes) bar (2 times, avg. size 618.50 bytes) baz (2 times, avg. size 211.50 bytes)
Break down the space usage of all sessions whose keys are in the given input file (useful for when you want to select sessions on more than encoded size)::
django-admin.py analyze-sessions --ids-from=/tmp/ids-to-check Processed 2 sessions out of 5125 total sessions Average size was 16885.50 bytes Saw the following keys: foo (2 times, avg. size 15723.00 bytes) bar (2 times, avg. size 618.50 bytes) baz (2 times, avg. size 211.50 bytes)
Known Issues and Bugs
The custom WHERE clause used to filter on session size may only work on MySQL (I don’t have access to a Django installation on another DBMS, so I can’t vouch for how well it’ll work there).
The tool could stand to be smarter about size abbreviations (e.g., by learning how to interpret 100KB, or abbreviating output)
The packaging (such as it is) isn’t very good.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file django-analyze-sessions-0.1.1.tar.gz
.
File metadata
- Download URL: django-analyze-sessions-0.1.1.tar.gz
- Upload date:
- Size: 5.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | abbb664ec13cb8dfb2632d0ebefbe358a515d54616d3f7b1902e6aa6c56bd9b4 |
|
MD5 | 1bf3155b9e596bb3ccc7fc3d8a93dde6 |
|
BLAKE2b-256 | 2b877425e07f0439294b3d6ee781523175a1a06a1778c8250a388d3b115b0180 |