reduce memory usage of Connection#377
Conversation
auvipy
left a comment
There was a problem hiding this comment.
thanks for your patch, you were involved in https://github.com/celery/py-amqp/pull/374/files aswell right?
|
Integrations tests are failing though so need some adjustment. Also I am almost done with #368 can you guys test it on your setup |
Yeah, I helped reproduce the issue.
I'm thinking this should fix it: 64f4900
I can try running our unit tests with it. Our last release of the year is tomorrow, so we couldn't put that into production for a while. However, we will be sending the fix for #374 to production tomorrow. |
|
OK thank you. you can try the slot related code in your local env as well. |
While looking into celery/celery#4843 (comment), I noticed Connection._avail_channel_ids seems to be the thing that uses the most memory on a

Connection:Currently
_avail_channel_idsis defined onConnectionlike this:It creates an array of all possible channel ids and removes them as they're used.
This PR reduces the memory usage of the
Connectionby reversing that logic and turning_avail_channel_idsinto_used_channel_ids. This will only store the channel ids that are currently used, which is almost always going to be a much smaller array.You can see the empty arrays use a lot less memory:
There's downside though: It's going to take a little bit longer to
_get_free_channel_id, because it's now going to start counting from the 1 to channel_max and return the first number that doesn't exist in_used_channel_ids.However, this could potentially reduce the severity of memory leaks.