testing udp

This reverts commit 69694a17be.
This commit is contained in:
Chris Lu 2021-03-18 22:02:40 -07:00
parent 5495497876
commit c012902c16
4 changed files with 1067 additions and 36 deletions

View file

@ -3,7 +3,7 @@ package command
import ( import (
"fmt" "fmt"
"github.com/chrislusf/seaweedfs/weed/storage/types" "github.com/chrislusf/seaweedfs/weed/storage/types"
"github.com/chrislusf/seaweedfs/weed/udptransfer" "github.com/chrislusf/seaweedfs/weed/wdclient/penet"
"net" "net"
"net/http" "net/http"
httppprof "net/http/pprof" httppprof "net/http/pprof"
@ -401,13 +401,7 @@ func (v VolumeServerOptions) startTcpService(volumeServer *weed_server.VolumeSer
func (v VolumeServerOptions) startUdpService(volumeServer *weed_server.VolumeServer) { func (v VolumeServerOptions) startUdpService(volumeServer *weed_server.VolumeServer) {
listeningAddress := *v.bindIp + ":" + strconv.Itoa(*v.port+20001) listeningAddress := *v.bindIp + ":" + strconv.Itoa(*v.port+20001)
listener, err := udptransfer.NewEndpoint(&udptransfer.Params{ listener, err := penet.Listen("", listeningAddress)
LocalAddr: listeningAddress,
Bandwidth: 100,
FastRetransmit: true,
FlatTraffic: true,
IsServ: true,
})
if err != nil { if err != nil {
glog.Fatalf("Volume server listen on %s:%v", listeningAddress, err) glog.Fatalf("Volume server listen on %s:%v", listeningAddress, err)
} }
@ -416,7 +410,6 @@ func (v VolumeServerOptions) startUdpService(volumeServer *weed_server.VolumeSer
for { for {
conn, err := listener.Accept() conn, err := listener.Accept()
if err == nil { if err == nil {
glog.V(0).Infof("Client from %s", conn.RemoteAddr())
go volumeServer.HandleUdpConnection(conn) go volumeServer.HandleUdpConnection(conn)
} else if isTemporaryError(err) { } else if isTemporaryError(err) {
continue continue

View file

@ -10,8 +10,6 @@ import (
func (vs *VolumeServer) HandleUdpConnection(c net.Conn) { func (vs *VolumeServer) HandleUdpConnection(c net.Conn) {
defer c.Close() defer c.Close()
glog.V(0).Infof("Serving writes from %s", c.RemoteAddr().String())
bufReader := bufio.NewReaderSize(c, 1024*1024) bufReader := bufio.NewReaderSize(c, 1024*1024)
bufWriter := bufio.NewWriterSize(c, 1024*1024) bufWriter := bufio.NewWriterSize(c, 1024*1024)
@ -19,7 +17,7 @@ func (vs *VolumeServer) HandleUdpConnection(c net.Conn) {
cmd, err := bufReader.ReadString('\n') cmd, err := bufReader.ReadString('\n')
if err != nil { if err != nil {
if err != io.EOF { if err != io.EOF {
glog.Errorf("read command from %s: %v", c.RemoteAddr().String(), err) // glog.Errorf("read command from: %v", err)
} }
return return
} }

1048
weed/wdclient/penet/penet.go Normal file

File diff suppressed because it is too large Load diff

View file

@ -3,18 +3,22 @@ package wdclient
import ( import (
"bufio" "bufio"
"github.com/chrislusf/seaweedfs/weed/pb" "github.com/chrislusf/seaweedfs/weed/pb"
"github.com/chrislusf/seaweedfs/weed/udptransfer"
"github.com/chrislusf/seaweedfs/weed/util" "github.com/chrislusf/seaweedfs/weed/util"
"github.com/chrislusf/seaweedfs/weed/wdclient/penet"
"io" "io"
"net" "net"
"time"
) )
// VolumeUdpClient put/get/delete file chunks directly on volume servers without replication // VolumeUdpClient put/get/delete file chunks directly on volume servers without replication
type VolumeUdpClient struct { type VolumeUdpClient struct {
Conn net.Conn
bufWriter *bufio.Writer
bufReader *bufio.Reader
} }
type VolumeUdpConn struct { type VolumeUdpConn struct {
net.Conn Conn net.Conn
bufWriter *bufio.Writer bufWriter *bufio.Writer
bufReader *bufio.Reader bufReader *bufio.Reader
} }
@ -30,41 +34,29 @@ func (c *VolumeUdpClient) PutFileChunk(volumeServerAddress string, fileId string
return parseErr return parseErr
} }
listener, err := udptransfer.NewEndpoint(&udptransfer.Params{ if c.Conn == nil {
LocalAddr: "", c.Conn, err = penet.DialTimeout("", udpAddress, 500*time.Millisecond)
Bandwidth: 100, if err != nil {
FastRetransmit: true, return err
FlatTraffic: true, }
IsServ: false, c.bufWriter = bufio.NewWriter(c.Conn)
})
if err != nil {
return err
} }
defer listener.Close()
conn, err := listener.Dial(udpAddress)
if err != nil {
return err
}
defer conn.Close()
bufWriter := bufio.NewWriter(conn)
buf := []byte("+" + fileId + "\n") buf := []byte("+" + fileId + "\n")
_, err = bufWriter.Write([]byte(buf)) _, err = c.bufWriter.Write([]byte(buf))
if err != nil { if err != nil {
return return
} }
util.Uint32toBytes(buf[0:4], fileSize) util.Uint32toBytes(buf[0:4], fileSize)
_, err = bufWriter.Write(buf[0:4]) _, err = c.bufWriter.Write(buf[0:4])
if err != nil { if err != nil {
return return
} }
_, err = io.Copy(bufWriter, fileReader) _, err = io.Copy(c.bufWriter, fileReader)
if err != nil { if err != nil {
return return
} }
bufWriter.Flush() c.bufWriter.Flush()
return nil return nil
} }