Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
penglongli opened this issue Sep 30, 2024 · 22 comments

Comments

@penglongli
Copy link

I want to develop a file distributor based on torrent and deploy it in a Kubernetes cluster using DaemonSet. I deployed the 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

@anacrolix
Copy link
Owner

To clarify, if you don't limit the CPU, it uses 600% but you get about 7x the speed than when you limit it to 100%?

@anacrolix
Copy link
Owner

You probably don't want to set some of those constants so high, particularly max unverified bytes. The request algorithm will try to read ahead much to far and expend a lot of computation excessively parallelizing downloads.

More is not better here. On resource constrained systems you actually want to lower those values.

Could you let me know how you go with mostly defaults?

@anacrolix
Copy link
Owner

The default storage implementation, file, is not very good and has very high system overhead.

If you are caching, consider possum, otherwise mmap, if you are able to control file consistency/availability.

@anacrolix
Copy link
Owner

The CPU profile you submitted makes me think that the request upload routine could do with some optimization, it probably needs to batch a bit. Otherwise it's a pretty healthy looking profile. I think you could mostly improve on that by reducing EstablishedConnsPerTorrent to maybe 25 or so.

@penglongli
Copy link
Author

penglongli commented Oct 8, 2024

@anacrolix Sorry for reply later. I changed the storage to MMAP:

clientConfig.DefaultStorage = storage.NewMMap(th.op.TransferPath)

And i set torrent to MMAP storage:

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.NewMMapWithCompletion(th.op.TransferPath, th.pc),
	ChunkSize: 128 * 1024,
})
err := to.MergeSpec(&torrent.TorrentSpec{
	InfoBytes: mi.InfoBytes,
	Trackers:  [][]string{{th.op.TorrentAnnounce}},
})

Limit 1c CPU

I1008 09:58:00.782617       1 torrent.go:384] torrent downloading(5.009006665s): 80 MB/3.1 GB: 16 MB/s, t-request=d375c2ec-1982-4c49-8a86-e82e90d5eefa, t-layer=c10c6ab20f1162764f2bcfc11ecafe890e051334318002febe51ffec5ed5346f
I1008 09:58:05.834817       1 torrent.go:384] torrent downloading(10.061184322s): 149 MB/3.1 GB: 14 MB/s, t-request=d375c2ec-1982-4c49-8a86-e82e90d5eefa, t-layer=c10c6ab20f1162764f2bcfc11ecafe890e051334318002febe51ffec5ed5346f
I1008 09:58:10.834786       1 torrent.go:384] torrent downloading(15.061166263s): 218 MB/3.1 GB: 14 MB/s, t-request=d375c2ec-1982-4c49-8a86-e82e90d5eefa, t-layer=c10c6ab20f1162764f2bcfc11ecafe890e051334318002febe51ffec5ed5346f
I1008 09:58:15.835355       1 torrent.go:384] torrent downloading(20.000431416s): 296 MB/3.1 GB: 16 MB/s, t-request=d375c2ec-1982-4c49-8a86-e82e90d5eefa, t-layer=c10c6ab20f1162764f2bcfc11ecafe890e051334318002febe51ffec5ed5346f
I1008 09:58:20.834769       1 torrent.go:384] torrent downloading(25.061156237s): 375 MB/3.1 GB: 16 MB/s, t-request=d375c2ec-1982-4c49-8a86-e82e90d5eefa, t-layer=c10c6ab20f1162764f2bcfc11ecafe890e051334318002febe51ffec5ed5346f
I1008 09:58:25.773732       1 torrent.go:384] torrent downloading(30.00012001s): 453 MB/3.1 GB: 16 MB/s, t-request=d375c2ec-1982-4c49-8a86-e82e90d5eefa, t-layer=c10c6ab20f1162764f2bcfc11ecafe890e051334318002febe51ffec5ed5346f
I1008 09:58:30.773710       1 torrent.go:384] torrent downloading(35.000097606s): 514 MB/3.1 GB: 12 MB/s, t-request=d375c2ec-1982-4c49-8a86-e82e90d5eefa, t-layer=c10c6ab20f1162764f2bcfc11ecafe890e051334318002febe51ffec5ed5346f

No-limit CPU

I1008 10:28:35.625671       1 torrent.go:384] torrent downloading(5.000057437s): 260 MB/3.1 GB: 52 MB/s, t-request=42a963ca-ec03-4147-a691-4dbeec402789, t-layer=c10c6ab20f1162764f2bcfc11ecafe890e051334318002febe51ffec5ed5346f
I1008 10:28:40.625845       1 torrent.go:384] torrent downloading(10.000228777s): 495 MB/3.1 GB: 47 MB/s, t-request=42a963ca-ec03-4147-a691-4dbeec402789, t-layer=c10c6ab20f1162764f2bcfc11ecafe890e051334318002febe51ffec5ed5346f
I1008 10:28:45.625669       1 torrent.go:384] torrent downloading(15.000052019s): 749 MB/3.1 GB: 51 MB/s, t-request=42a963ca-ec03-4147-a691-4dbeec402789, t-layer=c10c6ab20f1162764f2bcfc11ecafe890e051334318002febe51ffec5ed5346f
I1008 10:28:50.625905       1 torrent.go:384] torrent downloading(20.000282912s): 885 MB/3.1 GB: 27 MB/s, t-request=42a963ca-ec03-4147-a691-4dbeec402789, t-layer=c10c6ab20f1162764f2bcfc11ecafe890e051334318002febe51ffec5ed5346f
I1008 10:28:55.625825       1 torrent.go:384] torrent downloading(25.000211167s): 1.3 GB/3.1 GB: 74 MB/s, t-request=42a963ca-ec03-4147-a691-4dbeec402789, t-layer=c10c6ab20f1162764f2bcfc11ecafe890e051334318002febe51ffec5ed5346f
I1008 10:29:00.626036       1 torrent.go:384] torrent downloading(30.000424357s): 1.5 GB/3.1 GB: 52 MB/s, t-request=42a963ca-ec03-4147-a691-4dbeec402789, t-layer=c10c6ab20f1162764f2bcfc11ecafe890e051334318002febe51ffec5ed5346f
I1008 10:29:05.626016       1 torrent.go:384] torrent downloading(35.000402777s): 1.8 GB/3.1 GB: 50 MB/s, t-request=42a963ca-ec03-4147-a691-4dbeec402789, t-layer=c10c6ab20f1162764f2bcfc11ecafe890e051334318002febe51ffec5ed5346f
I1008 10:29:10.625694       1 torrent.go:384] torrent downloading(40.000074839s): 2.1 GB/3.1 GB: 72 MB/s, t-request=42a963ca-ec03-4147-a691-4dbeec402789, t-layer=c10c6ab20f1162764f2bcfc11ecafe890e051334318002febe51ffec5ed5346f
I1008 10:29:15.625669       1 torrent.go:384] torrent downloading(45.000047538s): 2.3 GB/3.1 GB: 35 MB/s, t-request=42a963ca-ec03-4147-a691-4dbeec402789, t-layer=c10c6ab20f1162764f2bcfc11ecafe890e051334318002febe51ffec5ed5346f
I1008 10:29:20.626011       1 torrent.go:384] torrent downloading(50.000383077s): 2.3 GB/3.1 GB: 839 kB/s, t-request=42a963ca-ec03-4147-a691-4dbeec402789, t-layer=c10c6ab20f1162764f2bcfc11ecafe890e051334318002febe51ffec5ed5346f
I1008 10:29:25.626042       1 torrent.go:384] torrent downloading(55.000403842s): 2.6 GB/3.1 GB: 56 MB/s, t-request=42a963ca-ec03-4147-a691-4dbeec402789, t-layer=c10c6ab20f1162764f2bcfc11ecafe890e051334318002febe51ffec5ed5346f

@penglongli
Copy link
Author

penglongli commented Oct 8, 2024

I found a situation with no-limit cpu. My file-transfer model is one that sends to multiple via torrent (1 -> N).

The main linux-node generate the torrent, others download the torrent from main-node. Main-node used 5c CPU, others used 0.8-1.5c CPU.

@anacrolix Do you have any suggestions for me in this situation? Or is there a distributed cache that can be shared by all clients in a local area network to reduce the CPU usage of the calculation?

@anacrolix
Copy link
Owner

Is c 100%?

The upload routines are not highly optimised.

Probably the most helpful thing is to send a few CPU profiles when usage is highest.

@penglongli
Copy link
Author

Is c 100%?

The upload routines are not highly optimised.

Probably the most helpful thing is to send a few CPU profiles when usage is highest.

Yes, 1c is 1 CPU-core.

Wait a minute, I will now construct a cpu-profiles

@penglongli
Copy link
Author

@anacrolix I found that uploading took up a lot of CPU resources

pprof.bcs-image-proxy.samples.cpu.002.pb.gz
pprof.bcs-image-proxy.samples.cpu.001.pb.gz

@penglongli
Copy link
Author

@anacrolix Is there any way to optimize uploads? :)

@anacrolix
Copy link
Owner

I haven't had a chance to look yet. A few days to develop a comprehensive integration performance test is the best chance, but I or others need sponsorship for that. I'll take a look at the profiles tonight

@anacrolix
Copy link
Owner

I highly suspect this workaround is causing issues:

for frontBuf.Len() != 0 {
// Limit write size for WebRTC. See https://github.com/pion/datachannel/issues/59.
next := frontBuf.Next(1<<16 - 1)
var n int
n, err = cn.w.Write(next)
if err == nil && n != len(next) {
panic("expected full write")
}
if err != nil {
break
}
}
.

The buffer size limit is rather small for offloading a lot of data and will be breaking up fast uploads into a significant number of syscalls to unaligned memory.

I expect if we fix that we could see 2-3x the throughput easily by correcting that, possibly a lot more, and probably a lot less CPU.

There is also some significant memory allocation overhead that I can see in the CPU profile. Could you provide a heap profile too? You should be able to collect that at the end of a long session. alloc_space and alloc_objects are what we want, and those should both be included by a single heap profile. It will be the next large contributor after the above is fixed, unless it is a symptom of the above too.

@penglongli
Copy link
Author

@anacrolix I think maybe memory is not an issue, most of the memory is used by cache. This is my cgroup info in pod

~# cat /sys/fs/cgroup/memory/memory.meminfo
MemTotal:        1048576 kB
MemFree:           50036 kB
Buffers:               0 kB
Cached:           691860 kB
SwapCached:            0 kB
Active:           347176 kB
Inactive:         573088 kB
Active(anon):          0 kB
Inactive(anon):   229580 kB
Active(file):     347176 kB
Inactive(file):   343508 kB
Unevictable:           0 kB
Mlocked:               0 kB
SwapTotal:             0 kB
SwapFree:              0 kB
Dirty:                 0 kB
Writeback:             0 kB
AnonPages:        229320 kB
Mapped:           669240 kB
Shmem:                 0 kB
Slab:                  0 kB
SReclaimable:          0 kB
SUnreclaim:            0 kB
KernelStack:           0 kB
PageTables:            0 kB
NFS_Unstable:          0 kB
Bounce:                0 kB
WritebackTmp:          0 kB
CommitLimit:           0 kB
Committed_AS:          0 kB
VmallocTotal:          0 kB
VmallocUsed:           0 kB
VmallocChunk:          0 kB
HardwareCorrupted:     0 kB
AnonHugePages:         0 kB

