Curl Gets the response time of the site

Source: Internet
Author: User
Tags response code browser cache

Curl Gets the response time of the site




0. Questions


There is always feedback that opening a page is slow,

But they don't know exactly where the slow is.

The same problem,

When we access the interfaces of the external business,

Often also feel very slow,

But it's not clear where it's slow.




1. Analysis


When we open a webpage,

For a person who does not need to think about technology,

Imagine that the picture should be,

We ask the browser for a thing through the address bar,

The browser then uses the address we provide to the corresponding server to fetch the corresponding file,

The content is then displayed to us according to the server's response.


From the perspective of an OPS person,

may not be so simple and rough to imagine,

Otherwise, you may never be able to confirm where the problem actually occurs.

650) this.width=650; "Src=" https://s2.51cto.com/wyfs02/M02/95/A2/wKiom1kX67SyNSqHAAKGkcagTis841.png-wh_500x0-wm_ 3-wmp_4-s_4264917737.png "title=" 1488804830_17_w960_h720.png "alt=" wkiom1kx67synsqhaakgkcagtis841.png-wh_50 "/ >



Simple point to summarize,

1. When we open the browser and enter www.qq.com in the Address bar,

The browser will first be based on the browser cache, computer cache, computer Hosts file, DNS service to resolve the www.qq.com corresponding network address is how much, this process will be based on the resolution of different places and time-consuming different.


Using the browser cache and the computer cache,

The results returned are the fastest, but may not be up-to-date or wrong.

The priority of resolving a domain name through the Hosts file is higher than the DNS service parsing,

We can also modify the parsing results of some domain names in the hosts.


2. After the browser obtains the domain name corresponding IP, starts to connect with the server three handshake.

3. The browser initiates a service request to the server after it has established a connection

4. After processing the request inside the server, send the processing result to the browser

5. The browser parses the result sent by the server and then presents it to the user


650) this.width=650; "Src=" https://s2.51cto.com/wyfs02/M00/95/A2/wKioL1kX68iS9lg3AAOA_bEGVE0404.png-wh_500x0-wm_ 3-wmp_4-s_2826386342.png "title=" 1488807484_30_w960_h720.png "alt=" wkiol1kx68is9lg3aaoa_begve0404.png-wh_50 "/ >


The above briefly describes the browser in the service request with the server process,

Any one of these links can take too long to affect the speed at which users visit the site.



2.Curl Get Related data


Using cur-w/--write-out l to get relevant data


Some of the more critical parameters:


Url_effective the URL that was last fetched.

Http_code The response code returned by the last HTTP (s) or FTP (s) operation. The same information is displayed in the Response_code 7.18.2 version.

Http_connect the numeric code found in response to the last connect request to curl (from the proxy). (added in 7.12.4 version)

Time_Total the time spent in all operations, in seconds. Accurate to milliseconds.

Time_namelookup The amount of time, in seconds, to complete from the start to the domain name resolution.

Time_connect the time, in seconds, that TCP connects to a remote host (or proxy server).

Time_appconnect ssl/ssh/time spent with remote host connection/handshake completion in seconds. (added in 7.19.0 version)

Time_pretransfer The amount of time, in seconds, that the file will take before it is to be transmitted. Includes all pre-transfer commands and negotiations for the specified protocol.

Time_redirect the time of all redirect steps, the packet domain name resolution, the connection, the pre-transfer, and the transfer before the last transaction begins, in seconds. Time_redirect shows the full execution time for multiple redirects. (added in 7.12.3 version)

Time_starttransfer The amount of time, in seconds, that will be spent before the first byte is transferred from the start.

This includes the time that the Time_pretransfer and the server require the results of the operation.

Size_download The total number of bytes downloaded.

Size_upload The total number of bytes uploaded.

Size_header The total number of bytes downloaded by the header.

The total number of bytes of HTTP requests sent by the Size_request.

Average download speed of Speed_download curl for successful downloads.

Average upload speed of speed_upload curl uploads successfully.





3. Get the time-consuming information for the request



For specific requests, the time-consuming situation of each link can be obtained through curl,

such as the time-consuming domain name resolution, the time to establish the connection, the service-side processing time, total time-consuming.



The material of a domestic cooperation party


Curl-o/dev/null-s-W "Http_code:%{http_code}\nhttp_connect:%{http_connect}\ncontent_type:%{content_type}\ntime_ dns:%{time_namelookup}\ntime_redirect:%{time_redirect}\ntime_pretransfer:%{time_pretransfer}\ntime_connect:%{ Time_connect}\ntime_starttransfer:%{time_starttransfer}\ntime_total:%{time_total}:\nspeed_download:%{speed_ download}\n "" Http://di.adsame.com/flv_test/20161107143341_231.jpg ";


http_code:200

http_connect:000

Content_type:image/jpeg

time_dns:0.005

time_redirect:0.000

time_pretransfer:0.013

time_connect:0.013

time_starttransfer:0.021

time_total:0.029:

speed_download:441815.000


Apple website Image material


Curl-o/dev/null-s-W "Http_code:%{http_code}\nhttp_connect:%{http_connect}\ncontent_type:%{content_type}\ntime_ dns:%{time_namelookup}\ntime_redirect:%{time_redirect}\ntime_pretransfer:%{time_pretransfer}\ntime_connect:%{ Time_connect}\ntime_starttransfer:%{time_starttransfer}\ntime_total:%{time_total}:\nspeed_download:%{speed_ download}\n "" Http://images.apple.com/v/iphone-7/d/images/overview/design_hero_large.jpg ";


http_code:200

http_connect:000

Content_type:image/jpeg

time_dns:0.449

time_redirect:0.000

time_pretransfer:0.456

time_connect:0.456

time_starttransfer:0.465

time_total:0.493:

speed_download:419293.000


Weibo short domain link


Curl-o/dev/null-s-W "Http_code:%{http_code}\nhttp_connect:%{http_connect}\ncontent_type:%{content_type}\ntime_ dns:%{time_namelookup}\ntime_redirect:%{time_redirect}\ntime_pretransfer:%{time_pretransfer}\ntime_connect:%{ Time_connect}\ntime_starttransfer:%{time_starttransfer}\ntime_total:%{time_total}:\nspeed_download:%{speed_ download}\n "-L" Http://t.cn/Rip1YJA "


http_code:200

http_connect:000

Content_type:text/html;charset=gbk

time_dns:0.210

time_redirect:0.079

time_pretransfer:0.240

time_connect:0.240

time_starttransfer:0.290

time_total:0.369:

speed_download:4349.000


4. Other


Currently, you can only use curl to get to a static page of a specified request, or you can't request a link from a page to a browser like that.

This will not realistically reflect the time-consuming situation of accessing pages in the browser.

But when the user reflects a slow time to access a page,

Access to the corresponding address via curl is basically OK,

Where a single request is primarily time-consuming.


This article from "Ops said: from rookie to veteran" blog, please be sure to keep this source http://liuqunying.blog.51cto.com/3984207/1925464

Curl Gets the response time of the site

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.