I have an HTTP Api Server that is querying a UDP Server. I used wrk to test the requests per second for the HTTP Api Server and now I want to test the UDP Server requests per second and latency per request. Id like to be able to set the number of threads and connections just like wrk does.

For wrk, I did the following:

wrk -t30 -c100 -d30s http://localhost:8083/queryArgument

which queries the API Server than then inside the code queries UDP.

I want to query the UDP Server alone without going thorugh the API Server.

For the example provided by the person who created the UDP Server, we have the following command to run:

echo -n "queryArgument" | nc -u -w4 1175

I don't know how to convert this into something I can pipe into wrk

Any help would be greatly appreciated.

The end goal would be to see statistics on querying UDP


I was able to query netcat as so:

time yes|nc -v -u -z -w 3 1175

But its in seconds for sys and i need milliseconds

  • 2
    There is no such thing as a UDP connection. UDP is explicitly a connectionless protocol; it is fire-and-forget, best-effort. – Ron Maupin Jun 28 '18 at 15:53

For traffic generation and benchmarking, "wrk" and "ab" (apachebench) only work for TCP HTTP requests. To generate UDP traffic, you will need to write your own code. (Eg. see http://1wt.eu/tools/udp-test/)

If you want timings, its probably best to use a dedicated traffic capture utility, such as tcpdump, tshark or wireshark, or write your own code with libcap or libtins. (Eg. https://github.com/pollere/pping)

If you simply need counters and throughputs, you can use iptables (or if you're on a bleeding edge server, nftables, which has a different command interface)

 iptables -t mangle -I INPUT -p udp --sport 1175
 iptables -t mangle -I INPUT -p udp --dport 1175

This creates firewall entries that does nothing but count the packets to- and from port 1175 on the local host. Then you can view the counters:

 iptables -nvxL -t mangle 

Which will give you the packet and byte counts.

If you want to confine it to loopback, and, and give it a unique comment line so you can delete it again when you're done:

 iptables -t mangle -I INPUT -p udp --sport 1175 -i lo -s -m comment --comment watch
 iptables -t mangle -I INPUT -p udp --dport 1175 -i lo -d -m comment --comment watch

When your traffic moves to another host, you will need to move the rules to the second rule to the OUTPUT chain. Or if you can monitor this traffic on your router, firewall, or another inbetween host, you can put both of the rules in the FORWARD chain.

You can do all of the above with syscalls to libiptc, or create your own favourite language interface too, of course, if you like. There are some other options such as rfw, ufw and more. Most utilities seem to talk to the firewall via iptables though.

When in doubt, consult:

 man iptables
  • How do I delete the entries from your first iptables example? – Yonaton Reid Jun 28 '18 at 16:47
  • iptables -nvxL # shows the line numbers for each item. You can then use iptables -t mangle -D INPUT 2 # and iptables -t mangle -D INPUT 1 .... Start at the higher numbers... because if you start at the lower numbers the higher ones shift down. Of course if its just those two you can just do the second command twice. – Dagelf Jun 29 '18 at 16:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.