> ok
github.com/calmh/dst <
http://github.com/calmh/dst> 9.054s
>
> (go version go1.3.3 darwin/amd64)
>
> It's obvious that my stuff is *much* worse than TCP, but then not *that*
> much worse when comparing to raw UDP. And reading seems not to be the
> issue; just pumping packets at lo0 in a tight loop is equally slow. A
> part of the problem seems to be whatever WriteTo() does in addition to
> Write() (resolving the address somehow?), but even Write() is a
> magnitude slower than TCP.
>
> Is this as designed, or expected because of some property of sending UDP
> that I don't understand, or not expected at all and I've screwed
> something up in my tests?
>
> (As an aside on "-cpu 4", the UDP tests fail without it because I'm not
> handling retransmissions and it seems to overrun the read/write buffers
> before context switching goroutines on a single core. TCP is almost
> twice as fast with the default of one core...)
>
> The benchmark code is
> in
https://github.com/calmh/dst/blob/master/benchmark_test.go - the rest
> of the DST code in the same repo, in full-hacking-proof-of-concept mode
> for the interested veiwer, but just sorting out my UDP writes first
> would be nice. :)
>
> //jb
I tried this on linux and I didn't get the test to work once.
BenchmarkUDP-4 2014/11/07 14:18:50 Received 198457 packets out of
200000; 0.8% loss
--- FAIL: BenchmarkUDP-4
udp_test.go:49: read udp: i/o timeout
ok _/home/ncw/udptest 3.096s
That indicates about 89 MB/s if it was working.
The fact that lots of packets go missing indicates to me that this isn't
a good test. It is the usual problems with UDP and no flow control.
Adding a bit of flow control like this
@@ -15,8 +26,11 @@
src := make([]byte, 1472)
io.ReadFull(rand.Reader, src)
+ flow := make(chan struct{}, 16)
+
go func(n int) {
for i := 0; i < n; i++ {
+ flow <- struct{}{}
_, err := bConn.WriteTo(src, aAddr)
if err != nil {
b.Fatal(err)
@@ -32,6 +46,7 @@
if i%1000 == 0 {
aConn.SetReadDeadline(time.Now().Add(1 * time.Second))
}
+ <-flow
n, err := aConn.Read(buf)
if err != nil {
log.Printf("Received %d packets out of %d; %.1f%% loss", i, b.N,
100-float64(i*100)/float64(b.N))
Makes the test run reliably at 120 -150 MB/s
--
Nick Craig-Wood <
ni...@craig-wood.com> --
http://www.craig-wood.com/nick