~#  cat /sys/fs/cgroup/memory/memory.stat 
cache 708464640
rss 234823680
rss_huge 0
shmem 0
mapped_file 685301760
dirty 0
writeback 798720
swap 0
pgpgin 12012260
pgpgout 11781546
pgfault 4200625
pgmajfault 74165
inactive_anon 235089920
active_anon 0
inactive_file 351752192
active_file 355508224
unevictable 0
hierarchical_memory_limit 1073741824
hierarchical_memsw_limit 9223372036854771712
total_cache 708464640
total_rss 234823680
total_rss_huge 0
total_shmem 0
total_mapped_file 685301760
total_dirty 0
total_writeback 798720
total_swap 0
total_pgpgin 12012260
total_pgpgout 11781546
total_pgfault 4200625
total_pgmajfault 74165
total_inactive_anon 235089920
total_active_anon 0
total_inactive_file 351752192
total_active_file 355508224
total_unevictable 0
pgscan_in_background 1928
pgsteal_in_background 1683
workingset_refault_anon 0
workingset_refault_file 6921070
workingset_activate_anon 0
workingset_activate_file 647985
workingset_restore_anon 0
workingset_restore_file 26130
workingset_nodereclaim 40690
workingset_refault_distance_last 71
workingset_refault_distance_avg_1m 252
workingset_refault_distance_avg_10m 1568
workingset_refault_distance_avg_30m 736
workingset_watermark_last 0
workingset_watermark_avg_1m 0
workingset_watermark_avg_10m 108
workingset_watermark_avg_30m 145
workingset_valid_eviction_last 9947
workingset_valid_eviction_avg_1m 11135
workingset_valid_eviction_avg_10m 9263
workingset_valid_eviction_avg_30m 4248
mst_mem_spd_max 0
mst_nr_throttled 0

I also give you the heap profile: heap.gz
(go tool pprof -http=":7777" ./heap.gz )

@penglongli
Copy link
Author

penglongli commented Oct 11, 2024

I also got some problem. When I have a lot of torrents downloading at the same time, I get no-speeds sometimes:

I1011 10:49:40.962663       1 torrent.go:383] torrent downloading(15.000282537s): 298 MB/2.2 GB: 36 MB/s, t-request=66ecdf17-836b-4a82-9d19-6d25345be459, t-layer=a7c9126206c9abc5ece02cda4f3aeabddc1b3d985f9b92c8933927c0b8bbde07
I1011 10:49:45.962448       1 torrent.go:383] torrent downloading(20.000044089s): 298 MB/2.2 GB: 0 B/s, t-request=66ecdf17-836b-4a82-9d19-6d25345be459, t-layer=a7c9126206c9abc5ece02cda4f3aeabddc1b3d985f9b92c8933927c0b8bbde07
I1011 10:49:51.200760       1 torrent.go:383] torrent downloading(25.238382966s): 621 MB/2.2 GB: 65 MB/s, t-request=66ecdf17-836b-4a82-9d19-6d25345be459, t-layer=a7c9126206c9abc5ece02cda4f3aeabddc1b3d985f9b92c8933927c0b8bbde07
I1011 10:49:55.963133       1 torrent.go:383] torrent downloading(30.000756356s): 629 MB/2.2 GB: 1.7 MB/s, t-request=66ecdf17-836b-4a82-9d19-6d25345be459, t-layer=a7c9126206c9abc5ece02cda4f3aeabddc1b3d985f9b92c8933927c0b8bbde07
I1011 10:50:00.962873       1 torrent.go:383] torrent downloading(35.000493641s): 629 MB/2.2 GB: 0 B/s, t-request=66ecdf17-836b-4a82-9d19-6d25345be459, t-layer=a7c9126206c9abc5ece02cda4f3aeabddc1b3d985f9b92c8933927c0b8bbde07
I1011 10:50:05.962565       1 torrent.go:383] torrent downloading(40.000192453s): 629 MB/2.2 GB: 0 B/s, t-request=66ecdf17-836b-4a82-9d19-6d25345be459, t-layer=a7c9126206c9abc5ece02cda4f3aeabddc1b3d985f9b92c8933927c0b8bbde07
I1011 10:50:10.962917       1 torrent.go:383] torrent downloading(45.000528981s): 1.4 GB/2.2 GB: 146 MB/s, t-request=66ecdf17-836b-4a82-9d19-6d25345be459, t-layer=a7c9126206c9abc5ece02cda4f3aeabddc1b3d985f9b92c8933927c0b8bbde07
I1011 10:50:15.963153       1 torrent.go:383] torrent downloading(50.000778857s): 1.4 GB/2.2 GB: 9.6 MB/s, t-request=66ecdf17-836b-4a82-9d19-6d25345be459, t-layer=a7c9126206c9abc5ece02cda4f3aeabddc1b3d985f9b92c8933927c0b8bbde07
I1011 10:50:20.963261       1 torrent.go:383] torrent downloading(55.00087276s): 1.5 GB/2.2 GB: 16 MB/s, t-request=66ecdf17-836b-4a82-9d19-6d25345be459, t-layer=a7c9126206c9abc5ece02cda4f3aeabddc1b3d985f9b92c8933927c0b8bbde07
I1011 10:50:25.962898       1 torrent.go:383] torrent downloading(1m0.000525763s): 1.6 GB/2.2 GB: 22 MB/s, t-request=66ecdf17-836b-4a82-9d19-6d25345be459, t-layer=a7c9126206c9abc5ece02cda4f3aeabddc1b3d985f9b92c8933927c0b8bbde07
I1011 10:50:30.963451       1 torrent.go:383] torrent downloading(1m5.00107011s): 1.8 GB/2.2 GB: 32 MB/s, t-request=66ecdf17-836b-4a82-9d19-6d25345be459, t-layer=a7c9126206c9abc5ece02cda4f3aeabddc1b3d985f9b92c8933927c0b8bbde07
I1011 10:50:35.963057       1 torrent.go:383] torrent downloading(1m10.000680443s): 1.9 GB/2.2 GB: 26 MB/s, t-request=66ecdf17-836b-4a82-9d19-6d25345be459, t-layer=a7c9126206c9abc5ece02cda4f3aeabddc1b3d985f9b92c8933927c0b8bbde07
I1011 10:50:40.962926       1 torrent.go:383] torrent downloading(1m15.00052799s): 2.0 GB/2.2 GB: 25 MB/s, t-request=66ecdf17-836b-4a82-9d19-6d25345be459, t-layer=a7c9126206c9abc5ece02cda4f3aeabddc1b3d985f9b92c8933927c0b8bbde07
I1011 10:50:45.963275       1 torrent.go:383] torrent downloading(1m20.000898669s): 2.2 GB/2.2 GB: 32 MB/s, t-request=66ecdf17-836b-4a82-9d19-6d25345be459, t-layer=a7c9126206c9abc5ece02cda4f3aeabddc1b3d985f9b92c8933927c0b8bbde07

