aboutsummaryrefslogtreecommitdiff
path: root/weed/command/filer.go
diff options
context:
space:
mode:
authorchrislu <chris.lu@gmail.com>2022-03-07 02:00:14 -0800
committerchrislu <chris.lu@gmail.com>2022-03-07 02:00:14 -0800
commitda3d330616663e1c843514bd7a7a2c1833bf42d1 (patch)
tree8bb184b6a49b099876f1856f68c21db594ff62cc /weed/command/filer.go
parent0cb17b45b108340033de06d71cf2fc1b891c3be8 (diff)
downloadseaweedfs-da3d330616663e1c843514bd7a7a2c1833bf42d1.tar.xz
seaweedfs-da3d330616663e1c843514bd7a7a2c1833bf42d1.zip
s3 and filer transport using unix domain socket instead of tcp
Diffstat (limited to 'weed/command/filer.go')
-rw-r--r--weed/command/filer.go21
1 files changed, 21 insertions, 0 deletions
diff --git a/weed/command/filer.go b/weed/command/filer.go
index f886f1258..07fedd72d 100644
--- a/weed/command/filer.go
+++ b/weed/command/filer.go
@@ -2,6 +2,7 @@ package command
import (
"fmt"
+ "net"
"net/http"
"os"
"time"
@@ -51,6 +52,7 @@ type FilerOptions struct {
concurrentUploadLimitMB *int
debug *bool
debugPort *int
+ localSocket *string
}
func init() {
@@ -76,6 +78,7 @@ func init() {
f.concurrentUploadLimitMB = cmdFiler.Flag.Int("concurrentUploadLimitMB", 128, "limit total concurrent upload size")
f.debug = cmdFiler.Flag.Bool("debug", false, "serves runtime profiling data, e.g., http://localhost:<debug.port>/debug/pprof/goroutine?debug=2")
f.debugPort = cmdFiler.Flag.Int("debug.port", 6060, "http port for debugging")
+ f.localSocket = cmdFiler.Flag.String("localSocket", "", "default to /tmp/seaweedfs-filer-<port>.sock")
// start s3 on filer
filerStartS3 = cmdFiler.Flag.Bool("s3", false, "whether to start S3 gateway")
@@ -139,11 +142,14 @@ func runFiler(cmd *Command, args []string) bool {
if *filerStartS3 {
filerS3Options.filer = &filerAddress
filerS3Options.bindIp = f.bindIp
+ filerS3Options.localFilerSocket = f.localSocket
go func() {
time.Sleep(startDelay * time.Second)
filerS3Options.startS3Server()
}()
startDelay++
+ } else {
+ f.localSocket = nil
}
if *filerStartWebDav {
@@ -230,6 +236,18 @@ func (fo *FilerOptions) startFiler() {
glog.Fatalf("Filer listener error: %v", e)
}
+ // start on local unix socket
+ if *fo.localSocket == "" {
+ *fo.localSocket = fmt.Sprintf("/tmp/seaweefs-filer-%d.sock", *fo.port)
+ if err := os.Remove(*fo.localSocket); err != nil && !os.IsNotExist(err) {
+ glog.Fatalf("Failed to remove %s, error: %s", *fo.localSocket, err.Error())
+ }
+ }
+ filerSocketListener, err := net.Listen("unix", *fo.localSocket)
+ if err != nil {
+ glog.Fatalf("Failed to listen on %s: %v", *fo.localSocket, err)
+ }
+
// starting grpc server
grpcPort := *fo.portGrpc
grpcL, err := util.NewListener(util.JoinHostPort(*fo.bindIp, grpcPort), 0)
@@ -242,6 +260,9 @@ func (fo *FilerOptions) startFiler() {
go grpcS.Serve(grpcL)
httpS := &http.Server{Handler: defaultMux}
+ go func() {
+ httpS.Serve(filerSocketListener)
+ }()
if err := httpS.Serve(filerListener); err != nil {
glog.Fatalf("Filer Fail to serve: %v", e)
}