anacrolix / anacrolix/torrent

Speed too slowly if set cpu-limit for pod in Kubernetes. Or high cpu usage with cpu-nolimit.

オープン
#982 コメント 22 件 リアクション 0 件 担当者 0 名 GitHub で見る
主要言語
Go
スター
6.1k
フォーク
690
平均マージ
3日 10時間
マージ済み PR(30日)
12

説明

I want to develop a file distributor based on torrent and deploy it in a Kubernetes cluster using DaemonSet. I deployed the [chihaya/chihaya](https://github.com/chihaya/chihaya) as the tracker.

Every node i have a torrent client:
```
clientConfig := torrent.NewDefaultClientConfig()
clientConfig.DataDir = th.op.TransferPath
clientConfig.Seed = true
clientConfig.ListenPort = int(th.op.TorrentPort)
clientConfig.DefaultStorage = storage.NewFileByInfoHash(th.op.TransferPath)
clientConfig.DisableUTP = true
clientConfig.MaxUnverifiedBytes = 64 << 30
clientConfig.NoDHT = false
clientConfig.DisablePEX = false
clientConfig.EstablishedConnsPerTorrent = 200
clientConfig.HalfOpenConnsPerTorrent = 100
clientConfig.TorrentPeersHighWater = 2000
clientConfig.MaxUnverifiedBytes = 671088640
```

When i need distribute a file from one node, i'll generate the torrent first
```
pieceLength = metainfo.ChoosePieceLength(layerFileInfo.Size())
info := metainfo.Info{
PieceLength: pieceLength,
}
if err := info.BuildFromFilePath(layerFile); err != nil {
return nil, errors.Wrapf(err, "build torrent metainfo from file '%s' failed", layerFileInfo)
}
mi := metainfo.MetaInfo{
InfoBytes: bencode.MustMarshal(info),
}
ih := mi.HashInfoBytes()
to, _ := th.client.AddTorrentOpt(torrent.AddTorrentOpts{
InfoHash: ih,
Storage: storage.NewFileOpts(storage.NewFileClientOpts{
ClientBaseDir: layerFile,
FilePathMaker: func(opts storage.FilePathMakerOpts) string {
return filepath.Join(opts.File.BestPath()...)
},
TorrentDirMaker: nil,
PieceCompletion: th.pc,
}),
ChunkSize: 128 * 1024,
})
err := to.MergeSpec(&torrent.TorrentSpec{
InfoBytes: mi.InfoBytes,
Trackers: [][]string{{th.op.TorrentAnnounce}},
})
```

Then every torrent client(running in K8S pod) will start download this torrent. But the speed is too slowly, about 8-9MiB/s.
(The K8S pod is set cpu limit to 1c)

If i set cpu no-limit, the torrent client will use about 6c CPU, speed 60MiB/s. I don't know where the problem is.

**pprof file**
[cpu.pb.gz](https://github.com/user-attachments/files/17187659/cpu.pb.gz)

コントリビューションガイド

このリポジトリのコントリビューションガイドは索引されていません

評価

この issue はまだ評価されていません。

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。