Browse Source

testing udp

This reverts commit 69694a17be.
test_udp
Chris Lu 4 years ago
parent
commit
c012902c16
  1. 11
      weed/command/volume.go
  2. 4
      weed/server/volume_server_udp_handlers.go
  3. 1048
      weed/wdclient/penet/penet.go
  4. 34
      weed/wdclient/volume_udp_client.go

11
weed/command/volume.go

@ -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{
LocalAddr: listeningAddress,
Bandwidth: 100,
FastRetransmit: true,
FlatTraffic: true,
IsServ: true,
})
listener, err := penet.Listen("", listeningAddress)
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

4
weed/server/volume_server_udp_handlers.go

@ -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
File diff suppressed because it is too large
View File

34
weed/wdclient/volume_udp_client.go

@ -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{
LocalAddr: "",
Bandwidth: 100,
FastRetransmit: true,
FlatTraffic: true,
IsServ: false,
})
if c.Conn == nil {
c.Conn, err = penet.DialTimeout("", udpAddress, 500*time.Millisecond)
if err != nil { if err != nil {
return err return err
} }
defer listener.Close()
conn, err := listener.Dial(udpAddress)
if err != nil {
return err
c.bufWriter = bufio.NewWriter(c.Conn)
} }
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
} }
Loading…
Cancel
Save