Browse Source
add tcp read
add tcp read
Performance not so good. Could need some optimization. Concurrency Level: 16 Time taken for tests: 33.575 seconds Complete requests: 1048576 Failed requests: 0 Total transferred: 1106753375 bytes Requests per second: 31230.86 [#/sec] Transfer rate: 32191.03 [Kbytes/sec] vs normal http Concurrency Level: 16 Time taken for tests: 24.829 seconds Complete requests: 1048576 Failed requests: 0 Total transferred: 1106761259 bytes Requests per second: 42231.10 [#/sec] Transfer rate: 43529.78 [Kbytes/sec]tcp_read
Chris Lu
5 years ago
8 changed files with 650 additions and 280 deletions
-
47weed/command/benchmark.go
-
1weed/command/server.go
-
32weed/command/volume.go
-
73weed/operation/grpc_client.go
-
4weed/pb/volume_server.proto
-
567weed/pb/volume_server_pb/volume_server.pb.go
-
150weed/server/volume_tcp_file.go
-
56weed/util/http_util.go
567
weed/pb/volume_server_pb/volume_server.pb.go
File diff suppressed because it is too large
View File
File diff suppressed because it is too large
View File
@ -0,0 +1,150 @@ |
|||
package weed_server |
|||
|
|||
import ( |
|||
"context" |
|||
"encoding/json" |
|||
"fmt" |
|||
"net" |
|||
"net/http" |
|||
"strings" |
|||
|
|||
"github.com/chrislusf/seaweedfs/weed/glog" |
|||
"github.com/chrislusf/seaweedfs/weed/pb/volume_server_pb" |
|||
"github.com/chrislusf/seaweedfs/weed/storage/needle" |
|||
"github.com/chrislusf/seaweedfs/weed/util" |
|||
) |
|||
|
|||
func (vs *VolumeServer) HandleTcpConnection(conn net.Conn) error { |
|||
|
|||
// println("handle tcp conn", conn.RemoteAddr())
|
|||
tcpMessage := &volume_server_pb.TcpRequestHeader{} |
|||
if err := util.ReadMessage(conn, tcpMessage); err != nil { |
|||
return fmt.Errorf("read message: %v", err) |
|||
} |
|||
|
|||
if tcpMessage.Get != nil { |
|||
vs.handleFileGet(conn, tcpMessage.Get) |
|||
} |
|||
|
|||
err := util.WriteMessageEOF(conn) |
|||
// println("processed", tcpMessage.Get.FileId)
|
|||
return err |
|||
} |
|||
|
|||
func (vs *VolumeServer) handleFileGet(conn net.Conn, req *volume_server_pb.FileGetRequest) error { |
|||
|
|||
headResponse := &volume_server_pb.FileGetResponse{} |
|||
n := new(needle.Needle) |
|||
|
|||
commaIndex := strings.LastIndex(req.FileId, ",") |
|||
vid := req.FileId[:commaIndex] |
|||
fid := req.FileId[commaIndex+1:] |
|||
|
|||
volumeId, err := needle.NewVolumeId(vid) |
|||
if err != nil { |
|||
headResponse.ErrorCode = http.StatusBadRequest |
|||
return util.WriteMessage(conn, headResponse) |
|||
} |
|||
err = n.ParsePath(fid) |
|||
if err != nil { |
|||
headResponse.ErrorCode = http.StatusBadRequest |
|||
return util.WriteMessage(conn, headResponse) |
|||
} |
|||
|
|||
hasVolume := vs.store.HasVolume(volumeId) |
|||
_, hasEcVolume := vs.store.FindEcVolume(volumeId) |
|||
|
|||
if !hasVolume && !hasEcVolume { |
|||
headResponse.ErrorCode = http.StatusMovedPermanently |
|||
return util.WriteMessage(conn, headResponse) |
|||
} |
|||
|
|||
cookie := n.Cookie |
|||
var count int |
|||
if hasVolume { |
|||
count, err = vs.store.ReadVolumeNeedle(volumeId, n) |
|||
} else if hasEcVolume { |
|||
count, err = vs.store.ReadEcShardNeedle(context.Background(), volumeId, n) |
|||
} |
|||
|
|||
if err != nil || count < 0 { |
|||
headResponse.ErrorCode = http.StatusNotFound |
|||
return util.WriteMessage(conn, headResponse) |
|||
} |
|||
if n.Cookie != cookie { |
|||
headResponse.ErrorCode = http.StatusNotFound |
|||
return util.WriteMessage(conn, headResponse) |
|||
} |
|||
|
|||
if n.LastModified != 0 { |
|||
headResponse.LastModified = n.LastModified |
|||
} |
|||
|
|||
headResponse.Etag = n.Etag() |
|||
|
|||
if n.HasPairs() { |
|||
pairMap := make(map[string]string) |
|||
err = json.Unmarshal(n.Pairs, &pairMap) |
|||
if err != nil { |
|||
glog.V(0).Infoln("Unmarshal pairs error:", err) |
|||
} |
|||
headResponse.Headers = pairMap |
|||
} |
|||
|
|||
/* |
|||
// skip this, no redirection
|
|||
if vs.tryHandleChunkedFile(n, filename, w, r) { |
|||
return |
|||
} |
|||
*/ |
|||
|
|||
if n.NameSize > 0 { |
|||
headResponse.Filename = string(n.Name) |
|||
} |
|||
mtype := "" |
|||
if n.MimeSize > 0 { |
|||
mt := string(n.Mime) |
|||
if !strings.HasPrefix(mt, "application/octet-stream") { |
|||
mtype = mt |
|||
} |
|||
} |
|||
headResponse.ContentType = mtype |
|||
|
|||
headResponse.IsGzipped = n.IsGzipped() |
|||
|
|||
if n.IsGzipped() && req.AcceptGzip { |
|||
if n.Data, err = util.UnGzipData(n.Data); err != nil { |
|||
glog.V(0).Infof("ungzip %s error: %v", req.FileId, err) |
|||
} |
|||
} |
|||
|
|||
headResponse.ContentLength = uint32(len(n.Data)) |
|||
bytesToRead := len(n.Data) |
|||
bytesRead := 0 |
|||
|
|||
t := headResponse |
|||
|
|||
for bytesRead < bytesToRead { |
|||
|
|||
stopIndex := bytesRead + BufferSizeLimit |
|||
if stopIndex > bytesToRead { |
|||
stopIndex = bytesToRead |
|||
} |
|||
|
|||
if t == nil { |
|||
t = &volume_server_pb.FileGetResponse{} |
|||
} |
|||
t.Data = n.Data[bytesRead:stopIndex] |
|||
|
|||
err = util.WriteMessage(conn, t) |
|||
t = nil |
|||
if err != nil { |
|||
return err |
|||
} |
|||
|
|||
bytesRead = stopIndex |
|||
} |
|||
|
|||
return nil |
|||
|
|||
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue