Skip to content

Commit 5bd435c

Browse files
authored
extracted socketbuffer to external repo (#7)
* extracted socketbuffer to external repo * multiple bw limiter goroutines
1 parent 98a1b2b commit 5bd435c

12 files changed

Lines changed: 15 additions & 513 deletions

File tree

go.mod

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ go 1.19
44

55
require (
66
github.com/BurntSushi/toml v1.2.0
7+
github.com/danlapid/socketbuffer v1.0.0
78
github.com/klauspost/reedsolomon v1.10.0
89
github.com/rjeczalik/notify v0.9.3-0.20210809113154-3472d85e95cd
910
github.com/sirupsen/logrus v1.9.0
1011
github.com/yeka/zip v0.0.0-20180914125537-d046722c6feb
1112
github.com/zhuangsirui/binpacker v2.0.0+incompatible
12-
golang.org/x/sys v0.0.0-20220829200755-d48e67d00261
1313
golang.org/x/time v0.0.0-20220722155302-e5dcc9cfc0b9
1414
gorm.io/driver/sqlite v1.3.6
1515
gorm.io/gorm v1.23.8
@@ -21,4 +21,5 @@ require (
2121
github.com/klauspost/cpuid/v2 v2.0.14 // indirect
2222
github.com/mattn/go-sqlite3 v1.14.12 // indirect
2323
golang.org/x/crypto v0.0.0-20220829220503-c86fa9a7ed90 // indirect
24+
golang.org/x/sys v0.0.0-20220829200755-d48e67d00261 // indirect
2425
)

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
github.com/BurntSushi/toml v1.2.0 h1:Rt8g24XnyGTyglgET/PRUNlrUeu9F5L+7FilkXfZgs0=
22
github.com/BurntSushi/toml v1.2.0/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ=
3+
github.com/danlapid/socketbuffer v1.0.0 h1:jBfA6Sj14bWR809AeTX+Wy5ADoMO3qP7n8bM0HgxjdQ=
4+
github.com/danlapid/socketbuffer v1.0.0/go.mod h1:iCIDUm7ZqwK7XTCkJuybROMERiL/XmuSs9KtaR9IjfY=
35
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
46
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
57
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
@@ -16,8 +18,6 @@ github.com/mattn/go-sqlite3 v1.14.12 h1:TJ1bhYJPV44phC+IMu1u2K/i5RriLTPe+yc68XDJ
1618
github.com/mattn/go-sqlite3 v1.14.12/go.mod h1:NyWgC/yNuGj7Q9rpYnZvas74GogHl5/Z4A/KQRfk6bU=
1719
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
1820
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
19-
github.com/rjeczalik/notify v0.9.2 h1:MiTWrPj55mNDHEiIX5YUSKefw/+lCQVoAFmD6oQm5w8=
20-
github.com/rjeczalik/notify v0.9.2/go.mod h1:aErll2f0sUX9PXZnVNyeiObbmTlk5jnMoCa4QEjJeqM=
2121
github.com/rjeczalik/notify v0.9.3-0.20210809113154-3472d85e95cd h1:LHLg0gdpRUCvujg2Zol6e2Uknq5vHycLxqEzYwxt1vY=
2222
github.com/rjeczalik/notify v0.9.3-0.20210809113154-3472d85e95cd/go.mod h1:gF3zSOrafR9DQEWSE8TjfI9NkooDxbyT4UgRGKZA0lc=
2323
github.com/sirupsen/logrus v1.9.0 h1:trlNQbNUG3OdDrDil03MCb1H2o9nJ1x4/5LYw7byDE0=

pkg/bandwidthlimiter/bandwidthlimiter.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,13 @@ func worker(ctx context.Context, conf *bandwidthLimiterConfig) {
2929
}
3030
}
3131

32-
func CreateBandwidthLimiter(ctx context.Context, bandwidth int, chunksize int, input chan *structs.Chunk, output chan *structs.Chunk) {
32+
func CreateBandwidthLimiter(ctx context.Context, bandwidth int, chunksize int, input chan *structs.Chunk, output chan *structs.Chunk, workercount int) {
3333
conf := bandwidthLimiterConfig{
3434
rl: rate.NewLimiter(rate.Limit(bandwidth), chunksize),
3535
input: input,
3636
output: output,
3737
}
38-
go worker(ctx, &conf)
38+
for i := 0; i < workercount; i++ {
39+
go worker(ctx, &conf)
40+
}
3941
}

pkg/bandwidthlimiter/bandwidthlimiter_test.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"context"
55
"oneway-filesync/pkg/bandwidthlimiter"
66
"oneway-filesync/pkg/structs"
7+
"runtime"
78
"testing"
89
"time"
910
)
@@ -34,7 +35,8 @@ func TestCreateBandwidthLimiter(t *testing.T) {
3435

3536
ctx, cancel := context.WithCancel(context.Background())
3637
start := time.Now()
37-
bandwidthlimiter.CreateBandwidthLimiter(ctx, tt.args.bytes_per_sec, tt.args.chunk_size, ch_in, ch_out)
38+
bandwidthlimiter.CreateBandwidthLimiter(ctx, tt.args.bytes_per_sec, tt.args.chunk_size, ch_in, ch_out, runtime.GOMAXPROCS(0)*2)
39+
3840
for i := 0; i < tt.args.chunk_count; i++ {
3941
<-ch_out
4042
}

pkg/sender/sender.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,6 @@ func Sender(ctx context.Context, db *gorm.DB, conf config.Config) {
2525
queuereader.CreateQueueReader(ctx, db, queue_chan)
2626
filereader.CreateFileReader(ctx, db, conf.ChunkSize, conf.ChunkFecRequired, queue_chan, chunks_chan, maxprocs)
2727
fecencoder.CreateFecEncoder(ctx, conf.ChunkSize, conf.ChunkFecRequired, conf.ChunkFecTotal, chunks_chan, shares_chan, maxprocs)
28-
bandwidthlimiter.CreateBandwidthLimiter(ctx, conf.BandwidthLimit, conf.ChunkSize, shares_chan, bw_limited_chunks)
28+
bandwidthlimiter.CreateBandwidthLimiter(ctx, conf.BandwidthLimit, conf.ChunkSize, shares_chan, bw_limited_chunks, maxprocs)
2929
udpsender.CreateUdpSender(ctx, conf.ReceiverIP, conf.ReceiverPort, bw_limited_chunks, maxprocs)
3030
}

pkg/udpreceiver/udpreceiver.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ import (
55
"errors"
66
"net"
77
"oneway-filesync/pkg/structs"
8-
"oneway-filesync/pkg/utils"
98
"time"
109

10+
"github.com/danlapid/socketbuffer"
1111
"github.com/sirupsen/logrus"
1212
)
1313

@@ -24,7 +24,7 @@ func manager(ctx context.Context, conf *udpReceiverConfig) {
2424
logrus.Errorf("Error getting raw socket: %v", err)
2525
return
2626
}
27-
bufsize, err := utils.GetReadBuffer(rawconn)
27+
bufsize, err := socketbuffer.GetReadBuffer(rawconn)
2828
if err != nil {
2929
logrus.Errorf("Error getting read buffer size: %v", err)
3030
}
@@ -34,7 +34,7 @@ func manager(ctx context.Context, conf *udpReceiverConfig) {
3434
case <-ctx.Done():
3535
return
3636
case <-ticker.C:
37-
toread, err := utils.GetAvailableBytes(rawconn)
37+
toread, err := socketbuffer.GetAvailableBytes(rawconn)
3838
if err != nil {
3939
logrus.Errorf("Error getting available bytes on socket: %v", err)
4040
}

pkg/utils/darwin_ioctl.go

Lines changed: 0 additions & 26 deletions
This file was deleted.

pkg/utils/linux_ioctl.go

Lines changed: 0 additions & 51 deletions
This file was deleted.

pkg/utils/linux_procudp.go

Lines changed: 0 additions & 201 deletions
This file was deleted.

0 commit comments

Comments
 (0)