我如何阅读URLSessionTaskMetrics?

时间:2017-05-26 16:09:41

标签: ios nsurlsession

我收集有关请求的指标,我看到以下信息:

(Task Interval) <_NSConcreteDateInterval: 0x60800022d6e0> (Start Date) 2017-05-26 15:04:14 +0000 + (Duration) 4.643568 seconds = (End Date) 2017-05-26 15:04:19 +0000
(Redirect Count) 0
(Transaction Metrics) (Request) <NSURLRequest: 0x608000016b80> { URL: <URL> }
(Response) <NSHTTPURLResponse: 0x60800043ad00> { URL: <URL> } { status code: 200, headers { <headers> }
(Fetch Start) 2017-05-26 15:04:14 +0000
(Domain Lookup Start) (null)
(Domain Lookup End) (null)
(Connect Start) (null)
(Secure Connection Start) (null)
(Secure Connection End) (null)
(Connect End) (null)
(Request Start) 2017-05-26 15:04:14 +0000
(Request End) 2017-05-26 15:04:14 +0000
(Response Start) 2017-05-26 15:04:18 +0000
(Response End) 2017-05-26 15:04:19 +0000
(Protocol Name) h2
(Proxy Connection) NO
(Reused Connection) YES
(Fetch Type) Network Load

让我感到困惑的是以下几行:

(Request End) 2017-05-26 15:04:14 +0000
(Response Start) 2017-05-26 15:04:18 +0000

事情发生了四秒钟,我无法理解究竟是什么。

同时ab(Apache Benchmark)显示以下数字:

Requests per second:    1.59 [#/sec] (mean)
Time per request:       629.910 [ms] (mean)
Time per request:       629.910 [ms] (mean, across all concurrent requests)
Transfer rate:          121.60 [Kbytes/sec] received

有没有人知道那里可能出错的地方?如何改善响应时间?

1 个答案:

答案 0 :(得分:1)

请求结束和响应开始之间的时间是http标头传输和服务器准备发送给您的响应。我的猜测是你应该检查你的GET。 下图很好地解释了指标和时间表: enter image description here