- 
                Notifications
    You must be signed in to change notification settings 
- Fork 406
Implement load test scripts for MCP server #978
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
          
     Draft
      
      
            yczhang-nv
  wants to merge
  14
  commits into
  NVIDIA:develop
  
    
      
        
          
  
    
      Choose a base branch
      
     
    
      
        
      
      
        
          
          
        
        
          
            
              
              
              
  
           
        
        
          
            
              
              
           
        
       
     
  
        
          
            
          
            
          
        
       
    
      
from
yczhang-nv:yuchen-add-mcp-load-testing
  
      
      
   
  
    
  
  
  
 
  
      
    base: develop
Could not load branches
            
              
  
    Branch not found: {{ refName }}
  
            
                
      Loading
              
            Could not load tags
            
            
              Nothing to show
            
              
  
            
                
      Loading
              
            Are you sure you want to change the base?
            Some commits from the old base branch may be removed from the timeline,
            and old review comments may become outdated.
          
          
      
        
          +1,369
        
        
          −0
        
        
          
        
      
    
  
  
     Draft
                    Changes from all commits
      Commits
    
    
            Show all changes
          
          
            14 commits
          
        
        Select commit
          Hold shift + click to select a range
      
      043372b
              
                initial commit
              
              
                yczhang-nv a67b618
              
                fix bug
              
              
                yczhang-nv 3590bb6
              
                use yaml config files
              
              
                yczhang-nv 95b6173
              
                some rename and clean up
              
              
                yczhang-nv b9c2427
              
                update README
              
              
                yczhang-nv 6ab7baa
              
                fix CI
              
              
                yczhang-nv 6ce6c31
              
                fix CI
              
              
                yczhang-nv a8fcaa9
              
                Update MCP documentation for consistency and clarity (#977)
              
              
                dagardner-nv 8b5c860
              
                update docstrings
              
              
                yczhang-nv 0b2b653
              
                fix docs
              
              
                yczhang-nv 499a0a9
              
                fix doc
              
              
                yczhang-nv 186ffbc
              
                fix doc
              
              
                yczhang-nv 2797ead
              
                move the load test suite to new path
              
              
                yczhang-nv 417990f
              
                update doc
              
              
                yczhang-nv File filter
Filter by extension
Conversations
          Failed to load comments.   
        
        
          
      Loading
        
  Jump to
        
          Jump to file
        
      
      
          Failed to load files.   
        
        
          
      Loading
        
  Diff view
Diff view
There are no files selected for viewing
        
          
  
    
      
          
            238 changes: 238 additions & 0 deletions
          
          238 
        
  packages/nvidia_nat_test/src/nat/test/mcp/load_test_utils/README.md
  
  
      
      
   
        
      
      
    
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,238 @@ | ||
| <!-- | ||
| SPDX-FileCopyrightText: Copyright (c) 2025, NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| SPDX-License-Identifier: Apache-2.0 | ||
|  | ||
| Licensed under the Apache License, Version 2.0 (the "License"); | ||
| you may not use this file except in compliance with the License. | ||
| You may obtain a copy of the License at | ||
|  | ||
| http://www.apache.org/licenses/LICENSE-2.0 | ||
|  | ||
| Unless required by applicable law or agreed to in writing, software | ||
| distributed under the License is distributed on an "AS IS" BASIS, | ||
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| See the License for the specific language governing permissions and | ||
| limitations under the License. | ||
| --> | ||
|  | ||
| # MCP Server Load Testing | ||
|  | ||
| This utility simulates concurrent users making tool calls to MCP servers and generates detailed performance reports for NVIDIA NeMo Agent toolkit. | ||
|  | ||
| ## Requirements | ||
|  | ||
| Before running load tests, ensure you have the following: | ||
|  | ||
| - NeMo Agent toolkit with MCP support installed through `nvidia-nat[mcp]` | ||
| - NeMo Agent toolkit with Test support installed through `nvidia-nat[test]` | ||
| - Valid NeMo Agent toolkit workflow configuration with MCP-compatible tools | ||
|  | ||
| The `psutil` package is required for monitoring server memory usage during load tests. Install it using the following command: | ||
|  | ||
| ```bash | ||
| uv pip install psutil | ||
| ``` | ||
|  | ||
| ## Quick Start | ||
|  | ||
| Run a load test from the project root: | ||
|  | ||
| ```bash | ||
| python packages/nvidia_nat_test/src/nat/test/mcp/load_test_utils/cli.py \ | ||
| --config_file=packages/nvidia_nat_test/src/nat/test/mcp/load_test_utils/configs/config.yml | ||
| ``` | ||
|  | ||
| Get help: | ||
|  | ||
| ```bash | ||
| python packages/nvidia_nat_test/src/nat/test/mcp/load_test_utils/cli.py --help | ||
| ``` | ||
|  | ||
| ## Configuration | ||
|  | ||
| Configure load test options using YAML files stored in the `configs/` directory. | ||
|  | ||
| ### Example Configuration | ||
|  | ||
| ```yaml | ||
| # Path to NeMo Agent toolkit workflow configuration file | ||
| config_file: "examples/getting_started/simple_calculator/configs/config.yml" | ||
|  | ||
| # Server configuration | ||
| server: | ||
| host: "localhost" | ||
| port: 9901 | ||
| transport: "streamable-http" # Options: "streamable-http" or "sse" | ||
|  | ||
| # Load test parameters | ||
| load_test: | ||
| num_concurrent_users: 10 | ||
| duration_seconds: 30 | ||
| warmup_seconds: 5 | ||
|  | ||
| # Output configuration | ||
| output: | ||
| directory: "load_test_results" | ||
|  | ||
| # Tool calls to execute during load testing | ||
| tool_calls: | ||
| - tool_name: "calculator_multiply" | ||
| args: | ||
| text: "2 * 3" | ||
| weight: 2.0 # Called twice as often as weight 1.0 tools | ||
|  | ||
| - tool_name: "calculator_divide" | ||
| args: | ||
| text: "10 / 2" | ||
| weight: 1.0 | ||
| ``` | ||
|  | ||
| ### Configuration Parameters | ||
|  | ||
| #### Required Parameters | ||
|  | ||
| **`config_file`** (string) | ||
| : Path to the NeMo Agent toolkit workflow configuration file. | ||
|  | ||
| #### Server Configuration | ||
|  | ||
| Configure the MCP server settings in the `server` section: | ||
|  | ||
| **`host`** (string, default: `"localhost"`) | ||
| : Host address where the MCP server will run. | ||
|  | ||
| **`port`** (integer, default: `9901`) | ||
| : Port number for the MCP server. | ||
|  | ||
| **`transport`** (string, default: `"streamable-http"`) | ||
| : Transport protocol type. Options: `"streamable-http"` or `"sse"`. | ||
|  | ||
| #### Load Test Parameters | ||
|  | ||
| Configure load test behavior in the `load_test` section: | ||
|  | ||
| **`num_concurrent_users`** (integer, default: `10`) | ||
| : Number of concurrent users to simulate. | ||
|  | ||
| **`duration_seconds`** (integer, default: `60`) | ||
| : Duration of the load test in seconds. | ||
|  | ||
| **`warmup_seconds`** (integer, default: `5`) | ||
| : Warmup period before measurements begin, in seconds. | ||
|  | ||
| #### Output Configuration | ||
|  | ||
| Configure report output in the `output` section: | ||
|  | ||
| **`directory`** (string, default: `"load_test_results"`) | ||
| : Directory where test reports will be saved. | ||
|  | ||
| #### Tool Calls | ||
|  | ||
| Define tool calls to execute in the `tool_calls` list. Each tool call includes: | ||
|  | ||
| **`tool_name`** (string, required) | ||
| : Name of the MCP tool to call. | ||
|  | ||
| **`args`** (dictionary, optional) | ||
| : Arguments to pass to the tool. | ||
|  | ||
| **`weight`** (float, default: `1.0`) | ||
| : Relative call frequency. Tools with higher weights are called more frequently. A tool with weight 2.0 is called twice as often as a tool with weight 1.0. | ||
|  | ||
| ## Running Load Tests | ||
|  | ||
| ### Command Line | ||
|  | ||
| Run load tests from the project root using the command-line interface: | ||
|  | ||
| ```bash | ||
| # Basic usage | ||
| python packages/nvidia_nat_test/src/nat/test/mcp/load_test_utils/cli.py \ | ||
| There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why not install as a script command under  That way it's transparent/easy for any user to run. 
 | ||
| --config_file=packages/nvidia_nat_test/src/nat/test/mcp/load_test_utils/configs/config.yml | ||
|  | ||
| # With verbose logging | ||
| python packages/nvidia_nat_test/src/nat/test/mcp/load_test_utils/cli.py \ | ||
| --config_file=packages/nvidia_nat_test/src/nat/test/mcp/load_test_utils/configs/config.yml \ | ||
| --verbose | ||
|  | ||
| # Short form | ||
| python packages/nvidia_nat_test/src/nat/test/mcp/load_test_utils/cli.py \ | ||
| -c packages/nvidia_nat_test/src/nat/test/mcp/load_test_utils/configs/config.yml | ||
| ``` | ||
|  | ||
| ### Python API | ||
|  | ||
| #### Using YAML Configuration | ||
|  | ||
| ```python | ||
| from nat.test.mcp.load_test_utils import run_load_test_from_yaml | ||
|  | ||
| results = run_load_test_from_yaml( | ||
| "packages/nvidia_nat_test/src/nat/test/mcp/load_test_utils/configs/config.yml" | ||
| ) | ||
| ``` | ||
|  | ||
| #### Programmatic Usage | ||
|  | ||
| ```python | ||
| from nat.test.mcp.load_test_utils import run_load_test | ||
|  | ||
| results = run_load_test( | ||
| config_file="examples/getting_started/simple_calculator/configs/config.yml", | ||
| tool_calls=[ | ||
| { | ||
| "tool_name": "calculator_multiply", | ||
| "args": {"text": "2 * 3"}, | ||
| "weight": 2.0, | ||
| }, | ||
| { | ||
| "tool_name": "calculator_divide", | ||
| "args": {"text": "10 / 2"}, | ||
| "weight": 1.0, | ||
| }, | ||
| ], | ||
| num_concurrent_users=10, | ||
| duration_seconds=30, | ||
| ) | ||
| ``` | ||
|  | ||
| ## Output Reports | ||
|  | ||
| The load test generates two report files in the output directory: | ||
|  | ||
| ### CSV Report | ||
|  | ||
| **File name**: `load_test_YYYYMMDD_HHMMSS.csv` | ||
|  | ||
| Detailed per-request data with the following columns: | ||
|  | ||
| - `timestamp`: Request timestamp | ||
| - `tool_name`: Name of the tool called | ||
| - `success`: Boolean success status | ||
| - `latency_ms`: Request latency in milliseconds | ||
| - `memory_rss_mb`: Resident Set Size (RSS) memory in MB at request time | ||
| - `memory_vms_mb`: Virtual Memory Size (VMS) in MB at request time | ||
| - `memory_percent`: Memory usage percentage at request time | ||
| - `error`: Error message if the request failed | ||
|  | ||
| ### Summary Report | ||
|  | ||
| **File name**: `load_test_YYYYMMDD_HHMMSS_summary.txt` | ||
|  | ||
| Human-readable summary with the following statistics: | ||
|  | ||
| **Summary Metrics** | ||
| : Total requests, success rate, requests per second | ||
|  | ||
| **Latency Statistics** | ||
| : Mean, median, P95, P99, minimum, and maximum latencies | ||
|  | ||
| **Memory Statistics** | ||
| : RSS and VMS memory usage (mean and max), memory percentage (mean and max) | ||
|  | ||
| **Per-Tool Statistics** | ||
| : Individual performance metrics for each tool | ||
|  | ||
| **Error Analysis** | ||
| : Breakdown of failed requests by error type | ||
        
          
  
    
      
          
            24 changes: 24 additions & 0 deletions
          
          24 
        
  packages/nvidia_nat_test/src/nat/test/mcp/load_test_utils/__init__.py
  
  
      
      
   
        
      
      
    
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| # SPDX-FileCopyrightText: Copyright (c) 2025, NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
| """MCP Server Load Testing Utilities. | ||
|  | ||
| This module provides utilities for load testing MCP servers. | ||
| """ | ||
|  | ||
| from nat.test.mcp.load_test_utils.load_tester import MCPLoadTest | ||
| from nat.test.mcp.load_test_utils.load_tester import run_load_test | ||
| from nat.test.mcp.load_test_utils.load_tester import run_load_test_from_yaml | ||
|  | ||
| __all__ = ["MCPLoadTest", "run_load_test", "run_load_test_from_yaml"] | 
      
      Oops, something went wrong.
        
    
  
  Add this suggestion to a batch that can be applied as a single commit.
  This suggestion is invalid because no changes were made to the code.
  Suggestions cannot be applied while the pull request is closed.
  Suggestions cannot be applied while viewing a subset of changes.
  Only one suggestion per line can be applied in a batch.
  Add this suggestion to a batch that can be applied as a single commit.
  Applying suggestions on deleted lines is not supported.
  You must change the existing code in this line in order to create a valid suggestion.
  Outdated suggestions cannot be applied.
  This suggestion has been applied or marked resolved.
  Suggestions cannot be applied from pending reviews.
  Suggestions cannot be applied on multi-line comments.
  Suggestions cannot be applied while the pull request is queued to merge.
  Suggestion cannot be applied right now. Please check back later.
  
    
  
    
Uh oh!
There was an error while loading. Please reload this page.