Performance Testing: Measuring QPS with JsonPath, Regex, and Exception Handling in Java
This article explores how to accurately measure QPS in Java performance‑testing scripts by using JsonPath and regular‑expression validation, analyzes error margins under different thread and iteration configurations, and demonstrates that exception handling has minimal impact on overall throughput.
JsonPath
The author revisits a JsonPath‑based JSON parsing approach used in earlier performance‑testing scripts, noting its popularity in frameworks like Rest‑Assured, and references previous articles for background.
@Override
void run() {
times.times {
def start = Time.getTimeStamp()
sleep(0.05)
def instance = JsonUtil.getInstance(json)
instance.get("$.store.book[0].author")
def end = Time.getTimeStamp()
excutetimes.getAndIncrement()
costs.add(end - start)
}
countDownLatch.countDown()
}Running the script with 20 threads and 50 iterations yields an expected QPS of 400, but the measured QPS is around 357–350 (≈2.2% error). Increasing to 40 threads and 50 iterations raises the measured QPS to about 720 (≈2.3% error). With 40 threads and 100 iterations, the QPS stabilises near 730–740 with only about 1% error, likely due to Java hotspot optimisation.
Regex
The same JSON payload is used, adding a static string variable jsonstr . The run method now validates the payload with a regular expression.
@Override
void run() {
times.times {
def start = Time.getTimeStamp()
sleep(0.05)
Regex.isRegex(jsonstr, /0-\d{3}-\d{5}-/)
def end = Time.getTimeStamp()
excutetimes.getAndIncrement()
costs.add(end - start)
}
countDownLatch.countDown()
}Results: with 20 threads/50 iterations the QPS is about 371 (≈2.6% error); with 40 threads/50 iterations the QPS rises to ~720 (≈2.5% error); with 40 threads/100 iterations the QPS reaches ~750 with only ~1.2% error, showing comparable performance to JsonPath.
Exception Handling
The script introduces random failures inside a try‑catch block to measure the cost of exception handling.
@Override
void run() {
times.times {
def start = Time.getTimeStamp()
sleep(0.05)
try {
if (getRandomInt(3) == 1) fail()
} catch (e) {
// ignore
}
def end = Time.getTimeStamp()
excutetimes.getAndIncrement()
costs.add(end - start)
}
countDownLatch.countDown()
}With 20 threads/50 iterations the measured QPS is ~374 (≈3.5% error); with 40 threads/50 iterations it climbs to ~743 (≈2.7% error); with 40 threads/100 iterations it reaches ~754 (≈1.9% error), confirming that exception handling adds only a small overhead.
The series concludes that the different validation methods and occasional exceptions have stable and predictable impacts on QPS, and the observed errors remain within a narrow range across various load configurations.
FunTester
10k followers, 1k articles | completely useless
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.