Operations 5 min read

Microbenchmarking API Parameter Signing and Performance Testing with a Custom Framework

The article explains how to conduct microbenchmark tests for API parameter signing, measures the overhead of signature generation, and demonstrates using a custom performance testing framework to isolate request processing time and improve throughput accuracy.

FunTester
FunTester
FunTester
Microbenchmarking API Parameter Signing and Performance Testing with a Custom Framework

Recently I performed a performance test on an API that requires parameter signing, and the results showed that local signature generation takes about 10 ms, while under concurrency it can reach 100 ms, making data validation crucial.

Between two requests, the local machine only collects test results, generates test data, and signs it, with signing being the most time‑consuming step; after data collection, a round or several rounds of micro‑benchmarking are needed.

Micro‑benchmarking measures the performance of tiny code units, such as comparing synchronous versus asynchronous method execution time, the cost of creating threads versus using a thread pool, and the runtime of an algorithm versus its alternative implementation.

Below is the assembled parameter and signing method (request and response handling are commented out):

@Override
protected void doing() throws Exception {
    String url = com.okayqa.studentapd.base.OkayBase.HOST + "/api/member/createOrRenewMember";
    Map
p = new HashMap<>();
    p.put("days", "1");
    p.put("memberId", "208");
    p.put("orderNo", "F" + RString.getString(4) + i.getAndAdd(1));
    p.put("orderPaySystemId", "85123213");
    p.put("orderPayTime", "2020-02-09 10:00:00");
    p.put("payMoney", "30");
    p.put("recordSources", "3");
    p.put("renewal", "false");
    def user = Users.getStuUser(i.getAndAdd(1) % 1000);
    // output(user)
    p.put("systemId", user);
    String sign = RSAUtilLJT.sign(p, RSAUtilLJT.getPrivateKey(RSAUtilLJT.RSA_PRIVATE_KEY));
    p.put("sign", sign);
    HttpPost post = getHttpPost(url, JSON.toJSONString(p));
    def s = "F" + getNanoMark();
    // post.addHeader(getHeader("requestid", s));
    // def simlple = FanLibrary.excuteSimlple(post)
    // if (!simlple.contains("success")) {
    //     logger.warn(s + OR + user + simlple.toString())
    //     fail()
    // }
}

Running the interface pressure‑test script:

public static void main(String[] args) {
    def argsUtil = new ArgsUtil(args);
    def thread = argsUtil.getIntOrdefault(0, 1);
    def times = argsUtil.getIntOrdefault(1, 100);
    def reqs = [];
    thread.times {
        // def mark = new HeaderMark("requestid")
        reqs << new Thr(times);
    }
    new Concurrent(reqs, "会员支付和续费接口").start();
    testOver();
}

By using the same thread count and iteration count to measure the time spent on non‑request work and subtracting it from the total API performance test time, the measured throughput can be corrected; however, the calibrated throughput may still be higher than the real value because the local pause between requests does not reflect true server load, a topic to be addressed in the next article.

Disclaimer: This article was first published on the WeChat public account “FunTester” and may not be reproduced by third parties (except Tencent Cloud).

javaConcurrencyperformance testingMicrobenchmarkAPI signing
FunTester
Written by

FunTester

10k followers, 1k articles | completely useless

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.