I hope some network experts can help me here, this is probably not-so-Julia-related.
My problem is that I am unable to receive more than ~600 UDP packets per second (on my MacBook, on my Xeon it’s ~900/s) however, I am able to send several thousands per seconds with a fixed rate.
I am wondering: is this an intrinsic limit of my network/hardware or am I overlooking some settings?
To spam UDP packets with a fixed rate, I use this script, which will print a .
whenever it failed to send a packet “on-time”, just to see if it can keep up with a constant rate. I noticed that I can do up to 20000 UDP packets (on my Xeon) with only a few dots per second, to exclude that bottleneck.
#!/usr/bin/env julia
using Sockets
if length(ARGS) < 1
println("Usage ./send.jl PACKETS_PER_SECOND")
exit(1)
end
function main()
target = ip"127.0.0.1"
port = 10000
data = rand(UInt8, 244)
packets_per_second = parse(Int, ARGS[1])
sock = UDPSocket()
send_data(sock, target, port, data, packets_per_second)
end
function send_data(sock, target, port, data, packets_per_second)
delta_t = 1 / packets_per_second
stopat = time() + delta_t
while true
now = time()
send(sock, target, port, data)
pausefor = now + delta_t - time()
if pausefor < 0
# error("Can't keep up with UDP packet rate ($pausefor s)")
print(".")
continue
end
sleep(pausefor)
end
end
main()
Running this on my Xeon with ./send.jl 20000
(on my MacBook with 2000) and then executing the following script to count the UDP packets for a given time period:
#!/usr/bin/env julia
using Sockets
if length(ARGS) < 1
println("Usage: udp.jl TIMEOUT")
exit(1)
end
function main()
println("Setting up UDP connection")
sock = UDPSocket()
bind(sock, ip"0.0.0.0", 10000)
timeout = parse(Int64, ARGS[1])
println("Counting UDP packets for $timeout seconds")
n = countpackets(sock, timeout)
println("$n UDP packets recieved")
end
function countpackets(sock, timeout)
stopat = time() + timeout
n = 0
while time() < stopat
data = recv(sock)
n += 1
end
n
end
main()
yields:
░ tamasgal@greybox.local:~/tmp/udp took 11s
░ 10:49:10 > ./receive.jl 10
Setting up UDP connection
Counting UDP packets for 10 seconds
6879 UDP packets recieved
I also tried increasing the socket buffer size up to the maximum allowed value using the following code but it did not help:
arg = Ref{Cint}(...) # this value is doubled on Linux
Base.uv_error("buffer size",ccall(:uv_recv_buffer_size, Cint, (Ptr{Cvoid}, Ptr{Cint}), sock.handle, arg))
Any ideas why it hits this limit? In Python I see similar numbers btw.