You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

JMeter技术问询:如何实现多用户指定时间请求第二个端点?

Solutions for Synchronized Post-Login Requests in JMeter

I’ve run into this exact scenario dozens of times—simulating staggered logins followed by a coordinated burst of requests is tricky with JMeter’s default scheduler, but there are three reliable ways to make it work:

Option 1: Two Thread Groups with Session Sharing + Timed Trigger

This is the most straightforward approach for separating the login phase and synchronized request phase:

  • First Thread Group (Login Phase)

    • Set Number of Threads (users) to your total user count (e.g., 5000)
    • Set Ramp-Up Period to 300 seconds (5 minutes) — this spreads out login requests randomly over the 5-minute window
    • Add your login HTTP Request, plus a Cookie Manager to preserve session tokens
    • Enable Run Thread Groups Consecutively in the Test Plan settings (so this group finishes before the next starts)
  • Second Thread Group (Synchronized Request Phase)

    • Set Number of Threads to match the first group (same user count)
    • Use JMeter’s Scheduler to set a specific start time (the exact moment you want all users to hit the second endpoint)
    • Add the HTTP Request for your target resource — the Cookie Manager automatically reuses session tokens from the first group (JMeter shares cookie managers across thread groups by default)

Option 2: Single Thread Group with JSR223 Wait Logic

If you prefer keeping everything in one thread group (to avoid session sharing edge cases), use a Groovy script to pause each thread until your target time:

  1. Configure your thread group with:

    • Number of Threads: Your total user count
    • Ramp-Up Period: 300 seconds (to stagger logins)
  2. Add your login HTTP Request first.

  3. Insert a JSR223 Sampler right after the login request, with this Groovy code (replace the target time with your desired timestamp):

    // Define your target trigger time (format: yyyy-MM-dd HH:mm:ss)
    def targetTriggerTime = Date.parse("yyyy-MM-dd HH:mm:ss", "2024-05-20 15:00:00")
    def currentTime = new Date()
    
    // Wait until we hit the target time
    while (currentTime.before(targetTriggerTime)) {
        sleep(1000) // Check every second to avoid excessive CPU usage
        currentTime = new Date()
    }
    
  4. Add your second endpoint HTTP Request after the JSR223 Sampler.

Each thread will log in at a random time over 5 minutes, wait until the target time, then fire the resource request simultaneously.

Option 3: Synchronizing Timer for Burst Control (Alternative)

If you don’t need an exact wall-clock time, just want all logged-in users to trigger the request at the same relative point, use a Synchronizing Timer:

  • Add the timer right after your login request
  • Set Number of Simultaneous Users to Group By to your total user count
  • This pauses every thread after login until all threads have completed the login step, then they’ll all fire the next request at once

Note: This works best if your login phase completes quickly relative to the ramp-up — if logins take time, some threads might finish early and wait longer than others.


内容的提问来源于stack exchange,提问作者stuart

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.20 08:00:33