Giter VIP home page Giter VIP logo

udp-latency's Introduction

udp-latency

A single Python file end-to-end latency testing tool based on UDP ๐Ÿ“ˆ.

Support both one-way and round-trip latency measurement:

  • udp_latency.py measures one-way latency.
  • udp_rrt.py measures round-trip latency. (both with same arguments)

example

Features

Compare with existing latency measuring tools.

udp-latency tcp-latency Ping command IPerf
Support UDP โœ… โŒ โŒ โœ…
Flexible packet size โœ… โŒ โŒ โŒ
Flexible bandwidth โœ… โŒ โŒ โœ…
Specific sending period โœ… โœ… โœ… โŒ
Simple as single Python file โœ… โŒ โŒ โŒ

Client Usage

python3 udp_latency.py -c -f/m <frequency / bandwidth> -n <packet size> -t <running time> --ip <remote ip> --port <remote port> --verbose <bool> --sync <bool>

Server Usage

python3 udp_latency.py -s -b <buffer size> --ip <remote ip> --port <local port> --verbose <bool> --sync <bool> --save <records saving path>

Arguments

Argument Description Default value
-c Client N/A
-s Server N/A
-f Frequency of sending packets from clients, unit is Hz (number of packet per second). -f โ€œmโ€ means constantly send UDP packets in maximum bandwidth 1
-m Bandwidth of sending packets from clients, unit is Mbits. This argument will overwritten -f argument. N/A
-n Size of sending packets in clients, unit is bytes. Notes that it is the frame size on wire including IP header and UDP header, the packet size should be within (44, 1500]. 1500
-t Client running time, uint is second. The server also stops when client stops running. 10
-b Buffer size in server. 1500
--ip Remote ip. 127.0.0.1
--port To port and local port for client and server respectively. 20001
--verbose Whether to print the testing result each iteration. True
--sync Whether to do the time synchronization in advance. (only for udp_latency.py) True
--dyna Whether to use dynamic bandwidth adaption. True
--save File path to save testing result. ./result.csv

Time synchronization (--sync)

โš ๏ธ Udp-latency (one-way) requires precise synchronization (same clock time) between server and clients. The basic idea for my implementation is from IEEE PTP protocol.

ptp

In the first 10 seconds before measurement, PTP events are exchanged per second to calculate time offset between the server and clients. To avoid the impact on the experimental traffic, it stops sending PTP messages during the experiment and neglects the time drifting.

Udp-rrt doesn't rely on synchronization.

Dynamic adaption (--dyna)

โš ๏ธ This method will slightly damage the periodicity. (Small jitter contains with this additional bandwidth optimization)

Due to the non-deterministic delay in `socket.sendto()` system call, it is difficult to maintain a constant sending bandwidth/frequency. For example, you want to send flow in 5 Mbits with `-m` argument (for a 100 byte packet in 1 Gbs linkspeed, you call `socket.sendto` every 2.5 us in Python interpreter), however, the sending speed can be only 3 Mbits when there is an around 1.67 us delay in `socket.sendto()` system call. Furthermore, this delay can be different using kernel scheduling policy and system workload making it hard to bound or estimate (See the following figure about the delay measurement).

figure

To alleviate this problem here, this code uses a greedy method to adjust sending frequency dynamically (like PID control):

$$ NewFrequency = \frac{ExpectedFrequency}{DecayedRate}, ExpectedFrequency = \frac{CurrentFrquency \times RunningTime}{RemaingTime}, DecayedRate = \frac{CurrentFrequency}{Global Frequency} $$

Where $CurrenctFrequency$ is the accumulated frequency from the program beginning to the current time. $GlobalFrequency$ is the frequency user set with -f or -m argument. $RunningTime$ and $RemainingTime$ are the time from the programming beginning time and time to the programming ending time defined by -t argument respectively.

During the local test through 127.0.0.1, the gap between realistic and expected bandwidth is bounded within 1%, the difference can be 30% without dynamic adaption.

Contact

Feel free to contact me at [email protected]

udp-latency's People

Contributors

chuanyuxue avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

udp-latency's Issues

quick question

Hi @ChuanyuXue, a quick question is what is the reason we choose socket instead of scapy to implement the udp latency? Thank you very much for your answering.

round-trip latency is similar to one-way latency

Hi @ChuanyuXue,

I got similar results when testing udp_rrt and udp_latency. It seems like division 2 of udp_rrt.py needs to be removed in the following function.

def listen(self, buffer_size: int, verbose: bool, save: Optional[str], q: Queue)-> None:
        latency = 0.0
        while True:
            msg, _ = self._udp_socket.recvfrom(buffer_size)
            recv_time = time.time_ns()
            packet_index = int.from_bytes(msg[:4], 'big')
            send_time = int.from_bytes(msg[4:12], 'big')
            old_latency = latency
            latency = round(((recv_time - send_time) * 1e-9) / 2, 6)
            jitter = abs(latency - old_latency)
            recv_size = len(msg)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.