首页主机资讯ubuntu jmeter性能测试

ubuntu jmeter性能测试

时间2025-10-02 00:27:03发布访客分类主机资讯浏览235
导读:Installing Java Environment JMeter is a Java-based tool, so a compatible JDK (Java Development Kit is required. For Ubu...

Installing Java Environment
JMeter is a Java-based tool, so a compatible JDK (Java Development Kit) is required. For Ubuntu, you can install OpenJDK using the following commands:

sudo apt update
sudo apt install openjdk-11-jdk  # Recommended version (JMeter 5.x+ supports Java 8+)

Verify the installation with:

java -version

This should display the installed Java version (e.g., “openjdk version 11.0.xx”).

Installing Apache JMeter

  1. Download JMeter: Use wget to fetch the latest stable version from the official Apache website:
    wget https://downloads.apache.org/jmeter/binaries/apache-jmeter-5.6.3.tgz  # Replace with the latest version
    
  2. Extract the Archive: Unzip the downloaded file to a directory (e.g., /opt for system-wide access):
    sudo tar -xzf apache-jmeter-5.6.3.tgz -C /opt
    
  3. Configure Environment Variables: Edit the system profile file (/etc/profile) to add JMeter to your PATH:
    sudo vim /etc/profile
    
    Add these lines at the end (replace /opt/apache-jmeter-5.6.3 with your actual path):
    export JMETER_HOME=/opt/apache-jmeter-5.6.3
    export PATH=$JMETER_HOME/bin:$PATH
    
    Save the file and apply changes:
    source /etc/profile
    
  4. Verify Installation: Run jmeter -v to confirm JMeter is accessible. You should see version details (e.g., “Apache JMeter 5.6.3”).

Creating a Basic Test Plan
JMeter uses “test plans” (.jmx files) to define performance tests. Here’s how to create one via the GUI (for simplicity) and run it in non-GUI mode:

  1. Open JMeter GUI: Run jmeter from the terminal to launch the graphical interface.
  2. Add a Thread Group: Right-click “Test Plan” → “Add” → “Threads (Users)” → “Thread Group”. Configure:
    • Number of Threads (users): Number of concurrent users (e.g., 50).
    • Ramp-up Period (seconds): Time to start all threads (e.g., 10 seconds).
    • Loop Count: Number of iterations (e.g., 10).
  3. Add an HTTP Request: Right-click the Thread Group → “Add” → “Sampler” → “HTTP Request”. Fill in:
    • Server Name or IP: Your target server (e.g., example.com).
    • Path: The endpoint to test (e.g., /api/v1/users).
  4. Add Listeners: Listeners collect and display results. Right-click the Thread Group → “Add” → “Listener” → “Aggregate Report” (for summary metrics) and “View Results Tree” (for detailed request/response data, disable in production).
  5. Save the Test Plan: Click “File” → “Save As” and name it (e.g., my_test_plan.jmx).

Running Performance Tests (Non-GUI Mode)
Non-GUI mode is essential for high-concurrency tests—it reduces resource usage on the client machine. Use this command:

jmeter -n -t /path/to/my_test_plan.jmx -l /path/to/results.jtl -e -o /path/to/report
  • -n: Non-GUI mode.
  • -t: Path to the test plan (.jmx) file.
  • -l: Path to save results (.jtl file, contains raw data).
  • -e: Generate HTML report after the test.
  • -o: Directory to store the HTML report (must be empty).

Example:

jmeter -n -t ~/jmeter/my_test_plan.jmx -l ~/jmeter/results.jtl -e -o ~/jmeter/report

After the test completes, open the HTML report in ~/jmeter/report/index.html to view metrics like response time, throughput, and error rate.

Monitoring System Resources During Testing
To analyze performance bottlenecks, monitor server resources (CPU, memory, disk I/O) during the test. Use these tools:

  1. Top: Real-time view of CPU and memory usage:
    top
    
    Press Shift + P to sort by CPU usage, Shift + M for memory.
  2. Vmstat: System-wide performance stats (run every second for 60 seconds):
    vmstat 1 60 >
         vmstat.log
    
    The log includes CPU idle time, memory usage, and disk I/O.
  3. Nmon: Detailed resource monitoring (install via sudo apt install nmon):
    nmon -f -s 1 -c 60
    
    This generates a .nmon file (use nmon_analyzer to convert it into charts).

Best Practices for Effective Testing

  • Use Non-GUI Mode Always: GUI mode consumes significant CPU/memory (~10-25% of system resources). Reserve it for test creation/debugging only.
  • Limit Listeners in Production Tests: Listeners like “View Results Tree” store detailed request/response data, which increases memory usage. Disable them during high-concurrency tests and use them only to analyze specific requests.
  • Optimize JMeter Memory: Edit the jmeter script (in the bin directory) to increase heap size. For example, set:
    HEAP="-Xms1g -Xmx4g -XX:MaxMetaspaceSize=512m"
    
    This allocates 1GB initial heap, 4GB maximum heap, and 512MB for metadata.
  • Distribute Load for High Concurrency: For tests exceeding 500 concurrent users, use JMeter’s distributed testing feature (set up multiple “slave” machines to run tests in parallel).

Troubleshooting Common Issues

  • Java Not Found: If you see java: command not found, ensure Java is installed and JAVA_HOME is correctly set in /etc/profile.
  • Port Conflicts: JMeter uses port 1099 by default for distributed testing. If another process uses it, change the port in jmeter.properties (look for server.rmi.localport).
  • Plugin Errors: If you encounter NoClassDefFoundError (e.g., for WebSocket plugins), install the required dependencies. For WebSocket tests, download jetty-http, jetty-util, and websocket-client JARs and place them in the lib/ext directory.

声明:本文内容由网友自发贡献,本站不承担相应法律责任。对本内容有异议或投诉,请联系2913721942#qq.com核实处理,我们将尽快回复您,谢谢合作!


若转载请注明出处: ubuntu jmeter性能测试
本文地址: https://pptw.com/jishu/716431.html
ubuntu jmeter配置指南 ubuntu jmeter使用教程

游客 回复需填写必要信息