前提:手机(不管安卓还是苹果),连WiFi(信号满格),小程序没有新版本发布,服务器、接口都正常
请求方法:
function request(options) {
return new Promise((resolve, reject) => {
let requestStamp = Date.now() // 请求时间戳
options.complete = (response) => {
let responseStamp = Date.now() // 响应时间戳
let responseTime = responseStamp - requestStamp // 耗时
resolve(response)
}
wx.request(options)
})
}
小程序冷启动,请求是在页面onLoad 中调用,会出现超时的问题,下面我记录了一组数据
requestStamp:2024-10-22 08:59:42.129
responseStamp:2024-10-22 08:59:47.026
responseTime:4897ms(正常情况下接口响应都是在100ms以内的)
下面是响应的profile
{"responseStart":1729558787021,"redirectEnd":0,"rtt":22,"throughputKbps":0,"httpRttEstimate":115,
"sendBytesCount":464,"fetchStart":1729558786945,"estimate_nettype":5,"downstreamThroughputKbpsEstimate":1961,
"SSLconnectionStart":1729558786963,"connectStart":1729558786949,"requestEnd":1729558787022,"requestStart":1729558786948,
"redirectStart":0,"responseEnd":1729558787023,"protocol":"h2","connectEnd":1729558786987,"transportRttEstimate":22,
"port":443,"SSLconnectionEnd":1729558786987,"socketReused":false,
"domainLookUpStart":1729558786949,"receivedBytedCount":478,"domainLookUpEnd":1729558786949,"usingHighPerformanceMode":false}
解读profile
从我代码中发起请求requestStamp 到 profile中 fetchStart(资源准备好)耗时4816ms
HTTP建立连接耗时 (connectEnd - connectStart)38ms
SSL建立耗时(SSLconnectionEnd - SSLconnectionStart) 24ms
HTTP 请求读取真实文档耗时(requestEnd - requestStart) 74ms
HTTP 接收响应耗时(responseEnd - responseStart) 2ms
HTTP 请求资源准备好(fetchStart) 到 响应结束耗时(responseEnd) 78ms
这种情况我每天会收到大量的这种长时间的请求,现在就是搞不明白 为什么 到fetchStart 会花这么长的时间,有没有大佬帮忙看一下的