-
Notifications
You must be signed in to change notification settings - Fork 887
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
Memory leak per request with add_request_method and resource_url #1212
Comments
The test app memory on windows grows at a rate of 4388 bytes per request, average over 50K requests. |
Running this with this gc tween checker shows the following python objects being created for each request:
Removing the request method removes changes that to this:
|
I traced this down to InstancePropertyMixin._set_properties. If I comment out the last line ( |
One thing I am wondering here is why a new type is created for every request instance? Isn't it possible to create the type once when the WSGI app is created and then keep using that? |
The class/type of the request object is dependent on the request factory used in the app. It's not predictable at configuration time. |
The other way to implement the InstancePropertyMixin is to override the |
When |
Incorrect, the request type is completely dependent on the request factory the user supplies, which is a per-request factory of the format |
This issue is related to #1067. |
Hmm. I wonder what the use case of a per-request factory is. It feels like Zopish over-engineering, but I'm guessing Chris had a valid use case I can't think of. |
It was the way to add custom properties to a request until we added request properties in 1.3. There are plenty of other reasons as well, for example replacing webob or custom request subclasses based on some headers. The type of the request is something that pyramid dispatches based on as well. |
Before request properties I can see the point of providing a custom Request type, but not in having a different request type per HTTP request. I still can't think of any reason why you would need that. |
The analysis from #1067 seems to match the extra objects I see, which suggests this may be a bug in the ZTK. |
What's happening here is this:
I don't know what the solution is yet. |
(NB: thanks Wiggy for the info in the gc tween tracker; it allowed me to put pdb.set_trace calls in the right places to track this down) |
One "global registry" might be the |
I've fixed this without understanding the issue in its entirety (without tracking down exactly how references are leaked) but the fix works. |
The fix seems to work ok for the minimal pyramid application. Unfortunately not for my real pyramid app. I will investigate more. |
@murrayreadccdc Could you provide more information on your memory leak? |
@bertjwregeer - it's been a year since I look at this, but my last note on this issue was "Using Pyramid 1.5b1 on Linux, I am not seeing significant evidence of memory leak now." |
I am finding a continuous memory growth in my Pyramid application when I make repeated requests to it. This is happening both with pserve on windows and apache on linux.
A test pserve process died due to memory exhaustion after 85 minutes with 1871MB allocated under a load of up to 40 requests per second.
I have managed to reproduce the issue in a minimal pyramid application, based on the standard hello world app. There are two key lines added to this, which cause the problem. First "config.add_request_method(db, property=True)" - if this is used with either property=True or reify=True, you get the leak, otherwise not. Second "url = request.resource_url(request.context)" - without this call to get a resource url, there is no leak. Here is the full test app:
I am using the following test client app to drive the server:
Monitoring the memory use in the pyramid app, it increases by 1MB every few seconds. This rate stays approximately constant.
The text was updated successfully, but these errors were encountered: