Skip to content

Comments

Basic stress testing and JWT/MSAL usage optimizations#175

Merged
axelsrz merged 26 commits intomainfrom
users/robrandao/optimizations
Oct 20, 2025
Merged

Basic stress testing and JWT/MSAL usage optimizations#175
axelsrz merged 26 commits intomainfrom
users/robrandao/optimizations

Conversation

@rodrigobr-msft
Copy link
Contributor

This pull request introduces a new benchmarking tool for the Microsoft 365 Agents SDK for Python, including documentation, configuration templates, and a modular implementation for concurrent benchmarking using threads or asyncio. It also includes an update to the MSAL authentication library to avoid blocking the event loop by running synchronous MSAL calls in a thread. The most important changes are grouped below.
This pull request introduces a new Python benchmarking tool for the Microsoft 365 Agents SDK and adds async support for MSAL authentication. The changes include new documentation, configuration templates, and a modular benchmarking suite capable of running concurrent requests to an agent using either threads or coroutines. Additionally, the MSAL authentication library is updated to avoid blocking the event loop by running synchronous MSAL methods in a separate thread.

New Benchmarking Tool

  • Added a new dev/benchmark directory with a modular benchmarking suite:
    • Includes executors for both threading and asyncio concurrency (CoroutineExecutor, ThreadExecutor, Executor, ExecutionResult) and aggregation of results (AggregatedResults). [1] [2] [3] [4] [5]
    • Provides a CLI entry point (main.py) using click for configuration, and a payload sender supporting authentication token generation. [1] [2] [3]
    • Includes sample configuration (env.template), requirements (requirements.txt), and payload (payload.json) files. [1] [2] [3]
    • Documentation added for setup and usage, including support for free-threaded Python 3.13+ on Windows. [1] [2]
    • Added click to development dependencies.

MSAL Authentication Improvements

  • Updated MsalAuth in msal_auth.py to support async token acquisition:

    • Uses asyncio.to_thread to run synchronous MSAL methods in a thread, preventing event loop blocking. [1] [2] [3]
    • Ensures proper client instantiation and error handling in both client credentials and on-behalf-of flows. [1] [2]
    • Imports asyncio and initializes the MSAL auth client in the constructor. [1] [2]
      Benchmarking Tool Implementation:
  • Added a new dev/benchmark directory containing a Python benchmarking tool with modular executors (CoroutineExecutor, ThreadExecutor), result aggregation, token generation, and payload sending utilities. This enables concurrent benchmarking of agent endpoints using threads or asyncio. [1] [2] [3] [4] [5] [6] [7] [8] [9] [10]

  • Added supporting files: requirements.txt, env.template, and a sample payload.json for configuration and demonstration. [1] [2] [3]

Documentation:

  • Added documentation for developers in dev/README.md and dev/benchmark/README.md, including setup instructions for running the benchmark tool, especially for Windows and Python 3.13+ free-threaded versions. [1] [2]

Dependency Updates:

  • Updated dev_dependencies.txt to include click for CLI support in the benchmarking tool.

MSAL Authentication Improvements:

  • Updated MsalAuth in msal_auth.py to run synchronous MSAL token acquisition methods in a separate thread using asyncio.to_thread, preventing event loop blocking in async contexts. This affects both get_access_token and acquire_token_on_behalf_of methods. [1] [2] [3] [4] [5]

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Introduces a benchmarking tool and async/MSAL/JWT authentication adaptations.

  • Adds a new dev/benchmark suite with coroutine and thread executors, token generation, and aggregation utilities plus docs and env templates.
  • Updates MSAL auth flows to run blocking calls in threads; converts JWT token validation to async.
  • Adjusts dev dependencies (adds click) and provides Windows free-threaded Python setup docs.

Reviewed Changes

Copilot reviewed 21 out of 22 changed files in this pull request and generated 12 comments.

Show a summary per file
File Description
tests/authentication_msal/test_msal_auth.py Removes now-invalid mocking after refactoring client creation to set internal state instead of returning a client.
tests/_common/testing_objects/mocks/mock_msal_auth.py Adapts mock to new _create_client_application side-effect pattern.
jwt_token_validator.py Converts token validation to async and introduces JWKS client caching helpers.
jwt_authorization_middleware.py Awaits new async validate_token API.
msal_auth.py Adds async wrappers for client credential and OBO flows; refactors client creation to retain instance.
dev_dependencies.txt Adds click for CLI benchmarking tool.
dev/benchmark/src/payload_sender.py Adds payload sender factory with token injection.
dev/benchmark/src/main.py CLI entry point for running benchmarks.
dev/benchmark/src/generate_token.py Adds Azure AD client credential token generation utilities.
dev/benchmark/src/executor/thread_executor.py Thread-based executor implementation.
dev/benchmark/src/executor/executor.py Base executor abstraction and timing wrapper.
dev/benchmark/src/executor/execution_result.py Data class representing execution outcome.
dev/benchmark/src/executor/coroutine_executor.py Asyncio-based executor implementation.
dev/benchmark/src/executor/init.py Re-exports executor components.
dev/benchmark/src/config.py Environment-based benchmark configuration loader (naming inconsistency).
dev/benchmark/src/aggregated_results.py Aggregation and display of execution metrics.
dev/benchmark/requirements.txt Requirements for benchmarking tool.
dev/benchmark/payload.json Sample activity payload for benchmarking.
dev/benchmark/env.template Template for required environment variables.
dev/benchmark/README.md Documentation for benchmarking and free-threaded Python setup.
dev/README.md High-level developer tools overview.
Comments suppressed due to low confidence (1)

dev/benchmark/src/generate_token.py:1

  • Docstring references Direct Line token and secret, but this function requests an Azure AD client credential token against tenant OAuth2 endpoint. Update wording to reflect Azure AD client credentials flow.
import requests

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Copilot AI review requested due to automatic review settings October 16, 2025 13:37
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Copilot reviewed 21 out of 22 changed files in this pull request and generated 9 comments.


Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@rodrigobr-msft rodrigobr-msft marked this pull request as ready for review October 17, 2025 16:04
Copilot AI review requested due to automatic review settings October 17, 2025 16:04
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Copilot reviewed 21 out of 22 changed files in this pull request and generated 9 comments.


Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Copilot AI review requested due to automatic review settings October 20, 2025 16:19
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Copilot reviewed 21 out of 22 changed files in this pull request and generated 3 comments.


Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Copilot AI review requested due to automatic review settings October 20, 2025 16:42
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Copilot reviewed 21 out of 22 changed files in this pull request and generated no new comments.


Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@axelsrz axelsrz merged commit 62bc7d8 into main Oct 20, 2025
10 checks passed
@axelsrz axelsrz deleted the users/robrandao/optimizations branch October 20, 2025 19:56
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

Successfully merging this pull request may close these issues.

Wrap blocking MSAL library methods with async tasks Performance issues under load testing (using teams_sso sample)

2 participants