Skip to content

Very slow iteration over jobs with MLClient.jobs.list() #48415

Description

@dstoe
  • Package Name: azure.ai.ml.MLClient -> azure.ai.ml.operations._job_operations._append_tid_to_studio_url
  • Package Version: 1.34.1
  • Operating System: linux
  • Python Version: 3.12

Describe the bug
Iterating over azure.ai.ml.MLClient.jobs.list() is unnecessarily slow, since there's a full authentication flow initiated on every job item just to find out the tenant-id. The iteration repeatedly calls azure.ai.ml.operations._job_operations._append_tid_to_studio_url which has in it's implementation:

                        # Extract the tenant id from the credential using PyJWT
                        decode = jwt.decode(
                            self._credential.get_token(*default_scopes).token,
                            options={"verify_signature": False, "verify_aud": False},
                        )
                        tid = decode["tid"]
                        formatted_tid = TID_FMT.format(tid)
                        studio_endpoint.endpoint = studio_url + formatted_tid

As explicitly noted in the get_token function, this function does not cache any data.

To Reproduce

from azure.ai.ml import MLClient
from azure.identity import AzureCliCredential


ml_client = MLClient(
    AzureCliCredential(),
    subscription_id="foo",
    workspace_name="bar",
    resource_group_name="foobar",
)

# Load 100 jobs and exit
for index, job_run in enumerate(ml_client.jobs.list()):
    if index > 100:
        break
    del job_run

Timing of the above with the vanilla-implementation in azure.ai.ml.operations._job_operations._append_tid_to_studio_url:

$ time python test.py 

real	1m17.016s
user	0m55.264s
sys	0m7.458s

With the code-block in azure.ai.ml.operations._job_operations._append_tid_to_studio_url replaced with hard-coding my tenant-id:

time python test.py 

real	0m13.239s
user	0m3.261s
sys	0m0.346s

Expected behavior
Looping over many jobs shouldn't be unnecessarily slow.

Metadata

Metadata

Assignees

No one assigned

    Labels

    ClientThis issue points to a problem in the data-plane of the library.Machine LearningService AttentionWorkflow: This issue is responsible by Azure service team.customer-reportedIssues that are reported by GitHub users external to the Azure organization.needs-team-attentionWorkflow: This issue needs attention from Azure service team or SDK teamquestionThe issue doesn't require a change to the product in order to be resolved. Most issues start as that

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions