tencent cloud

Dynamic Acceleration

Download
Mode fokus
Ukuran font
Terakhir diperbarui: 2026-05-21 11:46:31
The SDK provides a range of network measurement APIs and callback APIs. Businesses can set measurement thresholds to achieve acceleration as needed. Meanwhile, the SDK also offers a fallback strategy. If significant anomalies occur during acceleration, such as network disconnection, excessive latency, negative optimization, or acceleration performance far below expectations, the SDK will proactively disable acceleration and speed tests, directing traffic to the origin server to prevent abnormal acceleration from impacting normal business operation.
Note:
When the SDK triggers the escape onAccException callback, it will directly terminate the acceleration channel. If the acceleration was initiated using a SOCKS5 proxy, the business must switch the appropriate network requests back to direct connection (no longer using a proxy).

Access Process

1. Initialization and Sign-up Phase
SDK Initialization: First, call setDataKey to complete the basic configuration.
Interface Registration: Initiate registration with the server via the register API.
Registration failed: The system directly enters the "End" process.
Registration successful: The system proceeds to the next phase via the onRegisterSuccess callback.
2. Speed Test and Evaluation Phase
Initiate speed test: After registering the listener event, set thresholds for RTT (latency), packet loss rate, jitter, and other metrics, and then start evaluating the current network quality via startMeasure.
Trigger acceleration: The onStartMpAcc callback is triggered when the network environment meets the preset acceleration conditions.
3. Acceleration Configuration and Execution Phase
Initiate acceleration: Configure the acceleration mode, application allowlist, and routing table. Then, the business side executes startAcc.
Secondary verification: The system performs a final verification of permissions, network conditions, and device compatibility.
Verification failed: The system returns the acceleration failure onAccFail.
Verification passed: The system establishes a QUIC channel, implements traffic diversion and acceleration, and returns the onAccSuccess callback.
4. Effect Monitoring and Dynamic Adjustment Phase
After acceleration is enabled, the SDK continuously monitors network performance in real time:
Normal operation: Acceleration continues.
Poor performance: If conditions such as prolonged lack of optimization, single NIC, or no network persist, it is recommended to stop acceleration (the business side decides whether to call onStopMpAcc).
5. Exception Handling and Exit Phase
Exception escape: If "negative optimization" or a gateway exception occurs, the SDK triggers the onAccException callback and proactively disables acceleration and speed testing.
End: All paths ultimately lead to the end of the process.

Flowchart





Example Code

private MeasureCallback measureCallback = new MeasureCallbackImpl();
private void initMpAcc() {
// The datakey applied from Tencent Cloud needs to be imported
MpAccClient.setDataKey("test-123456", "*");
mpAccClient = MpAccClient.getInstance(this);
}
private void startMeasure() throws MpAccSDKException {
//Trigger callback listening
mpAccClient.registerMeasureCallback(measureCallback);
MeasureConfig measureConfig = new MeasureConfig();
//Set measurement configuration threshold
measureConfig.setJitter(15)
.setLoss(5)
.setRTT(60)
.setTime(8000)
.setQuickTime(2000)
.setQuickRtt(80)
.setInterval(1000)
.setMode(2);
//Start network measurement
mpAccClient.startMeasure(measureConfig);
}
private void stopMeasure() throws MpAccSDKException {
//Unregister network measurement listener
mpAccClient.unregisterMeasureCallback(measureCallback);
//Stop network measurement
mpAccClient.stopMeasure();
}
class MeasureCallbackImpl implements MeasureCallback {
@Override
public void onStartMpAcc(int code, int links) {
//Trigger acceleration, see example code for each mode
startAcc();
}
@Override
public void onStopMpAcc(int code) {
//Disable acceleration, see example code for disabling acceleration
stopAcc();
}
@Override
public void onNoPolicy(int code) {
//No valid acceleration strategy currently
}
@Override
public void onAccException(int code) {
//Acceleration anomaly, SDK triggers fallback
}
}


Bantuan dan Dukungan

Apakah halaman ini membantu?

masukan