{"id":290,"date":"2023-02-24T21:54:37","date_gmt":"2023-02-24T13:54:37","guid":{"rendered":"https:\/\/www.appblog.cn\/?p=290"},"modified":"2023-04-30T15:12:01","modified_gmt":"2023-04-30T07:12:01","slug":"curl-test-dns-parsing-time-and-tcp-connection-time","status":"publish","type":"post","link":"https:\/\/www.appblog.cn\/index.php\/2023\/02\/24\/curl-test-dns-parsing-time-and-tcp-connection-time\/","title":{"rendered":"curl\u6d4b\u8bd5dns\u89e3\u6790\u65f6\u95f4\u53catcp\u8fde\u63a5\u65f6\u95f4"},"content":{"rendered":"<p>1\u3001\u7528Linux\u4e0b\u7684<code>curl<\/code>\u547d\u4ee4\u6d4b\u91cf\u7f51\u7edc\u8bf7\u6c42(\u5206\u53f7\u662f\u5206\u9694\u7b26\uff0c\u53ef\u4ee5\u662f\u5176\u4ed6\u7b26\u53f7)\uff1a<\/p>\n<pre><code class=\"language-bash\"># curl -o \/dev\/null -s -w %{time_connect}:%{time_starttransfer}:%{time_total}  http:\/\/www.baidu.com\n\n0.037:0.209:0.210<\/code><\/pre>\n<p><!-- more --><\/p>\n<p><code>-o<\/code>\uff1a\u8868\u793a\u8f93\u51fa\u7ed3\u679c\u5230<code>\/dev\/null<\/code>\uff0c<code>-s<\/code>\u8868\u793a\u53bb\u9664\u72b6\u6001\u4fe1\u606f\uff0c<code>-w<\/code>\u8868\u793a\u5217\u51fa\u540e\u9762\u7684\u53c2\u6570\u7684\u7ed3\u679c\u3002<\/p>\n<p>\u800c\u4e14<code>python<\/code>\u4e5f\u6709\u4e00\u4e2a<code>pycurl<\/code>\u6a21\u5757<\/p>\n<p>2\u3001<code>curl<\/code>\u547d\u4ee4\u652f\u6301\u7684\u53c2\u6570\uff0c\u6709\u5982\u4e0b\uff1a<\/p>\n<ul>\n<li><code>time_connect<\/code>\uff1a\u5efa\u7acb\u5230\u670d\u52a1\u5668\u7684 TCP \u8fde\u63a5\u6240\u7528\u7684\u65f6\u95f4<\/li>\n<li><code>time_starttransfer<\/code>\uff1a\u5728\u53d1\u51fa\u8bf7\u6c42\u4e4b\u540e,Web \u670d\u52a1\u5668\u8fd4\u56de\u6570\u636e\u7684\u7b2c\u4e00\u4e2a\u5b57\u8282\u6240\u7528\u7684\u65f6\u95f4<\/li>\n<li><code>time_total<\/code>\uff1a\u5b8c\u6210\u8bf7\u6c42\u6240\u7528\u7684\u65f6\u95f4<\/li>\n<li><code>time_namelookup<\/code>\uff1aDNS\u89e3\u6790\u65f6\u95f4,\u4ece\u8bf7\u6c42\u5f00\u59cb\u5230DNS\u89e3\u6790\u5b8c\u6bd5\u6240\u7528\u65f6\u95f4(\u8bb0\u5f97\u5173\u6389 Linux \u7684 nscd \u7684\u670d\u52a1\u6d4b\u8bd5)<\/li>\n<li><code>speed_download<\/code>\uff1a\u4e0b\u8f7d\u901f\u5ea6\uff0c\u5355\u4f4d-\u5b57\u8282\u6bcf\u79d2\u3002<\/li>\n<\/ul>\n<p>\u901a\u8fc7\u8be5\u547d\u4ee4\uff0c\u53ef\u4ee5\u8ba1\u7b97\u7f51\u7edc\u8bf7\u6c42\u4e2dDNS\u89e3\u6790\u3001\u8fde\u63a5\u3001\u4f20\u8f93\u53ca\u603b\u7684\u65f6\u95f4\uff0c\u8fdb\u884c\u521d\u6b65\u7684\u6545\u969c\u6392\u67e5\u3002<\/p>\n<p>\u5173\u4e8enscd\u7684\u8bf4\u660e\uff1a<a target=\"_blank\" rel=\"noopener\" href=\"https:\/\/www.hi-linux.com\/posts\/9461.html\">https:\/\/www.hi-linux.com\/posts\/9461.html<\/a><\/p>\n<p>3\u3001\u4f8b\u5b50<\/p>\n<pre><code class=\"language-bash\"># curl -o \/dev\/null -s -w time_namelookup:&quot;\\t&quot;%{time_namelookup}&quot;\\n&quot;time_connect:&quot;\\t\\t&quot;%{time_connect}&quot;\\n&quot;time_appconnect:&quot;\\t&quot;%{time_appconnect}&quot;\\n&quot;time_pretransfer:&quot;\\t&quot;%{time_pretransfer}&quot;\\n&quot;time_starttransfer:&quot;\\t&quot;%{time_starttransfer}&quot;\\n&quot;time_total:&quot;\\t\\t&quot;%{time_total}&quot;\\n&quot;time_redirect:&quot;\\t\\t&quot;%{time_redirect}&quot;\\n&quot; https:\/\/www.baidu.com\ntime_namelookup:    0.004\ntime_connect:        0.010\ntime_appconnect:    0.068\ntime_pretransfer:    0.068\ntime_starttransfer:    0.075\ntime_total:        0.075\ntime_redirect:        0.000<\/code><\/pre>\n<ul>\n<li>DNS\u89e3\u6790\u8017\u65f6\uff1a0.004s<\/li>\n<li>TCP\u5efa\u7acb\u8fde\u63a5\u7684\u8017\u65f6\uff1a0.010-0.004=0.06s<\/li>\n<li>SSL\u63e1\u624b\u5b8c\u6210\u8017\u65f6\uff1a0.068-0.010=0.058s\uff0c58ms\uff0c\u591a\u4e86\u4e00\u5c42SSL\u8fd8\u662f\u5f88\u8017\u65f6\u7684\uff1b<\/li>\n<li>server\u5904\u7406\u6570\u636e\u7684\u65f6\u95f4\uff1a0.068-0.068=0\uff0c0ms\uff0c\u8bf4\u660e\u670d\u52a1\u5668\u5904\u7406\u5f88\u5feb\uff0c\u5982\u679cserver\u8017\u65f6\u8f83\u9ad8\uff0c\u5c31\u9700\u8981\u5206\u6790\u4ed6\u7684\u8017\u65f6\uff1a\u9632\u706b\u5899-&gt;\u8d1f\u8f7d\u5747\u8861-&gt;\u5e94\u7528-&gt;\u7f13\u5b58\u548cDB\uff0c\u9700\u8981\u6df1\u5165\u5206\u6790\u65f6\u95f4\u6d88\u8017\u5728\u54ea\u4e2a\u73af\u8282\uff1b<\/li>\n<li>\u603b\u4f53\u7684\u8017\u65f6\uff1a0.075s<\/li>\n<li>\u6574\u4e2a\u8fc7\u7a0b\u6ca1\u6709redirect\uff0c\u6240\u4ee5redirect\u7684\u8017\u65f6\u4e3a0<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>1\u3001\u7528Linux\u4e0b\u7684curl\u547d\u4ee4\u6d4b\u91cf\u7f51\u7edc\u8bf7\u6c42(\u5206\u53f7\u662f\u5206\u9694\u7b26\uff0c\u53ef\u4ee5\u662f\u5176\u4ed6\u7b26\u53f7)\uff1a # curl -o \/dev\/ [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[9],"tags":[73],"class_list":["post-290","post","type-post","status-publish","format-standard","hentry","category-devops-base","tag-curl"],"_links":{"self":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/290","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/comments?post=290"}],"version-history":[{"count":0,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/290\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/media?parent=290"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/categories?post=290"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/tags?post=290"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}