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

internal/poll: provide method to change maxSpliceSize #40222

Closed
march1993 opened this issue Jul 15, 2020 · 9 comments
Closed

internal/poll: provide method to change maxSpliceSize #40222

march1993 opened this issue Jul 15, 2020 · 9 comments
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. FrozenDueToAge help wanted NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@march1993
Copy link

maxSpliceSize = 4 << 20

I suffer from poor performance caused by the default maxSpliceSize 4MiB on my embedded platforms. Would it be beneficial that a method is provided to change it?

After I changed the value from 4MiB to 32KiB on my OpenWRT router, I got a twice performance.

@ianlancetaylor
Copy link
Contributor

CC @acln0

If 32K is better than 4M on your system, perhaps we should just use that everywhere.

@ianlancetaylor ianlancetaylor added help wanted NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. labels Jul 15, 2020
@ianlancetaylor ianlancetaylor added this to the Backlog milestone Jul 15, 2020
@davecheney
Copy link
Contributor

Seconded @ianlancetaylor if there is a better value, let's make it the default rather than a configuration option.

@acln0
Copy link
Contributor

acln0 commented Jul 15, 2020

If 32K is better than 4M on your system, perhaps we should just use that everywhere.

In principle, I don't see why not, but I would need to run benchmarks to make sure that the change doesn't represent a regression for code that transfers a huge volume of data per unit of time through splice (the kind of systems that saturate links). Such code was the motivation for introducing the splice code in the first place, and a regression would be undesirable. If there is a singular better value, then, of course, that should be the default. Trying to sneak configuration down to the splice code seems to be prohibitively difficult to me anyway, so I think that option is off the table.

I do wonder why a maximum transfer size of 4M per splice round makes things significantly slower, though. We also have a large round size here:

const maxCopyFileRangeRound = 1 << 30

Should we change this one too? Or is this one different because it's copy_file_range and not splice?

Even if we changed the 4M to 32K today, the change wouldn't make it into the 1.15 tree, so I think it would be better to investigate it properly, by reading kernel source code, running more benchmarks, and so forth. I am going to do that at some point in the 1.16 development cycle.

@march1993
Sorry for the trouble. If you don't want to maintain a patched Go tree for a cycle until this is sorted out, try using, instead of io.Copy(dst, src), io.Copy(struct{ io.Writer }{dst}, src). This turns off the splice code and gives you the buffer size you want, at the cost of a little extra copying.

But while you are at it, and have patched your tree already, can you try a few additional intermediate transfer sizes and report the performance you observe, please? Perhaps 64K, 256K, and 1M? Thanks.

@mengzhuo
Copy link
Contributor

mengzhuo commented Feb 4, 2021

The length should be under MAX_RW_COUNT which based on PAGE_MASK

https://github.com/torvalds/linux/blob/d76913908102044f14381df865bb74df17a538cb/fs/splice.c#L783-L784

I can send a CL for this and done some tests on my rpi etc.

@gopherbot gopherbot added the compiler/runtime Issues related to the Go compiler and/or runtime. label Jul 7, 2022
@gopherbot
Copy link

Change https://go.dev/cl/425051 mentions this issue: internal/poll: optimize the maximum amount that can be transferred by one splice(2) call

@ianlancetaylor
Copy link
Contributor

@march1993 What is the contents of the file /proc/sys/fs/pipe-max-size on your system? Thanks.

@march1993
Copy link
Author

@march1993 What is the contents of the file /proc/sys/fs/pipe-max-size on your system? Thanks.

It was 1048576.

@panjf2000
Copy link
Member

Were you transferring a mass of data via splice(2) or small amount of data?and what's your kernel version? thanks.
@march1993

@march1993
Copy link
Author

Were you transferring a mass of data via splice(2) or small amount of data?and what's your kernel version? thanks. @march1993

A mass of data. The kernel version was 5.4.154.

@golang golang locked and limited conversation to collaborators Aug 26, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. FrozenDueToAge help wanted NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

7 participants