Remove worker pool.
Signed-off-by: Antonio Navarro Perez <antnavper@gmail.com>
This commit is contained in:
parent
40eefbf008
commit
ae4be076f9
11 changed files with 16 additions and 45 deletions
|
@ -1,6 +1,5 @@
|
||||||
GeneralChart.init();
|
GeneralChart.init();
|
||||||
var cacheChart = new SingleBarChart("chart-cache", "Cache disk");
|
var cacheChart = new SingleBarChart("chart-cache", "Cache disk");
|
||||||
var workerChart = new SingleBarChart("chart-workers", "Workers");
|
|
||||||
|
|
||||||
fetchData();
|
fetchData();
|
||||||
setInterval(function () {
|
setInterval(function () {
|
||||||
|
@ -22,7 +21,6 @@ function fetchData() {
|
||||||
GeneralChart.update(download, upload);
|
GeneralChart.update(download, upload);
|
||||||
|
|
||||||
cacheChart.update(stats.cacheFilled, stats.cacheCapacity - stats.cacheFilled);
|
cacheChart.update(stats.cacheFilled, stats.cacheCapacity - stats.cacheFilled);
|
||||||
workerChart.update(0, stats.poolFree - stats.poolCap);
|
|
||||||
document.getElementById("down-speed-text").innerText =
|
document.getElementById("down-speed-text").innerText =
|
||||||
Humanize.bytes(download, 1024) + "/s";
|
Humanize.bytes(download, 1024) + "/s";
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,7 @@ function SingleBarChart(id, name) {
|
||||||
this._used = [];
|
this._used = [];
|
||||||
this._free = [];
|
this._free = [];
|
||||||
this._chart = new Chart(ctx, {
|
this._chart = new Chart(ctx, {
|
||||||
type: 'bar',
|
type: 'horizontalBar',
|
||||||
data: {
|
data: {
|
||||||
labels:[name],
|
labels:[name],
|
||||||
datasets: [{
|
datasets: [{
|
||||||
|
|
|
@ -19,7 +19,6 @@ import (
|
||||||
"github.com/gin-contrib/static"
|
"github.com/gin-contrib/static"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
"github.com/goccy/go-yaml"
|
"github.com/goccy/go-yaml"
|
||||||
"github.com/panjf2000/ants/v2"
|
|
||||||
"github.com/shurcooL/httpfs/html/vfstemplate"
|
"github.com/shurcooL/httpfs/html/vfstemplate"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -67,13 +66,8 @@ func main() {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
pool, err := ants.NewPool(100)
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
ss := stats.NewTorrent()
|
ss := stats.NewTorrent()
|
||||||
mountService := mount.NewHandler(c, pool, ss)
|
mountService := mount.NewHandler(c, ss)
|
||||||
|
|
||||||
sigChan := make(chan os.Signal)
|
sigChan := make(chan os.Signal)
|
||||||
signal.Notify(sigChan, os.Interrupt, syscall.SIGTERM)
|
signal.Notify(sigChan, os.Interrupt, syscall.SIGTERM)
|
||||||
|
@ -82,8 +76,6 @@ func main() {
|
||||||
<-sigChan
|
<-sigChan
|
||||||
log.Println("Closing torrent client...")
|
log.Println("Closing torrent client...")
|
||||||
c.Close()
|
c.Close()
|
||||||
log.Println("Releasing execution pool...")
|
|
||||||
pool.Release()
|
|
||||||
log.Println("Unmounting fuse filesystem...")
|
log.Println("Unmounting fuse filesystem...")
|
||||||
mountService.Close()
|
mountService.Close()
|
||||||
|
|
||||||
|
@ -123,8 +115,6 @@ func main() {
|
||||||
"cacheItems": fc.Info().NumItems,
|
"cacheItems": fc.Info().NumItems,
|
||||||
"cacheFilled": fc.Info().Filled / 1024 / 1024,
|
"cacheFilled": fc.Info().Filled / 1024 / 1024,
|
||||||
"cacheCapacity": fc.Info().Capacity / 1024 / 1024,
|
"cacheCapacity": fc.Info().Capacity / 1024 / 1024,
|
||||||
"poolCap": pool.Cap(),
|
|
||||||
"poolFree": pool.Free(),
|
|
||||||
"torrentStats": ss.GlobalStats(),
|
"torrentStats": ss.GlobalStats(),
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
|
@ -23,7 +23,6 @@ require (
|
||||||
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
|
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
|
||||||
github.com/modern-go/reflect2 v1.0.1 // indirect
|
github.com/modern-go/reflect2 v1.0.1 // indirect
|
||||||
github.com/mschoch/smat v0.2.0 // indirect
|
github.com/mschoch/smat v0.2.0 // indirect
|
||||||
github.com/panjf2000/ants/v2 v2.3.1
|
|
||||||
github.com/shurcooL/httpfs v0.0.0-20190707220628-8d4bc4ba7749
|
github.com/shurcooL/httpfs v0.0.0-20190707220628-8d4bc4ba7749
|
||||||
github.com/stretchr/testify v1.4.0
|
github.com/stretchr/testify v1.4.0
|
||||||
github.com/tinylib/msgp v1.1.2 // indirect
|
github.com/tinylib/msgp v1.1.2 // indirect
|
||||||
|
|
|
@ -287,8 +287,6 @@ github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+W
|
||||||
github.com/onsi/ginkgo v1.7.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
|
github.com/onsi/ginkgo v1.7.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
|
||||||
github.com/onsi/gomega v1.4.3/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY=
|
github.com/onsi/gomega v1.4.3/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY=
|
||||||
github.com/openzipkin/zipkin-go v0.1.6/go.mod h1:QgAqvLzwWbR/WpD4A3cGpPtJrZXNIiJc5AZX7/PBEpw=
|
github.com/openzipkin/zipkin-go v0.1.6/go.mod h1:QgAqvLzwWbR/WpD4A3cGpPtJrZXNIiJc5AZX7/PBEpw=
|
||||||
github.com/panjf2000/ants/v2 v2.3.1 h1:9iOZHO5XlSO1Gs5K7x06uDFy8bkicWlhOKGh/TufAZg=
|
|
||||||
github.com/panjf2000/ants/v2 v2.3.1/go.mod h1:LtwNaBX6OeF5qRtQlaeGndalVwJlS2ueur7uwoAHbPA=
|
|
||||||
github.com/philhofer/fwd v1.0.0 h1:UbZqGr5Y38ApvM/V/jEljVxwocdweyH+vmYvRPBnbqQ=
|
github.com/philhofer/fwd v1.0.0 h1:UbZqGr5Y38ApvM/V/jEljVxwocdweyH+vmYvRPBnbqQ=
|
||||||
github.com/philhofer/fwd v1.0.0/go.mod h1:gk3iGcWd9+svBvR0sR+KPcfE+RNWozjowpeBVG3ZVNU=
|
github.com/philhofer/fwd v1.0.0/go.mod h1:gk3iGcWd9+svBvR0sR+KPcfE+RNWozjowpeBVG3ZVNU=
|
||||||
github.com/pierrec/lz4 v2.0.5+incompatible h1:2xWsjqPFWcplujydGg4WmhC/6fZqK42wMM8aXeqhl0I=
|
github.com/pierrec/lz4 v2.0.5+incompatible h1:2xWsjqPFWcplujydGg4WmhC/6fZqK42wMM8aXeqhl0I=
|
||||||
|
|
|
@ -11,7 +11,6 @@ import (
|
||||||
"github.com/anacrolix/torrent"
|
"github.com/anacrolix/torrent"
|
||||||
"github.com/hanwen/go-fuse/v2/fs"
|
"github.com/hanwen/go-fuse/v2/fs"
|
||||||
"github.com/hanwen/go-fuse/v2/fuse"
|
"github.com/hanwen/go-fuse/v2/fuse"
|
||||||
"github.com/panjf2000/ants/v2"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type Handler struct {
|
type Handler struct {
|
||||||
|
@ -19,16 +18,14 @@ type Handler struct {
|
||||||
s *stats.Torrent
|
s *stats.Torrent
|
||||||
opts *fs.Options
|
opts *fs.Options
|
||||||
|
|
||||||
pool *ants.Pool
|
|
||||||
servers map[string]*fuse.Server
|
servers map[string]*fuse.Server
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewHandler(c *torrent.Client, pool *ants.Pool, s *stats.Torrent) *Handler {
|
func NewHandler(c *torrent.Client, s *stats.Torrent) *Handler {
|
||||||
return &Handler{
|
return &Handler{
|
||||||
c: c,
|
c: c,
|
||||||
s: s,
|
s: s,
|
||||||
opts: &fs.Options{},
|
opts: &fs.Options{},
|
||||||
pool: pool,
|
|
||||||
servers: make(map[string]*fuse.Server),
|
servers: make(map[string]*fuse.Server),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -69,7 +66,7 @@ func (s *Handler) Mount(mpc *config.MountPoint) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
node := node.NewRoot(torrents, s.pool)
|
node := node.NewRoot(torrents)
|
||||||
server, err := fs.Mount(mpc.Path, node, s.opts)
|
server, err := fs.Mount(mpc.Path, node, s.opts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
|
@ -8,7 +8,6 @@ import (
|
||||||
"github.com/anacrolix/torrent"
|
"github.com/anacrolix/torrent"
|
||||||
"github.com/hanwen/go-fuse/v2/fs"
|
"github.com/hanwen/go-fuse/v2/fs"
|
||||||
"github.com/hanwen/go-fuse/v2/fuse"
|
"github.com/hanwen/go-fuse/v2/fuse"
|
||||||
"github.com/panjf2000/ants/v2"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var _ fs.NodeOnAdder = &Root{}
|
var _ fs.NodeOnAdder = &Root{}
|
||||||
|
@ -16,23 +15,20 @@ var _ fs.NodeGetattrer = &Root{}
|
||||||
|
|
||||||
type Root struct {
|
type Root struct {
|
||||||
fs.Inode
|
fs.Inode
|
||||||
pool *ants.Pool
|
|
||||||
torrents []*torrent.Torrent
|
torrents []*torrent.Torrent
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewRoot(torrents []*torrent.Torrent, pool *ants.Pool) *Root {
|
func NewRoot(torrents []*torrent.Torrent) *Root {
|
||||||
return &Root{torrents: torrents, pool: pool}
|
return &Root{torrents: torrents}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (root *Root) OnAdd(ctx context.Context) {
|
func (root *Root) OnAdd(ctx context.Context) {
|
||||||
for _, torrent := range root.torrents {
|
for _, torrent := range root.torrents {
|
||||||
root.pool.Submit(func() {
|
|
||||||
root.AddChild(
|
root.AddChild(
|
||||||
filepath.Clean(torrent.Name()),
|
filepath.Clean(torrent.Name()),
|
||||||
root.NewPersistentInode(ctx, &Torrent{t: torrent, pool: root.pool}, fs.StableAttr{
|
root.NewPersistentInode(ctx, &Torrent{t: torrent}, fs.StableAttr{
|
||||||
Mode: syscall.S_IFDIR,
|
Mode: syscall.S_IFDIR,
|
||||||
}), true)
|
}), true)
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -9,7 +9,6 @@ import (
|
||||||
"github.com/anacrolix/torrent"
|
"github.com/anacrolix/torrent"
|
||||||
"github.com/hanwen/go-fuse/v2/fs"
|
"github.com/hanwen/go-fuse/v2/fs"
|
||||||
"github.com/hanwen/go-fuse/v2/fuse"
|
"github.com/hanwen/go-fuse/v2/fuse"
|
||||||
"github.com/panjf2000/ants/v2"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var _ fs.NodeOnAdder = &Torrent{}
|
var _ fs.NodeOnAdder = &Torrent{}
|
||||||
|
@ -18,8 +17,6 @@ var _ fs.NodeGetattrer = &Torrent{}
|
||||||
type Torrent struct {
|
type Torrent struct {
|
||||||
fs.Inode
|
fs.Inode
|
||||||
t *torrent.Torrent
|
t *torrent.Torrent
|
||||||
|
|
||||||
pool *ants.Pool
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (folder *Torrent) OnAdd(ctx context.Context) {
|
func (folder *Torrent) OnAdd(ctx context.Context) {
|
||||||
|
@ -27,7 +24,6 @@ func (folder *Torrent) OnAdd(ctx context.Context) {
|
||||||
file := file
|
file := file
|
||||||
LoadNodeByPath(
|
LoadNodeByPath(
|
||||||
ctx,
|
ctx,
|
||||||
folder.pool,
|
|
||||||
file.Path(),
|
file.Path(),
|
||||||
func() (io.ReaderAt, error) { return iio.NewReadAtWrapper(file.NewReader()), nil },
|
func() (io.ReaderAt, error) { return iio.NewReadAtWrapper(file.NewReader()), nil },
|
||||||
&folder.Inode,
|
&folder.Inode,
|
||||||
|
|
|
@ -10,12 +10,11 @@ import (
|
||||||
|
|
||||||
"github.com/hanwen/go-fuse/v2/fs"
|
"github.com/hanwen/go-fuse/v2/fs"
|
||||||
"github.com/hanwen/go-fuse/v2/fuse"
|
"github.com/hanwen/go-fuse/v2/fuse"
|
||||||
"github.com/panjf2000/ants/v2"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type ReaderFunc func() (io.ReaderAt, error)
|
type ReaderFunc func() (io.ReaderAt, error)
|
||||||
|
|
||||||
func LoadNodeByPath(ctx context.Context, pool *ants.Pool, fp string, reader ReaderFunc, parent *fs.Inode, fileLength int64, pieceLen int32, numPieces int64) {
|
func LoadNodeByPath(ctx context.Context, fp string, reader ReaderFunc, parent *fs.Inode, fileLength int64, pieceLen int32, numPieces int64) {
|
||||||
p := parent
|
p := parent
|
||||||
dir, base := filepath.Split(filepath.Clean(fp))
|
dir, base := filepath.Split(filepath.Clean(fp))
|
||||||
for i, component := range strings.Split(dir, "/") {
|
for i, component := range strings.Split(dir, "/") {
|
||||||
|
|
|
@ -50,7 +50,6 @@ func (z *Zip) Opendir(ctx context.Context) syscall.Errno {
|
||||||
}
|
}
|
||||||
LoadNodeByPath(
|
LoadNodeByPath(
|
||||||
ctx,
|
ctx,
|
||||||
nil,
|
|
||||||
f.Name,
|
f.Name,
|
||||||
func() (io.ReaderAt, error) {
|
func() (io.ReaderAt, error) {
|
||||||
zfr, err := f.Open()
|
zfr, err := f.Open()
|
||||||
|
|
|
@ -10,13 +10,15 @@
|
||||||
<div class="container">
|
<div class="container">
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col">
|
<div class="col">
|
||||||
<canvas id="chart-general-network"></canvas>
|
<canvas id="chart-general-network" height="150"></canvas>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-sm">
|
<div class="col-sm">
|
||||||
<canvas id="chart-cache" height="400"></canvas>
|
<canvas id="chart-cache" height="20"></canvas>
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="row">
|
||||||
<div class="col-sm">
|
<div class="col-sm">
|
||||||
<h3>
|
<h3>
|
||||||
<svg class="bi bi-arrow-down" width="1em" height="1em" viewBox="0 0 16 16" fill="currentColor"
|
<svg class="bi bi-arrow-down" width="1em" height="1em" viewBox="0 0 16 16" fill="currentColor"
|
||||||
|
@ -43,9 +45,6 @@
|
||||||
<span id="up-speed-text"></span>
|
<span id="up-speed-text"></span>
|
||||||
</h3>
|
</h3>
|
||||||
</div>
|
</div>
|
||||||
<div class="col-sm">
|
|
||||||
<canvas id="chart-workers" height="400"></canvas>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{{template "common_footer.html"}}
|
{{template "common_footer.html"}}
|
||||||
|
|
Loading…
Reference in a new issue