Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Any way to run this without saving stuff to DB? #773

Open
SHxKM opened this issue Feb 8, 2025 · 5 comments
Open

Any way to run this without saving stuff to DB? #773

SHxKM opened this issue Feb 8, 2025 · 5 comments

Comments

@SHxKM
Copy link

SHxKM commented Feb 8, 2025

Title says it all. I'm looking for a way to run this "in memory", kinda like Debug Toolbar runs (although the latter is per request, but I'm fine with Silk losing all data on restart).

@stereodamage
Copy link

Well, there is InMemoryStorage available, not sure if this solves your question, but you can try it.

@SHxKM
Copy link
Author

SHxKM commented Feb 19, 2025

Well, there is InMemoryStorage available, not sure if this solves your question, but you can try it.

I'm not sure I understand. Is InMemoryStorage a special mode in Silk? because I can't find that. To clarify, I don't want the whole app to run in memory, I just want silk to keep its data in memory (and not write it to the DB) while the app is running. I don't want to deal with clean-ups, etc..

@stereodamage
Copy link

stereodamage commented Feb 19, 2025

InMemoryStorage is a storage class that can be set in configuration (see this section of README after the image on which configuration parameter to modify, depends on Django version). I can't confirm that it will keep all data in memory, but it seems like it's the closest you can get out of the box

edit: on that note, if you find InMemoryStorage is not sufficient for your requirements, you can write your own storage class based on any of those available in the package and use it in configuration

@SHxKM
Copy link
Author

SHxKM commented Feb 27, 2025

InMemoryStorage is a storage class that can be set in configuration (see this section of README after the image on which configuration parameter to modify, depends on Django version). I can't confirm that it will keep all data in memory, but it seems like it's the closest you can get out of the box

Thanks for the pointer. Unfortunately this didn't help:

STATICFILES_STORAGE = "whitenoise.storage.CompressedManifestStaticFilesStorage"

STORAGES = {
    "SILKY_STORAGE": {
        "BACKEND": "django.core.files.storage.InMemoryStorage",
    },
    "staticfiles": {
        "BACKEND": STATICFILES_STORAGE
    }
}

I load a few views, make a query SQLQuery.objects.count() and get a count that's > 0, restart the app, make a query again, and it's the same count. Hence silk is still saving the data to the DB.

@SHxKM
Copy link
Author

SHxKM commented Feb 27, 2025

I think I understand why:

A custom storage class can be used for the saved generated binary .prof files:

This setting only applies to .prof files, not the Response, SQLQuery, Profile, and Request objects.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants