UDP Rate
UDP Rate
- Subject: UDP Rate
- From: Zack Morris <email@hidden>
- Date: Sat, 21 Feb 2004 00:48:40 -0700
Hi, I have written a reliable UDP protocol for our games that uses
windowing, resending, ignoring duplicate packets, etc. It's easily the most
hellish thing I've ever written, I highly recommend against anybody doing
it, it was harder than opengl, sound double buffering, anything :) Anyway,
it all works, but I am getting some weird numbers for the throughput. Here
they are, at a 90% packet success rate:
512 bytes+header sized packets:
100bt ethernet:
#packets in window->speed: 16->350k/s, 32->550k/s, 64->750k/s, 128->850k/s
Airport:
#packets in window->speed: 8->110k/sec, 16->80k/s
localhost:
#packets in window->speed: 16->410k/sec, 128->460k/s no loss rate
8192 header+header sized packets:
100bt ethernet:
#packets in window->speed: 8->1.2M/s, 16->1.35M/s
Airport:
#packets in window->speed: 4->135k/s behavior erratic
localhost:
#packets in window->speed: 8->1.1k/sec at 95%, 16->320k/s at 50% success
Does anyone know why airport is so slow? Are the packets just
inherently unreliable over radio? Airport should be getting more like
1MB/sec.
Also, is there some setting, like only let 10% of a LAN's traffic be UDP
packets? These numbers all seem very low to me, certainly lower than the
theoretical ~10MB/sec for ethernet and who knows how high for localhost.
I also noticed that the program is extremely sensitive to things like
GetNextEvent() and printing to the console. If I do that very much at all,
the profiler shows an obscene amount going to the GUI. For instance,
running the program localhost only runs half as fast as running on LAN
because it draws twice as many lines to the screen, even though I am only
writing a line every 100k! (send+receive, see?)
FYI I am using nonblocking sockets with an Idle() routine I call as fast
as the computer can run with GetNextEvent(). I limit it with a timer that
only allows Idle() to execute 100 times per sec, otherwise it returns.
Anyway, my send and receive loops seem to run ~50 times per sec because of
missing the heartbeat/main loop stutter, which is perfect for my needs. I
am going to use 512 byte packets with a window size of 16 packets, with a
min window send interval of 10ms (normally averages 100ms tho). So that is
512x16x100 = 819200 bytes/sec. I never see anywhere near this, I can only
get to 350 k/sec with 512 byte packets.
Here are some specific questions, maybe the gurus can answer at their
leisure:
1. Is the sockets stack 64k? I can only seem to send about 500k/sec (512
bytes times 128 length window = 64k) about 8x a sec and get no loss rate.
Same for 8192x8=64k at about 16x a sec. Is this why localhost is slower
than network, I am running out of memory? Or is there something inherently
slow with calling sendto() and recvmsg()?
2. Is the udp mtu in OS X 8192 bytes? I can't seem to send 16384 byte
packets, or even 16000 bytes. And I thought the mtu for ethernet was 64k.
3. If the packet send success goes over 90% I turn up the speed, if it goes
below 75%, I turn it down. Are these reasonable numbers? I am afraid maybe
modems never go above 80% for instance.
4. Is there any benefit to threaded sockets? I am going to be calling
Idle() at least 30 fps in my game's loop, so I can't see how it would go
faster. I was thinking of making a thread with select() that only runs when
data comes in, or I would signal the thread to run by sending data to it on
a local socket (is this a pipe???). My code is about 90% interrupt safe, as
I was writing it to run on 9 too, but if I can avoid threads/interrupts,
that would be great as they are an evil icky can of disgusting worms.
5. Are my numbers even close to right? Have any of you programmed a UDP
game before? Is UDP just for signalling or something? My bandwidth should
be 10 times higher than it is, and I don't know if my main loop just isn't
running fast enough, or if the OS/network is limiting me. Okay I have
infinite questions so I will stop now.
Thanx for any help,
----------------------------------------------------------------------------
Zack Morris Z Sculpt Entertainment This Space
email@hidden
http://www.zsculpt.com For Rent
----------------------------------------------------------------------------
If the doors of perception were cleansed, everything would appear to man as
it is, infinite. -William Blake, The Marriage of Heaven and Hell
_______________________________________________
macnetworkprog mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/macnetworkprog
Do not post admin requests to the list. They will be ignored.