Mastering moco API: Real-Time Request Hit Monitoring and High‑QPS Testing

This guide explains how to extend the moco API with request‑hit monitoring, demonstrates building a lightweight test service, and shows achieving over 50,000 QPS using FunTester, while detailing the available assertion methods and their practical code examples.

FunTester
FunTester
FunTester
Mastering moco API: Real-Time Request Hit Monitoring and High‑QPS Testing

In daily development we often use various moco frameworks; this article focuses on the extensible moco API, adding new features and wrappers that make it comfortable to build a simple test service within minutes.

A performance test demo started a local moco service, created a basic GET endpoint, and used the FunTester framework for load testing. The single‑machine configuration (1 GB memory) reached more than 50,000 QPS, as shown in the image below.

50,000+ QPS performance result
50,000+ QPS performance result

During this process it was discovered that moco API already provides a request‑hit counter via the class com.github.dreamhead.moco.MocoRequestHit, which offers basic assertion capabilities.

Basic Syntax

def monitor = getHitMonitor()

def server = getServer(12345, "${getMark()}.log", monitor)

monitor.verify(urlStartsWith("/b"), atLeast(2))

The monitor variable is an instance of MocoRequestHit. It is passed to the httpserver during construction, allowing real‑time verification of endpoint hit rates while the server runs.

Assertion Methods

try {
    monitor.verify(urlStartsWith("/m"), never())
    monitor.verify(urlMatcher("/t"), once())
    monitor.verify(urlOnly("/a"), times(1))
    monitor.verify(urlEndWith("/b"), atLeast(2))
    monitor.verify(urlContain("/"), atMost(10))
    monitor.verify(urlEndWith("/"), between(12, 22))
    monitor.verify(unexpected(), never())
} catch (e) {
    logger.warn(e)
}

A try‑catch block is required to catch exceptions; otherwise the current thread would terminate and subsequent cleanup steps would be skipped.

Supported Verification Functions

never(): never called

once(): called exactly once

times(int i): called i times

atLeast(int i): called at least i times

atMost(int i): called at most i times

between(int i, int j): called between i and j times

unexpected(): not hit

These functions enable precise monitoring of API request patterns during performance or functional testing.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

BackendJavaPerformance TestingMoCorequest monitoringAPI testing
FunTester
Written by

FunTester

10k followers, 1k articles | completely useless

0 followers
Reader feedback

How this landed with the community

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.