tencent cloud

Dynamic Acceleration

Download
Mode fokus
Ukuran font
Terakhir diperbarui: 2026-05-21 16:14:31
The SDK provides a range of network measurement APIs and policy callback APIs. By setting measurement thresholds, businesses can achieve on-demand acceleration. At the same time, 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 proactively disables acceleration and speed tests, redirecting traffic to the origin server to prevent abnormal acceleration from affecting normal business operations.
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 for business operations, the business must switch the appropriate network requests back to direct connection (no longer using the proxy).
extension TestViewController {
func initMpAcc {
MpAccClient.shared.setupDatakey("xxx", uuid: "xxx")
}
func startMeasure() {
//Register speed test listener
MpAccClient.shared.registerMeasureCallback(self)
let measureConfig = MpMeasureConfig()
/// Sliding window measurement time (ms)
config.time = 8000
/// Latency threshold
config.rtt = 60
/// Packet loss rate threshold
config.loss = 5
/// Jitter threshold
config.jitter = 15
/// Quick startup window time
config.quickTime = 2000
/// Quick startup latency threshold
config.quickRtt = 80
/// Measure callback frequency
config.interval = 1000
/// Acceleration mode
config.mode = .Redundant
/// Enable acceleration
MpAccClient.shared.startMeasure(measureConfig: measureConfig)
}
func stopMeasure() {
// Unregister network measurement listener
MpAccClient.shared.unRegisterAccCallback(self);
//stop speed measurement
MpAccClient.shared.stopMeasure()
}

}
extension TestViewController: MpMeasureCallback {
/**
* enable dual send
* @param code Trigger code 1: Latency anomaly trigger 2: Packet loss anomaly trigger 3: Jitter anomaly trigger
*/
func onStartMpAcc(code: Int) {
appendLog("code:\\(code)")
}
/**
* disable dual send
* @param code Trigger code 1: ENI trigger 2: No optimization trigger 3: No network trigger 4: Accelerated network interface and actual active network interface not the same
* @msg trigger information
*/
func onStopMpAcc(code: Int, msg: String) {
appendLog("code:\\(code)")
}
/**
* Current network status has no policy available
* @param code Trigger code 1: Mobile only 2: wifi only 3: No network 4: Internal error -19: Failed to pull up speed test service -23: Test URL unavailable -25: plugin error -23: Invalid Speed Test -11: Authentication error
* @param message trigger information, if message is not empty, mainly use message info
*/
func onNoPolicy(code: Int, message: String?) {
appendLog("code:\\(code) msg: \\(message ?? "")")
}

/**
* Exception in accelerated link (in this case the sdk will proactively disable acceleration and switch back to normal mode)
* @param errorCode error code
* @param msg error information
*/
func onAccException(errorCode: Int, msg: String) {
appendLog("errorCode:\\(errorCode) msg: \\(msg)")
}
/**
* Bypass udping rtt delay callback
* @param type type (0: mobile 1: wifi 2: acc)
* @param rtt Delay (ms) Packet loss value is 460
*/
func onRttChanged(type: Int, rtt: Int) {
appendLog("type:\\(type) rtt:\\(rtt)")
}
/**
* Aggregate acceleration status change callback
* @param state false: off true: on
* @param code 0: normally enabled 1: normal shutdown 2: abnormal shutdown
*/
func onAccStateChanged(state: Bool, code: Int) {
appendLog("state:\\(state) code:\\(code)")
}
}







Bantuan dan Dukungan

Apakah halaman ini membantu?

masukan