Skip to content
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 increase while using the client #2855

Open
Ncoder2 opened this issue May 6, 2024 · 3 comments
Open

Memory increase while using the client #2855

Ncoder2 opened this issue May 6, 2024 · 3 comments

Comments

@Ncoder2
Copy link

Ncoder2 commented May 6, 2024

Description of the problem, including code/CLI snippet

When using the python gitlab client and calling any function say project details for example, there is a constant increase in memory and does not reduce with time. We tested this by running the get projects via http_get method in a loop, the memory kept increasing

Expected Behavior

function calls can increase memory but should be cleared once the call is complete

Actual Behavior

memory keeps increasing every time

Specifications

  • python-gitlab version: 3.10.0 and the latest version
  • API version you are using (v3/v4): 4
  • Gitlab server version (or gitlab.com):

Test Code to reproduce the behaviour, please replace token and project_id

import logging
from memory_profiler import profile
from gitlab_client import GitlabClient
from gitlab import Gitlab


@profile
def func1():
    gl = Gitlab('https://gitlab.com',private_token='{TOKEN}')
    project = gl.http_get("/projects/{project_id}")

if __name__ == '__main__':
    for i in range(10):
        print(i)
        func1()
@nejch
Copy link
Member

nejch commented May 6, 2024

@Ncoder2 I'm a bit surprised as we use python-gitlab for multiple long-running services that iterate over hundreds of thousands of projects and users on a weekly basis, and haven't seen issues. Do you have some results you could share?

Is there a reason to instantiate the client in every iteration instead of just once?

@Ncoder2
Copy link
Author

Ncoder2 commented May 6, 2024

@nejch , Thanks for the quick response, i just changed the above example code and tried to keep the Gitlab object creation out of the loop and the consumption has reduced. However, our use case is again to get project details of all projects using the gitlab client and take necessary actions/perform code scan etc.

We are using the gitlab client in a fastapi server, when we run a scan on say 1000s of projects, somehow the projects.get increases the memory the fastapi server restarts. In our code, we dont instantiate the gitlab object everytime though.

@Ncoder2
Copy link
Author

Ncoder2 commented May 11, 2024

HI @nejch , what would you suggest for this usecase:
The gitlab client is used as part of a fastapi service, where we retrieve project information based on project id for every request and these requests can be concurrent.

Solution 1:

  • Create a gitlab object by providing credentials as a class level variable, but create different project details object for every request, please note, gitlab object remains the same, but gitlab project details object is created for every request

Solution 2:

  • For every request, create a new gitlab object and project details object

Asking the two solutions to understand how would gitlab object behave when concurrent requests are made, gitlab project details object is created from the same gitlab object

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants