Thursday, October 24, 2013

Re: Sessions memory issue

-----BEGIN PGP SIGNATURE-----
Comment: GPGTools - https://gpgtools.org

iQEcBAEBCgAGBQJSaYzTAAoJELMiOgVOfjkQ0UgIAJ5v+fnL1maaW0YAU/Z/z85T
SclcaA2cD79gd6dD8f3s7A3k355X71+T+1VRiGw66usyp6lpkgprcPOvut54iE5M
mejbESudlRCnr3bKVJQBrZdkRuB8tVQbQQNALrpIz12rpOPAAY0Y73/Oswzo5y86
VAzOx2212pdwAy23iAeu6XAMXfLhX9UgKvoO2+hxp155X/78gxB5SyXPWifQeLwQ
DUPlGjrDydb0N65RWsVwXV8+peE7VQq4Qv3Z8sWjbQ5C1lsQxdzbSKBnSBDvQ0bJ
hTQp4tO57snbNjFSjeU1oVTveGk0mqupEdSnk0ssooa0OkybhgqC9/SGseQzqIk=
=OtCk
-----END PGP SIGNATURE-----
John

There are a couple of ways you can handle this, either you store the files in a database as a TEXT blob, or as a temporary file somewhere.

And you can identify your users with request.user if they have to have an account, or request.session.session_key if they don't, the session_key is the cookie. For either to work the client has to accept cookies.

The temporary file approach will required a database table to link the file name to the user.

I have used all of these and they all work well.

If you need the text to be persistent across sessions I would store it in a database, if it is around for an hour then just store it in a temporary file.

And make sure you have a process to delete old data.

Finally you could also compress the text when you save it.

Hopes this helps.

François


On Oct 24, 2013, at 3:51 PM, John Carlo <johncarlof1976@gmail.com> wrote:

> Hello everybody,
>
> I'm a newbie with Django, I love it but something it's not clear to me. So I'm here to make a question. Thank you in advance.
>
> I have an application that has some istances of custom classes I wrote. At every client request, every istance creates a big list of strings. Then, a function combines the lists generated from the istances and send them to the client.
> I store the istances in the session, and the combining function get the istances through session. The problem is that the lists of strings comsume a lot of memory...
> I know that sessions are stored in database, I can see them in the table django_session, but they are kept also in RAM, and this is my problem.
> How can I reduce the RAM memory consumption?
>
> I thought 2 ways:
> 1) Find a way to move the lists from the RAM and put them in the db, I hope there is something built-in in django session, but I did not find them
> 2) Instead building the lists of strings, I create a temp file in which I will append every string. In the end the combining function reads the temp files and combines them
>
> Could you please help me? I'm really I'm really stuck on this...
>
> thank you very much!
>
> --
> You received this message because you are subscribed to the Google Groups "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/c7118798-84fe-4a32-bba0-53452871b6ae%40googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate