Skip to main content

DBTimer for Django

Overview

DBTimer is a Django management command designed to measure the performance of various database operations (read, write, search) across different models and databases in a Django application. It helps developers and database administrators benchmark and optimize query performance by recording execution times and generating visual graphs.

Features

  • Measure Query Times: Perform read, write, and search operations on specified models and record the time taken for each operation.
  • Support for Multiple Databases: Test and compare the performance of different database configurations.
  • Automated Graph Generation: Generate graphs visualizing query performance and upload them to an S3-compatible storage service.
  • Detailed Reporting: Save results in JSON and HTML formats, including performance metrics and comparisons.
  • Exception Handling: Log and handle exceptions encountered during database operations.
  • Customizable via Django Settings: Configure models, fields, and operations to benchmark directly in Django settings.

Installation

You can install the Django DBTimer Command package via pip:

pip install dbtimer

Configuration

To use the Django DBTimer Command, you need to add some configuration to your Django settings:

settings_local.py

Most commonly you will be creating a settings_local because this feature will likely not be used in production.

####Example:

DBTIMER_ARGS = {
    "cycles": 100,  # Number of iterations per operation
    "sleep": 0.1,   # Sleep interval between operations
    "operations": ["read", "write", "search"],  # Operations to benchmark
    "models": [
        {
            "conf": ("myapp", "MyModel"),
            "name": "MyModel",
            "attr": "field_name",
            "search": {"field_name__icontains": "test"},
        },
        # Add more models as needed
    ],
    "dbs": ["default", "replica"],  # Databases to test
}

AWS S3 configuration for storing graphs

AWS_S3_REGION_NAME = 'your-region' AWS_S3_ENDPOINT_URL = 'https://your-s3-endpoint' AWS_ACCESS_KEY_ID = 'your-access-key-id' AWS_SECRET_ACCESS_KEY = 'your-secret-access-key' LINODE_BUCKET = 'your-s3-bucket-name'

Usage

Run the management command with optional notes: python manage.py dbtimer --notes "Testing query performance on different branches"

Output

The command will produce:

  • Graphs: Plots showing the duration of each operation for different database configurations, uploaded to the specified S3 bucket.
  • JSON Report: A JSON file containing detailed results of the benchmark session.
  • HTML Report: An HTML file summarizing the results, including links to the generated graphs.

Example Output

After running the command, you will see logs indicating the progress and completion of the benchmarking process. The output files will be saved to your S3 bucket, and a URL will be provided in the console.

Dependencies

  • Django
  • tqdm for progress bars
  • boto3 for S3 operations
  • matplotlib for graph generation
  • requests for HTTP operations Ensure these dependencies are listed in your requirements.txt or setup.py for easy installation.

Contributing

Contributions are welcome! Please open an issue or submit a pull request for any enhancements or bug fixes.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Contact

For any questions or feedback, please contact devs@djangowebstudio.com.

Metadata

Release files for dbtimer 0.1.1

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

Source distribution (sdist)

Source distribution for dbtimer 0.1.1
File Size Uploaded Provenance Actions
dbtimer-0.1.1.tar.gz 14.3 kB Without provenance Details for dbtimer-0.1.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for dbtimer 0.1.1
File Interpreter ABI Platform Actions
dbtimer-0.1.1-py3-none-any.whl Python 3 none any Details for dbtimer-0.1.1-py3-none-any.whl

Total release size: 38.2 kB

Release files / dbtimer-0.1.1.tar.gz

Download URL dbtimer-0.1.1.tar.gz
Size 14.3 kB
Tags Source
SHA-256 checksum
How to use checksums
184ec1dd3fbb4793e604f16ffae3069742c44e506c694bfd782336bcdc5317b7
BLAKE2b-256 checksum
How to use checksums
fa343ddc5a966235c0f4225186ac4690ab72098c8be4c3978486e44a242045b5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.11.7

Release files / dbtimer-0.1.1-py3-none-any.whl

Download URL dbtimer-0.1.1-py3-none-any.whl
Size 23.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ccb909d09c320a307650b375dfc16693c1846cb206ccf56809e799537b0c8b2a
BLAKE2b-256 checksum
How to use checksums
95b4a3201f9863157be7275426386c7f86c0e95144a99771a8adab90dcb2c406
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.11.7

Security for dbtimer 0.1.1

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.1.1 This release

2 release files 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