Upgrade SETUPTOOLS_VERSION to improve memory rss#1429
Upgrade SETUPTOOLS_VERSION to improve memory rss#1429goinnn wants to merge 1 commit intoheroku:mainfrom
Conversation
|
Hi! Thank you for the detailed write up. I'm quite surprised to hear that the setuptools version is affecting your application's memory usage at runtime. In general setuptools will only affect the build process itself, and not anything after that. The only thing I can think of, is that setuptools does runtime patching of distutils, and if your application or any of its dependencies rely upon distutils at runtime (and not only build time), then perhaps this is the reason? (Which would seem to be the case, given you mention adjusting From reading the PR description, it seems you found the memory usage improved between v66.1.1 and v67.0.0. However, reading the changes between the two, there doesn't seem to be anything that could affecting the distutils implementation? Is it possible there is a mistake in the versions listed above (and the memory usage improvement occurred in a different version), or there is some other factor not being taken into account with the test approach? In terms of updating setuptools version, we will be doing so at some point soon - however, there are multiple breaking changes in newer setuptools, so have been deliberately holding off updating as long as possible, in order to give packages time to adapt (along with stack overflow answers to exist for common failure modes) - to try and reduce the amount of customer app breakage caused. |
|
Setuptools has been updated as part of #1437 (along with an update to wheel, and test assertions being updated etc). |
|
Thanks @edmorley and sorry for delay
Everything is possible, but no :-), we were studing the memory of our application several weeks. We saw a memory increment in v210, and we understand the reason: setuptools changed the default value of SETUPTOOLS_USE_DISTUTILS from stdlib to local) but in v215 we saw another memory increment, but it is truth we don't understand what is the reason.
Thanks! I think a test would be good to be able to detect an increase in memory and be able to change setuptools dependencies without fear. Don't you think? Would you like me to do a "pip freeze" or do you need something else? |
|
No problem about the delay! The setuptools version was updated a couple of weeks ago, which should have resolved the issue you were experiencing.
This buildpack has quite a few tests already (integration tests), the issue with setuptools is that it intentionally made changes that broke a small proportion of packages out in the wild. PyPI has about half a million packages - it's not viable to test all of them here. And even if we attempted to, all it would prove is what we already know from setuptools' changelog - that newer setuptools breaks some older packages. The reason for holding off updating setuptools is not for lack of tests, but to allow time for:
Regarding adding a test for memory usage, that feels like something that might be good for you to suggest to the upstream setuptools project? It's not really viable for us to test every single implementation detail of our dependencies beyond the major functionality - at a certain point we have to trust that our dependencies have reasonable tests themselves. Also for this specific case, I'm presuming it requires a very specific scenario to be affected - since in general setuptools should not affect anything at runtime (only build time), plus for most apps a 9MB memory usage change would be insignificant. |
|
Ok, thanks for quickly answer. Only a detail of your answer: "... apps a 9MB memory usage change would be insignificant.". 9MB is only in one of our dynos.
The increase is 50 MB in worker and worker slow, or what is the same, as we have 1 Giga a increase of 5%. The measures in this issue are of beat dyno because it is very very stable, and with this dyno is very easy to meassure. But I understand your point of view. Thanks! |
|
Yeah I meant 9MB per process would not be significant for some projects (but of course would be for some others), depending on type of concurrency used for the app and memory usage of the rest of the application. For your app, it sounds like you are using process based concurrency set to 5, which would be more affected than the default Heroku standard 1x dyno concurrency of 3. Also, apps that use features like gunicorn's |
We have been using heroku since 2015. Currently we are upgrading our stack. And we have upgraded heroku-buildpack-python from v184 to v229.
In our stack we have several dynos: web (with Django), worker (with celery worker), worker-slow (with celery worker to slow tasks) and beat (celery beat). This last is very very stable to measure. The next measures are of this dyno in preproduction environment, that is even more stable:
Memory is increased
Memory is increased another time
Reasons:
We have done more tests:
Memory is increased:
Memory is decreased:
Memory is increased:
Memory is decreased:
So, if we upgrade setuptools and we use (or document) SETUPTOOLS_USE_DISTUTILS environment variable we can reduce our project by 9MB (7%). But 9MB for celery beat, this process consumes low memory. In our stack, we have decreased next MB per dyno: