Giter Club home page Giter Club logo

udp-latency's Issues

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)

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.

divide by zero on Windows

When I run it on a single Windows computer, I get a divide by zero with the default options:

C:\Users\Devin\Downloads>C:\Python310\python.exe udp_latency.py -c
| ---------- Sychonizing Server & Client by PTP ------------ |
| Client: 20002 | Packet: 1 | Time: 1716832507661762600 | Data size: 1468 |
Traceback (most recent call last):
File "C:\Users\Devin\Downloads\udp_latency.py", line 269, in
client.send(
File "C:\Users\Devin\Downloads\udp_latency.py", line 102, in send
* (len(self.log) / (frequency * (current_time - start_time) * 1e-9))
ZeroDivisionError: float division by zero

I can run it fine by using --dyna False on the client side.

When I run it on my computer, the current_time and start_time are the same, which results in a divide by zero:
frequency: 1.0
current_time: 1716832724571958100
start_time: 1716832724571958100
current_time - start_time: 0

I suspect that this is only an issue on Windows and is because of the following:
https://stackoverflow.com/a/1938096

I wonder what the best approach is to prevent the divide by zero, would something like the following work or would this skew the results?
if (current_time == start_time):
current_time = start_time + 1 # prevent divide by zero if using dyna on Windows due to +/- 16 ms accuracy (https://stackoverflow.com/a/1938096)

Would it be better to run without dyna?

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.