benchmark-tools
Introduction
There are lots of tools for traffic capturing, sending, replaying about protocols, here are some examples of these popular tools.
capture
- tcpdump(linux)
- wireshark(windows/linux)
sending/replay
- sendip
- tcprelay
http benchmark
- ab
- wrk
io benchmark
- dd
Traffic
tcpdump vs wireshark
tcpdump and wireshark are used to capture traffic on the internet, while wireshark provides filter for us after capture, that’s much helpful, while for tcpdump, there is no filter after capture, filter is only available when capturing, but you can save tcpdump output to xx.pcap than open it with wireshark, hence use filter provided by wireshark.
when capturing packets tcpdump and wireshark use the same syntax like host 10.10.2.2 and tcp port 5000
.
tcpdump
1 | # type: host,net,port, |
wireshark capture
syntax
1 | support tcpdump syntax but more than that with extra options like this. |
wireshark filter
tips: exported filtered packets from wireshark.
At the wireshark main panel, apply a filter, then you see filtered packets displayed, then exported it by
File->Export specified Packets-> All packets(displayed)!
filter syntax
1 | tcp.port eq 25 or icmp |
wireshark display
show absolute timeView->Time Display Format
show absolute tcp seq numberPreference->Protocols->TCP [uncheck]Relative sequence numbers
for tcp retransmission how can I distinguish the original packet and retransmitted onCheck TsVal it's at packets' Tcp options Tsval
Or Tcp field checksum
sendip vs tcprelay
sendip is used to send arbitrary IP
packets while tcprelay is mostly used to replay(edit) captured packet(send it again).
sendip
sendip
sends arbitrary IP packets(ip + upper protocol), like tcp, udp, icmp, rip etc
1 | $ sudo sendip -v -d "hello" -p ipv4 -is 192.168.200.1 -id 192.168.200.2 -p udp -us 4000 -ud 1200 192.168.200.2 |
tcpreplay
tcpreplay is a series of commands that can be used to replay packets captured(not only tcp packet) with more control, like sending duration, loop, send number, pps, modify packets etc.
- tcpreplay: only
send
packets captured - tcprewrite: only
modify
(mac, vlan, ip, tcp/udp etc)captured packets and save it to a file - tcpreplay-edit: modify on fly and send the modified packets ==
tcprewrite + tcpreplay
, so options for tcprewrite still work for tcpreplay-edit
1 | $ tcpreplay -i eth0 -l 2 c.pcap # replay twice on output device eth0 |
curl vs ab vs wrk
curl used for function test
supports get/post etc. while ab/wrk are used for performance test
ab and wrk both for http benchmark(software level, should not used for production), ab is from apache, old but more powerful with lots of options, while wrk is a newly tool which is very popular today.
curl
curl provides lots of options for sending one http request, by default, curl use http1.1 can change to http1.0 or http2.0
1 | $ curl --http1.0 www.example.com |
ab
ab provides lots of options for sending http request, like set cookie, header, authentication, ssl etc, by default ab sends GET
request with default values. only supports http1.0
get
1 | $ ab -n 1000 -c 10 http://127.0.0.1:8080/index.html |
post with data
1 | $ ab -t 30 -c 10 -p ./post.data -T "application/x-www-form-urlencoded" http://local/user |
wrk
run get with default header
1 | $ wrk -t12 -c400 -d30s --latency http://127.0.0.1:8080/index.html |
run get custom header
1 | $ wrk -t2 -c10 -d30s --latency -s ./get.lua http://127.0.0.1/index.html |
run post with data
1 | $ wrk -t2 -c10 -d30s --latency -s ./post.lua http://127.0.0.1/user |
FAQ
why content-length is 0 with POST method by curl
The reason should be the content of the file used by POST contains zero, as curl first reads the whole file to memory, then calculate the content_length with strlen(file content), hence if the content of the file contains ‘\0’, the content_length != file size, unexpected. here is a example
1 | # file content is all '\0'!! |
send http over unix-socket
1 | # if http server listens on unix socket |
IO
Use dd
to test io benchmark, as it’s an easy tool to use
1 | # write to another block device like nbd here |