chuanyuxue / udp-latency Goto Github PK
View Code? Open in Web Editor NEWA single Python file network latency testing tool by UDP.
License: MIT License
A single Python file network latency testing tool by UDP.
License: MIT License
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)
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.
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?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.