@penglongli
Copy link
Author

@penglongli
Copy link
Author

penglongli commented Oct 16, 2024

I found that if I adjusted the PieceLength and ChunkSize, I could get a better speed.

var pieceLength int64
pieceLength = metainfo.ChoosePieceLength(layerFileInfo.Size())
info := metainfo.Info{
	PieceLength: pieceLength * 10,  // set PieceLength tenfold increase
}
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.NewMMapWithCompletion(th.op.TransferPath, th.pc),
	ChunkSize: 1048576, // set ChunSize to 1MB
})
err := to.MergeSpec(&torrent.TorrentSpec{
	InfoBytes: mi.InfoBytes,
	Trackers:  [][]string{{th.op.TorrentAnnounce}},
})

But after i generate the torrent and let other-nodes download. At the beginning, there was a long period of time without speed.

torrent downloading(5.000529669s): 0 B/8.5 GB: 0 B/s, t-request=eb3c0c2f-cf98-49f9-bfd9-0d338e29acdf,  t-layer=d9cc3541512c994947891989e71c3334a23e830942b91a6461cc6c29e2935649
torrent downloading(10.000162751s): 0 B/8.5 GB: 0 B/s, t-request=eb3c0c2f-cf98-49f9-bfd9-0d338e29acdf,  t-layer=d9cc3541512c994947891989e71c3334a23e830942b91a6461cc6c29e2935649
torrent downloading(15.000683001s): 0 B/8.5 GB: 0 B/s, t-request=eb3c0c2f-cf98-49f9-bfd9-0d338e29acdf,  t-layer=d9cc3541512c994947891989e71c3334a23e830942b91a6461cc6c29e2935649
torrent downloading(20.001388498s): 0 B/8.5 GB: 0 B/s, t-request=eb3c0c2f-cf98-49f9-bfd9-0d338e29acdf,  t-layer=d9cc3541512c994947891989e71c3334a23e830942b91a6461cc6c29e2935649
torrent downloading(25.000285312s): 0 B/8.5 GB: 0 B/s, t-request=eb3c0c2f-cf98-49f9-bfd9-0d338e29acdf,  t-layer=d9cc3541512c994947891989e71c3334a23e830942b91a6461cc6c29e2935649
torrent downloading(30.000495636s): 0 B/8.5 GB: 0 B/s, t-request=eb3c0c2f-cf98-49f9-bfd9-0d338e29acdf,  t-layer=d9cc3541512c994947891989e71c3334a23e830942b91a6461cc6c29e2935649
torrent downloading(35.000939619s): 0 B/8.5 GB: 0 B/s, t-request=eb3c0c2f-cf98-49f9-bfd9-0d338e29acdf,  t-layer=d9cc3541512c994947891989e71c3334a23e830942b91a6461cc6c29e2935649
torrent downloading(40.000701298s): 0 B/8.5 GB: 0 B/s, t-request=eb3c0c2f-cf98-49f9-bfd9-0d338e29acdf,  t-layer=d9cc3541512c994947891989e71c3334a23e830942b91a6461cc6c29e2935649
torrent downloading(45.002410368s): 0 B/8.5 GB: 0 B/s, t-request=eb3c0c2f-cf98-49f9-bfd9-0d338e29acdf,  t-layer=d9cc3541512c994947891989e71c3334a23e830942b91a6461cc6c29e2935649
torrent downloading(50.00122322s): 0 B/8.5 GB: 0 B/s, t-request=eb3c0c2f-cf98-49f9-bfd9-0d338e29acdf,  t-layer=d9cc3541512c994947891989e71c3334a23e830942b91a6461cc6c29e2935649
torrent downloading(55.000676215s): 0 B/8.5 GB: 0 B/s, t-request=eb3c0c2f-cf98-49f9-bfd9-0d338e29acdf,  t-layer=d9cc3541512c994947891989e71c3334a23e830942b91a6461cc6c29e2935649
torrent downloading(1m0.002478829s): 0 B/8.5 GB: 0 B/s, t-request=eb3c0c2f-cf98-49f9-bfd9-0d338e29acdf,  t-layer=d9cc3541512c994947891989e71c3334a23e830942b91a6461cc6c29e2935649
torrent downloading(1m5.00048402s): 126 MB/8.5 GB: 25 MB/s, t-request=eb3c0c2f-cf98-49f9-bfd9-0d338e29acdf,  t-layer=d9cc3541512c994947891989e71c3334a23e830942b91a6461cc6c29e2935649
torrent downloading(1m10.000232989s): 503 MB/8.5 GB: 75 MB/s, t-request=eb3c0c2f-cf98-49f9-bfd9-0d338e29acdf,  t-layer=d9cc3541512c994947891989e71c3334a23e830942b91a6461cc6c29e2935649
torrent downloading(1m15.000250723s): 566 MB/8.5 GB: 13 MB/s, t-request=eb3c0c2f-cf98-49f9-bfd9-0d338e29acdf,  t-layer=d9cc3541512c994947891989e71c3334a23e830942b91a6461cc6c29e2935649
torrent downloading(1m20.000169387s): 819 MB/8.5 GB: 50 MB/s, t-request=eb3c0c2f-cf98-49f9-bfd9-0d338e29acdf,  t-layer=d9cc3541512c994947891989e71c3334a23e830942b91a6461cc6c29e2935649
torrent downloading(1m25.000167303s): 1.3 GB/8.5 GB: 88 MB/s, t-request=eb3c0c2f-cf98-49f9-bfd9-0d338e29acdf,  t-layer=d9cc3541512c994947891989e71c3334a23e830942b91a6461cc6c29e2935649
torrent downloading(1m30.000272529s): 1.3 GB/8.5 GB: 0 B/s, t-request=eb3c0c2f-cf98-49f9-bfd9-0d338e29acdf,  t-layer=d9cc3541512c994947891989e71c3334a23e830942b91a6461cc6c29e2935649
torrent downloading(1m35.000106784s): 1.6 GB/8.5 GB: 71 MB/s, t-request=eb3c0c2f-cf98-49f9-bfd9-0d338e29acdf,  t-layer=d9cc3541512c994947891989e71c3334a23e830942b91a6461cc6c29e2935649
torrent downloading(1m40.000884173s): 2.0 GB/8.5 GB: 76 MB/s, t-request=eb3c0c2f-cf98-49f9-bfd9-0d338e29acdf,  t-layer=d9cc3541512c994947891989e71c3334a23e830942b91a6461cc6c29e2935649
torrent downloading(1m45.0000347s): 2.6 GB/8.5 GB: 132 MB/s, t-request=eb3c0c2f-cf98-49f9-bfd9-0d338e29acdf,  t-layer=d9cc3541512c994947891989e71c3334a23e830942b91a6461cc6c29e2935649
torrent downloading(1m50.000052088s): 2.7 GB/8.5 GB: 9.7 MB/s, t-request=eb3c0c2f-cf98-49f9-bfd9-0d338e29acdf,  t-layer=d9cc3541512c994947891989e71c3334a23e830942b91a6461cc6c29e2935649
torrent downloading(1m55.000631812s): 2.9 GB/8.5 GB: 31 MB/s, t-request=eb3c0c2f-cf98-49f9-bfd9-0d338e29acdf,  t-layer=d9cc3541512c994947891989e71c3334a23e830942b91a6461cc6c29e2935649
torrent downloading(2m0.000738076s): 3.7 GB/8.5 GB: 176 MB/s, t-request=eb3c0c2f-cf98-49f9-bfd9-0d338e29acdf,  t-layer=d9cc3541512c994947891989e71c3334a23e830942b91a6461cc6c29e2935649
torrent downloading(2m5.000056626s): 3.8 GB/8.5 GB: 13 MB/s, t-request=eb3c0c2f-cf98-49f9-bfd9-0d338e29acdf,  t-layer=d9cc3541512c994947891989e71c3334a23e830942b91a6461cc6c29e2935649
torrent downloading(2m10.035212626s): 3.8 GB/8.5 GB: 4.2 MB/s, t-request=eb3c0c2f-cf98-49f9-bfd9-0d338e29acdf,  t-layer=d9cc3541512c994947891989e71c3334a23e830942b91a6461cc6c29e2935649
torrent downloading(2m15.000332026s): 3.8 GB/8.5 GB: 0 B/s, t-request=eb3c0c2f-cf98-49f9-bfd9-0d338e29acdf,  t-layer=d9cc3541512c994947891989e71c3334a23e830942b91a6461cc6c29e2935649
torrent downloading(2m20.00004438s): 3.8 GB/8.5 GB: 0 B/s, t-request=eb3c0c2f-cf98-49f9-bfd9-0d338e29acdf,  t-layer=d9cc3541512c994947891989e71c3334a23e830942b91a6461cc6c29e2935649
torrent downloading(2m25.000931383s): 3.9 GB/8.5 GB: 8.4 MB/s, t-request=eb3c0c2f-cf98-49f9-bfd9-0d338e29acdf,  t-layer=d9cc3541512c994947891989e71c3334a23e830942b91a6461cc6c29e2935649
torrent downloading(2m30.000693157s): 4.7 GB/8.5 GB: 159 MB/s, t-request=eb3c0c2f-cf98-49f9-bfd9-0d338e29acdf,  t-layer=d9cc3541512c994947891989e71c3334a23e830942b91a6461cc6c29e2935649
torrent downloading(2m35.00076308s): 5.5 GB/8.5 GB: 159 MB/s, t-request=eb3c0c2f-cf98-49f9-bfd9-0d338e29acdf,  t-layer=d9cc3541512c994947891989e71c3334a23e830942b91a6461cc6c29e2935649
torrent downloading(2m40.000796964s): 5.7 GB/8.5 GB: 42 MB/s, t-request=eb3c0c2f-cf98-49f9-bfd9-0d338e29acdf,  t-layer=d9cc3541512c994947891989e71c3334a23e830942b91a6461cc6c29e2935649
torrent downloading(2m45.000097708s): 5.7 GB/8.5 GB: 0 B/s, t-request=eb3c0c2f-cf98-49f9-bfd9-0d338e29acdf,  t-layer=d9cc3541512c994947891989e71c3334a23e830942b91a6461cc6c29e2935649
torrent downloading(2m50.000305337s): 5.7 GB/8.5 GB: 8.4 MB/s, t-request=eb3c0c2f-cf98-49f9-bfd9-0d338e29acdf,  t-layer=d9cc3541512c994947891989e71c3334a23e830942b91a6461cc6c29e2935649
torrent downloading(2m55.000467009s): 6.5 GB/8.5 GB: 150 MB/s, t-request=eb3c0c2f-cf98-49f9-bfd9-0d338e29acdf,  t-layer=d9cc3541512c994947891989e71c3334a23e830942b91a6461cc6c29e2935649
torrent downloading(3m0.000965473s): 7.2 GB/8.5 GB: 156 MB/s, t-request=eb3c0c2f-cf98-49f9-bfd9-0d338e29acdf,  t-layer=d9cc3541512c994947891989e71c3334a23e830942b91a6461cc6c29e2935649
torrent downloading(3m5.000037402s): 7.7 GB/8.5 GB: 84 MB/s, t-request=eb3c0c2f-cf98-49f9-bfd9-0d338e29acdf,  t-layer=d9cc3541512c994947891989e71c3334a23e830942b91a6461cc6c29e2935649
torrent downloading(3m10.000029362s): 7.7 GB/8.5 GB: 10 MB/s, t-request=eb3c0c2f-cf98-49f9-bfd9-0d338e29acdf,  t-layer=d9cc3541512c994947891989e71c3334a23e830942b91a6461cc6c29e2935649

