Skip to content

Limit concurrency of asyncio for gather_objects_recommendations #58

Closed

Description

@lujiajing1126

Describe the bug

When we have a large amount of container/pods in the cluster, e.g. >1000.

async def _gather_objects_recommendations(
self, objects: list[K8sObjectData]
) -> list[tuple[ResourceAllocations, MetricsData]]:
recommendations: list[tuple[RunResult, MetricsData]] = await asyncio.gather(
*[self._calculate_object_recommendations(object) for object in objects]
)

will start the >1000 coroutines to concurrently query Metrics server which cause resource exhaustion, e.g. connection pool in the VictoriaMetrics, local memory larger than 20GB, etc.

To Reproduce
Steps to reproduce the behavior:

  1. Go to '...'
  2. Click on '....'
  3. Scroll down to '....'
  4. See error

Expected behavior

According to the SO,

async def gather_with_concurrency(n: int, *coros):
    semaphore = asyncio.Semaphore(n)

    async def sem_coro(coro):
        async with semaphore:
            return await coro
    return await asyncio.gather(*(sem_coro(c) for c in coros))

can be used to limit concurrency level.

Screenshots
If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

  • OS: [e.g. iOS]
  • Browser [e.g. chrome, safari]
  • Version [e.g. 22]

Smartphone (please complete the following information):

  • Device: [e.g. iPhone6]
  • OS: [e.g. iOS8.1]
  • Browser [e.g. stock browser, safari]
  • Version [e.g. 22]

Additional context
Add any other context about the problem here.

Activity

  1. changed the title [-]Limit coroutine of asyncio for gather_objects_recommendations[/-] [+]Limit concurrency of asyncio for gather_objects_recommendations[/+] on Jun 1, 2023
  2. LeaveMyYard commented on Jun 23, 2023

    @LeaveMyYard
    Contributor

    We are working on this issue and will fix it soon
    I will update here as soon as it is finished

  3. added
    bug
    on Jun 23, 2023
  4. LeaveMyYard commented on Jun 29, 2023

    @LeaveMyYard
    Contributor

    #82 was already merged for that issue.
    It also added the -w flag to control the exact amount of executors to be used

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions