-
-
Notifications
You must be signed in to change notification settings - Fork 39
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 #169
Comments
With sergot/openssl#37 applied the leak is significantly reduced. I changed the code to loop just ten times and profiled with heaptrack. It showed 10Gb allocated before and only 268Mb allocated after. |
@MasterDuke17 sounds awesome! That said, I don't think it is good enough. |
sergot/openssl#38 reduces the memory used even further, down to 187Mb. |
Leaving aside the SSL thing, there is a built-in growth in memory consumption that is by design (though arguably not entirely sensible design,) as it saves every response in order to attempt to detect redirect loops, This is appended to the attribute Testing against a non-SSL URI with an additional I am pretty certain that this isn't documented (I had actually forgotten that it did this until you raised it,) and I will fix that this afternoon. I also think that there probably should be some switch on the UserAgent to control the behaviour as it would all become a bit of a faff in long runing software that uses the same UA for a large number of requests. |
@jonathanstowe ok, that makes sense! However, I'm not sure how redirect loops are related to this “feature”? If I'm doing a new request, why would it need something from the history? |
I'm not entirely convinced either but the code does :
Which basically checks whether the last max-redirects responses were re-directs. It's actually a bit tricky. I guess the best that you could do (and preserve this check,) is keep a count of the redirects and reset it when you get a non-redirect. Of course better suggestions would be appreciated (and being Saturday my brane is somewhat entertainment impaired :) |
Or for a start, only store the headers, not the bodies... |
there's a long standing comment in there that say's just that :) |
I'm still not sure why it has to store anything after |
pull request forthcoming, as a basis for discussion. |
See #169. We used to store the full history of the response, just to count redirects. This used up lots of RAM for very little gain. This commit replaces it by a simple integer that stores the count of redirects in a row. Since @.history was a public attribute, this changes the public API, and as such is subject to discussion.
It seems to pass the tests and I quite like it, but I was going to go for something slightly more conservative and use an :save-history on the request, which is only set by default on on the redirect (so that part can remain unchanged) and if it isn't set rest history at the end of request. That way the same strange behaviour can be retained but not by default. |
@jonathanstowe there are two things here I don't understand. First, who benefits from retaining the strange behavior, particularly if it's not always enabled? At least inside the public ecosystem, there's no usage:
(The mention of And second, how does that work? You don't know whether to save history until after the request, and IMHO that's too late to lead to predictable behavior. |
I think the original intention was eventually keep just the headers and allow some way for the Request to transparently store the content history to and from disk. But there have been lots of improvements to the architecture of HTTP::UserAgent since the redirect code was written, so module space could probably provide the content storage portion easily now (although I'm all for it being implemented directly if someone else is doing it). As for why to keep the headers instead of just a redirect counter - more enhanced redirect logic (especially involving caching) requires more information than just "how many times have I been redirected?". |
As I noted on the #170 I'd be inclined to move the redirect chain into the response object for those cases where something more sophisticated is required ( this could be as simple as adding a |
I've merged the #170 I'm going to look at ssupplying the redirect history on a per-response basis under separate cover. |
sergot/openssl#38 was just merged. |
Are we happy with this now so it can be closed? |
No, I am not. It is still leaking memory. Just run the example and see yourself. |
i'm only seeing a tiny leak. Memory usage goes up for a while, but then pretty much stabilizes. |
Yeah I'm not seeing the memory use monotonously increasing, it goes up for a bit then stays flat as, I guess, the garbage collection starts to take back the unused objects. |
Actually, yes! It turns out that I was using an old version. D'oh! Sorry! IMO it's closable. I don't know if you want to have tests for this, so feel free to reopen. |
Yeah I'd like to have a test but I can't see how to do it without shelling out to some highly platform dependent tool. |
Check the OS and maybe use Linux::Proc::Statm on linux. It's much better to have a test that only runs on Linux than to have no test at all. |
Sometimes around ≈20MB per fetched page.
Feel free to try it yourself (I was using blead rakudo):
The text was updated successfully, but these errors were encountered: