In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-11 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article shows you how to use the curl command to analyze the time-consuming situation of the request, the content is concise and easy to understand, it will definitely brighten your eyes. I hope you can get something through the detailed introduction of this article.
Recently, I encountered a problem in my work, and the response to a request was particularly slow, so I hope there is a way to analyze which step of the request takes a long time to further find out the cause of the problem. After searching the Internet, I found a very useful method, and the curl command can help you analyze the various parts of the request.
The curl command provides the-w parameter, which is interpreted in manpage as follows:
-W,-- write-out Make curl display information on stdout after a completed transfer. The format is a string that may contain plain text mixed with any number of variables. The format can be specified as a literal "string", or you can have curl read the format from a file with "@ filename" and to tell curl to read the format from stdin you write "@ -" The variables present in the output format will be substituted by the value or text that curl thinks fit, as described below. All variables are specified as {vari- able_name} and to output a normal you just write them as. You can output a newline by using\ n, a carriage return with\ r and a tab space with\ t.
It can print certain information in a specified format, use certain variables, and support\ n,\ t, and\ r escape characters. There are many variables provided, such as status_code, local_port, size_download, and so on. In this article, we will only focus on the variables related to the request time (variables that begin with time_).
First write the following to the text file curl-format.txt:
➜~ cat curl-format.txt time_namelookup:% {time_namelookup}\ ntime_connect:% {time_connect}\ ntime_appconnect:% {time_appconnect}\ ntime_redirect:% {time_redirect}\ ntime_pretransfer:% {time_pretransfer}\ ntime_starttransfer:% {time_starttransfer}\ n -\ ntime_total:% {time_total}\ n
So what do these variables mean? Let me explain:
Time_namelookup: when DNS domain names are resolved, it is the process of translating https://zhihu.com into ip addresses.
Time_connect: the time when the TCP connection is established is the time of the three-way handshake
Time_appconnect: time for upper layer protocols such as SSL/SSH to establish a connection, such as the time of connect/handshake
Time_redirect: the time from the start to * a request transaction
Time_pretransfer: the time from the start of the request to the start of the response transmission
Time_starttransfer: the time from the start of the request to * bytes to be transferred
Time_total: the total time spent on this request
Let's first look at a simple request with no redirection and no SSL protocol time:
➜~ curl- w "@ curl-format.txt"-o / dev/null-s-L "http://cizixs.com" time_namelookup: 0.012 time_connect: 0.227 time_appconnect: 0.000 time_redirect: 0.000 time_pretransfer: 0.227 time_starttransfer: 0.443-time_total: 0.867
You can see that the time of each step of this request has been printed out, and each number is in seconds, so you can analyze which step is more time-consuming and make it easy to locate the problem. The meaning of each parameter of this command:
-w: read the format of the information to be printed from the file
-o / dev/null: discard the content of the response, because we don't care about it here, only about the time consuming of the request
-s: do not print the progress bar
From this output, we can calculate the time of each step:
DNS query: 12ms
TCP connection time: pretransfter (2277)-namelookup (12) = 215ms
Server processing time: starttransfter (443)-pretransfer (227) = 216ms
Content transfer time: total (867)-starttransfer (443) = 424ms
For a more complicated one, visit the home page with redirection and SSL protocol in the middle:
➜~ curl- w "@ curl-format.txt"-o / dev/null-s-L "https://baidu.com" time_namelookup: 0.012 time_connect: 0.018 time_appconnect: 0.328 time_redirect: 0.356 time_pretransfer: 0.018 time_starttransfer: 0.027-time_total: 0.384
You can see that both time_appconnect and time_redirect are not zero, and the processing time of SSL protocol is 328-18=310ms. And the time for both pretransfer and starttransfer is shortened, which is the time requested after the redirect.
The above is how to use the curl command to analyze the time-consuming situation of the request. Have you learned the knowledge or skills? If you want to learn more skills or enrich your knowledge reserve, you are welcome to follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 265
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.