xtaci/kcp-go

Just need some help and explanation

tandem97 opened this issue · 0 comments

Hello! Here is a simple server that transfer 50MB to client. I cant understand why it takes so much time to do it. Can you recommend the optimal settings that will be reliable and fast. SetNoDelay(1, 10, 2, 1) give better performance but still takes to much time. Without SetNoDelay transfer takes about 2.5 minutes which looks like infinity. Here is my test server and client. Thank you very much for help!

package main

import (
	"fmt"
	"strings"

	"github.com/xtaci/kcp-go/v5"
)

func main() {
	listener, _ := kcp.ListenWithOptions("127.0.0.1:55200", nil, 10, 3)
	for {
		udpSession, _ := listener.AcceptKCP()
		udpSession.SetNoDelay(1, 10, 2, 1)
		writer(udpSession)
	}
}

func writer(udpSession *kcp.UDPSession) {
	data := []byte(strings.Repeat(fmt.Sprint(1), 50000000))
	for {
		udpSession.Write(append(data, []byte("\n")...))
	}
}
package main

import (
	"bufio"
	"fmt"
	"time"

	"github.com/xtaci/kcp-go/v5"
)

func main() {
	udpSession, _ := kcp.DialWithOptions("127.0.0.1:55200", nil, 10, 3)
	udpSession.SetNoDelay(1, 10, 2, 1)
	udpSession.Write([]byte{1})

	reader := bufio.NewReader(udpSession)
	now := time.Now()
	for {
		data, _ := reader.ReadBytes('\n')
		fmt.Println(time.Since(now), len(data))
		now = time.Now()
	}
}

P.S If I add SetACKNoDelay(true) performance increase, but in code it is commented as for testing purpose. Is transfer still reliable with this option