How to Build a Fixed‑QPS Load‑Testing Framework in Java
This article explains the design and implementation of a Java‑based fixed QPS load‑testing framework, covering its multithreaded base class, concurrent executor, compensation thread, performance metrics collection, and provides source code links for practical use and further development.
Background and Goal
When discussing fixed QPS load testing with peers, the author needed a reusable component for a performance testing framework and released the implementation on GitHub and Gitee.
Design Overview
The solution consists of a multithreaded base class, a concurrent executor built from a thread pool, a task generator, and a compensator thread that fills the gap when the actual request rate falls short of the target.
Base Class
The abstract FixedQpsThread defines common fields such as qps, limit, and isTimesMode. It records whether the test runs in “times mode” (fixed number of requests) or “duration mode”. Sub‑classes must implement clone() and the test logic in run(), which measures execution time, logs slow requests, and updates shared counters.
Execution Engine
The FixedQpsConcurrent class manages a list of FixedQpsThread instances, a thread pool (20 core, 200 max, keep‑alive 3 s), and statistics collections. The start() method calculates the interval between requests, launches an auxiliary AidThread for compensation, and repeatedly submits cloned task objects until the configured limit or duration is reached.
After execution it shuts down the pool, records total time, success and error counts, and writes raw latency data and markers to files. The countQPS methods compute average latency, QPS, and other metrics using the saved data.
Compensation Thread
The inner AidThread monitors the elapsed time and expected request count. If the actual executed requests lag behind the target by more than ten, it injects additional tasks at short intervals (100 ms) until the gap is closed, then sleeps briefly before the next check.
Current Limitations and Future Work
The compensator logic still contains two sleep points and hard‑coded configuration values; these will be externalized and refined after more practical testing. Additional helper classes for marking and statistics are pending updates.
Source code and further updates are available at https://github.com/JunManYuanLong/FunTester and https://gitee.com/fanapi/tester.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
