我试图找出究竟需要多lessnetworking数据来执行一个HTTP请求
我目前使用curl来模拟请求
curl -v -X POST ${vehicles_endpoint}/updateMileageAndErrorCodes/abc123/9500/P0187,P0191,P0213
并捕获响应:
* About to connect() to localhost port 8088 (#0) * Trying ::1... connected * Connected to localhost (::1) port 8088 (#0) > POST /vdm/vehicles/updateMileageAndErrorCodes/abc123/15000/P0110 HTTP/1.1 > User-Agent: curl/7.21.4 (universal-apple-darwin11.0) libcurl/7.21.4 OpenSSL/0.9.8r zlib/1.2.5 > Host: localhost:8088 > Accept: */* > < HTTP/1.1 204 No Content < Server: Apache-Coyote/1.1 < Date: Wed, 28 Aug 2013 08:20:18 GMT < * Connection #0 to host localhost left intact * Closing connection #0
如何找出执行此请求/响应所需的确切字节数?
我可以看看请求中的字符数(211)
POST /vdm/vehicles/updateMileageAndErrorCodes/abc123/9500/P0187,P0191,P0213 HTTP/1.1 User-Agent: curl/7.21.4 (universal-apple-darwin11.0) libcurl/7.21.4 OpenSSL/0.9.8r zlib/1.2.5 Host: localhost:8088 Accept: */*
和回应(86):
HTTP/1.1 204 No Content Server: Apache-Coyote/1.1 Date: Wed, 28 Aug 2013 08:20:18 GMT
但是我想有一些其他协议相关的开销?
如果我做了一个tcpdump
sudo tcpdump -s 0 -X 'tcp dst port 80'
它给了我以下输出:
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode listening on eth0, link-type EN10MB (Ethernet), capture size 65535 bytes 10:41:47.442934 IP 34-188-5-188.mobileinternet.proximus.be.51905 > CentOS-63-64-minimal.http: Flags [S], seq 1277831461, win 13140, options [mss 1460,sackOK,TS val 3832792 ecr 0,nop,wscale 1], length 0 0x0000: 4500 003c 52fd 4000 2906 b6e0 bc05 bc22 E..<R.@.)......" 0x0010: 904c 3f6a cac1 0050 4c2a 2925 0000 0000 .L?j...PL*)%.... 0x0020: a002 3354 1060 0000 0204 05b4 0402 080a ..3T.`.......... 0x0030: 003a 7bd8 0000 0000 0103 0301 .:{......... 10:41:47.862952 IP 34-188-5-188.mobileinternet.proximus.be.51905 > CentOS-63-64-minimal.http: Flags [.], ack 197676124, win 6570, options [nop,nop,TS val 3832868 ecr 2984946753], length 0 0x0000: 4500 0034 52fe 4000 2906 b6e7 bc05 bc22 E..4R.@.)......" 0x0010: 904c 3f6a cac1 0050 4c2a 2926 0bc8 4c5c .L?j...PL*)&..L\ 0x0020: 8010 19aa a223 0000 0101 080a 003a 7c24 .....#.......:|$ 0x0030: b1ea ac41 ...A 10:41:48.144006 IP 34-188-5-188.mobileinternet.proximus.be.51905 > CentOS-63-64-minimal.http: Flags [P.], seq 0:317, ack 1, win 6570, options [nop,nop,TS val 3832874 ecr 2984946753], length 317 0x0000: 4500 0171 52ff 4000 2906 b5a9 bc05 bc22 E..qR.@.)......" 0x0010: 904c 3f6a cac1 0050 4c2a 2926 0bc8 4c5c .L?j...PL*)&..L\ 0x0020: 8018 19aa 63e2 0000 0101 080a 003a 7c2a ....c........:|* 0x0030: b1ea ac41 504f 5354 202f 7664 6d2f 7665 ...APOST./vdm/ve 0x0040: 6869 636c 6573 2f75 7064 6174 654d 696c hicles/updateMil 0x0050: 6561 6765 416e 6445 7272 6f72 436f 6465 eageAndErrorCode 0x0060: 732f 6162 6331 3233 2f39 3530 302f 5030 s/abc123/9500/P0 0x0070: 3138 372c 5030 3139 312c 5030 3231 3320 187,P0191,P0213. 0x0080: 4854 5450 2f31 2e31 0d0a 5573 6572 2d41 HTTP/1.1..User-A 0x0090: 6765 6e74 3a20 4461 6c76 696b 2f31 2e36 gent:.Dalvik/1.6 0x00a0: 2e30 2028 4c69 6e75 783b 2055 3b20 416e .0.(Linux;.U;.An 0x00b0: 6472 6f69 6420 342e 333b 2047 616c 6178 droid.4.3;.Galax 0x00c0: 7920 4e65 7875 7320 4275 696c 642f 4a57 y.Nexus.Build/JW 0x00d0: 5236 3659 290d 0a48 6f73 743a 2076 646d R66Y)..Host:.vdm 0x00e0: 2d61 7069 2e65 636f 6d6d 6974 2d63 6f6e -api.ecommit-con 0x00f0: 7375 6c74 696e 672e 6265 0d0a 436f 6e6e sulting.be..Conn 0x0100: 6563 7469 6f6e 3a20 4b65 6570 2d41 6c69 ection:.Keep-Ali 0x0110: 7665 0d0a 4163 6365 7074 2d45 6e63 6f64 ve..Accept-Encod 0x0120: 696e 673a 2067 7a69 700d 0a43 6f6e 7465 ing:.gzip..Conte 0x0130: 6e74 2d54 7970 653a 2061 7070 6c69 6361 nt-Type:.applica 0x0140: 7469 6f6e 2f78 2d77 7777 2d66 6f72 6d2d tion/x-www-form- 0x0150: 7572 6c65 6e63 6f64 6564 0d0a 436f 6e74 urlencoded..Cont 0x0160: 656e 742d 4c65 6e67 7468 3a20 300d 0a0d ent-Length:.0... 0x0170: 0a . 10:41:49.603082 IP 34-188-5-188.mobileinternet.proximus.be.51905 > CentOS-63-64-minimal.http: Flags [.], ack 162, win 6490, options [nop,nop,TS val 3833096 ecr 2984948484], length 0 0x0000: 4500 0034 5300 4000 2906 b6e5 bc05 bc22 E..4S.@.)......" 0x0010: 904c 3f6a cac1 0050 4c2a 2a63 0bc8 4cfd .L?j...PL**c..L. 0x0020: 8010 195a 98ee 0000 0101 080a 003a 7d08 ...Z.........:}. 0x0030: b1ea b304 .... 10:41:49.622962 IP 34-188-5-188.mobileinternet.proximus.be.51905 > CentOS-63-64-minimal.http: Flags [F.], seq 317, ack 163, win 6490, options [nop,nop,TS val 3833098 ecr 2984948484], length 0 0x0000: 4500 0034 5301 4000 2906 b6e4 bc05 bc22 E..4S.@.)......" 0x0010: 904c 3f6a cac1 0050 4c2a 2a63 0bc8 4cfe .L?j...PL**c..L. 0x0020: 8011 195a 98ea 0000 0101 080a 003a 7d0a ...Z.........:}. 0x0030: b1ea b304 ....
我注意到请求的全部长度(包括所有http请求标头)为317,但我也看到很多长度:0输出。
我怎样才能弄清楚为这个请求传输的确切的字节数? (我用我的android手机数据使用工具,并注意到它是每个请求大约900字节)。
大爸爸要弄清单个请求的全部内容(包括主页所调用的外部文件),查看Pingdom的网站速度testing
您可以使用curl -I http://sitename或wget该网站。
curl -I只显示标题(包括Content-Length),但放弃文件,其中wget实际上是保存主站点文件(如index.html)。 这会得到主文件的大小,但不是所有页面也调用的文件。
您也可以尝试使用Chrome开发工具来收集一些见解。
您可以尝试HttpAnalyzer实用程序作为PcapPlusPlus项目的一部分。 这个工具可以捕获HTTP数据并收集很多关于它的统计信息。 其余部分收集HTTP请求/响应大小。 你可以阅读更多: http :
使用tshark / wireshark捕捉整个stream量并以可视化的方式进行分析 – 对您来说更容易。
工具iftop ( man iftop )通过主机在接口上显示带宽使用情况,传输/接收/总字节的累积统计信息,并且支持定义众所周知的PCAPfilter(例如使用tcpdump)来只计算特定的stream量。 您可以尝试使用简单的命令来监控httpstream量
iftop -P -i eth0 -f "dst port http"
默认情况下,当iftop启动时,屏幕的上半部分显示客户端和服务器之间当前的带宽使用情况,下方显示累积统计信息。 你可以通过在~/.iftoprc创build一个configuration文件来改变它,或者用-c选项来指定它。
尝试使用tcpdump -v来获得全包长度。 你在这里得到的(不带“-v”)是有效载荷大小(等于包大小减ethernet / IP / TCP头)。
然后总结一下整个通讯过程(过滤“src主机”可能有助于缩小stream量)
你不清楚你是否只计算输出数据包或input输出。
使用ifconfig可以看到在每个networking接口上发送和接收的字节数。 你可以在testing之前和之后运行ifconfig,然后从之后的字节数中减去之前的字节数。