Creating groups really slow for users with many groups
Summary
We are provisioning all users and groups via the api. Every group gets created by the default root (admin) user and therefore this user is in every group after creation. With about 5000 groups the requests to create new groups via api or gui becomes really slow and takes about 3 minutes to create a single group.
Looking deeper reveals, that the group gets created in the first second after sending the request and the returning the results consumes most of the 3 minutes. Perhaps all group memberships of the current user gets fetched from the database one for one and the duration is caused by the database <-> application latency?
We cannot remove the user from the group to keep the number of groups small, because the last owner of the group cannot be removed and we have some groups that have no members from time to time.
Steps to reproduce
- Create many groups with a single user or add user to many groups (e.g. 5000 groups)
- Create new group with the user via gui or api
- Wait about 3 minutes to complete (with 2 cpu, 8GB RAM, omnibus package)
What is the current bug behavior?
Creating a group as an user with many groups runs in the default timeout of 60 seconds. Only increasing the timeout to more than 180 seconds helps to get the request done. Besides the time taken to complete the requests is too long
What is the expected correct behavior?
Almost no impact on the creation time of new groups, independent (or not measurable) of how many groups the creating user has.
Possible fixes
Is it necessary to enforce that the creating user is a member of the group? Allow creation of empty groups would be really helpful and doesn't need any workarounds (or placeholder users) to keep a group alive until it gets members again.