On 07/06/2012 06:44 AM, Rémi Chaintreuil wrote:
Hi,

I'm developping a monitoring application, which use a classic
XMLHttpRequest object to get data from the server every second.

The object is calling a route ('/test', for instance), and the
view_callable is simply returning a Response object built from a string
(which is generated by the application).

I've realized that my application's memory use was increasing over time,
and after several tests, I can tell that this memory leak does not come
from the generation of the string itself, but from the view_callable
processing.

To confirm it, I've created a simple project who looks like this :

*__init__.py*

    from pyramid.config import Configurator

    def main(global_config, **settings):
         """ This function returns a Pyramid WSGI application.
         """
         config = Configurator(settings=settings)
         config.add_static_view('static', 'static', cache_max_age=3600)
         config.add_route('home', '/')
         config.add_route('test','/test')
         config.scan()
         return config.make_wsgi_app()


*views.py*

    from pyramid.view import view_config
    from pyramid.response import Response
    import random

    @view_config(route_name='home', renderer='templates/mytemplate.pt')
    def my_view(request):
         return {}

    @view_config(route_name='test')
    def test_view(request):
    return Response(str(random.random()))


*mytemplate.pt*

    <p id="test"></p>
    <script type="text/javascript">

    function test() {
    var xhr = new XMLHttpRequest();

    xhr.onreadystatechange = function() {
    if (xhr.readyState == 4 && (xhr.status == 200 || xhr.status == 0)) {
    document.getElementById('test').innerHTML = xhr.responseText;
    window.setTimeout(test, 500);
    }
    };
    xhr.open("GET", '/test', true);
    xhr.send(null);
    }

    test();

    </script>


The memory use of this application is indeed increasing over time,
especially when a lot of clients are connected.

Is Pyramid caching the response of my test_view in memory, and not
releasing it properly when the response changes ?
What would be the best way to achieve the same behaviour without having
such an increase of memory use ?

Be sure you're not using the Pyramid debugtoolbar in this configuration.

- C

--
You received this message because you are subscribed to the Google Groups 
"pylons-discuss" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/pylons-discuss?hl=en.

Reply via email to