I guess there is some performance bottleneck in torrent uploads. But I don't know if there is any way to solve it. Or is there a private version that I can test?

@anacrolix
Copy link
Owner

Just to clarify, memory overhead as in the cost of allocation and management. Not the actual amount of memory used. #982 (comment) remains my strongest suggestions. You can try to disable or remove that WebRTC workaround and see if it makes a difference.

@penglongli
Copy link
Author

for frontBuf.Len() != 0 {
// Limit write size for WebRTC. See https://github.com/pion/datachannel/issues/59.
next := frontBuf.Next(1<<16 - 1)
var n int
n, err = cn.w.Write(next)
if err == nil && n != len(next) {
panic("expected full write")
}
if err != nil {
break
}
}

Should I just delete this paragraph and reference my private github.com/penglongli/torrent version?

for frontBuf.Len() != 0 {
	// Limit write size for WebRTC. See https://github.com/pion/datachannel/issues/59.
	next := frontBuf.Next(1<<16 - 1)
	var n int
	n, err = cn.w.Write(next)
	if err == nil && n != len(next) {
		panic("expected full write")
	}
	if err != nil {
		break
	}
}

@anacrolix
Copy link
Owner

@anacrolix
Copy link
Owner

Try master where I've removed the limit except for webtorrent peer conns. On a re-read of the code, I had in my head that the limit was much smaller than it actually is. It might not have as much impact as I expected, but your feedback with master will be valuable.

@penglongli
Copy link
Author

I used v1.57.2-0.20241017235801-4d8437a05621, but it doesn't seem to have been a big improvement.

pprof-cpu-20241022.1.pb.gz
pprof-cpu-20241022.2.pb.gz
pprof-cpu-20241022.3.pb.gz
pprof-heap-20241022.1.pb.gz

@anacrolix
Copy link
Owner

In cpu 2, the CPU usage of Peer.maybeUpdateActualRequestState is very high. That will choke/starve the upload routine. The memory usage isn't bad, I think I see you are using the file storage, you may find another storage more optimized (like possum or mmap). There's still a fair amount of allocations there in the read pipeline. It will slow it down a bit but isn't choking it AFAICT. But the CPU usage mentioned will very likely cause problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants