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

cmd/syncthing, lib/config, lib/osutil: Lower process priority (fixes #4628) #4675

Closed
wants to merge 6 commits into from

Conversation

calmh
Copy link
Member

@calmh calmh commented Jan 15, 2018

Purpose

Be nicer to the rest of the system by default.

Adds a new option setLowPriority which is true by default. If set to false we do nothing to change our priority on startup, like before.

Testing

I've tested this on Mac, Linux and FreeBSD and see the desired result on all of them: all threads in the final syncthing process (not the monitor) become niceness level 9.

I have not inspected the result on Windows... I don't have a Windows VM on my laptop right now, I'd really appreciate if someone ran the resulting binary and checked if it did what it's supposed to and didn't, like, crash or something...

// group variants of Setpriority etc to affect all of our threads in one
// go. If this fails, bail, so that we don't affect things we shouldn't.
if err := syscall.Setpgid(0, 0); err != nil {
return
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sync.Once this?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see the point, it's just called once from main and we'd need to remember the error in another package variable to be able to return it again etc

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I was just pointing out in case other Go users use it. Also, with errors being returned, sync.Once makes more sense (as I assume doing pgrp twice will fail).

@@ -915,6 +915,11 @@ func syncthingMain(runtimeOptions RuntimeOptions) {

cleanConfigDirectory()

if cfg.Options().SetLowPriority {
// This is best effort and we ignore failures.
osutil.SetLowPriority()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could atleast log failures.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed

@AudriusButkevicius
Copy link
Member

Would it make sense to make this like a value you can adjust? Default being like 3, so people can go up and down? Perhaps someone is running syncthing as a service.

@calmh
Copy link
Member Author

calmh commented Jan 15, 2018

I'd really not want to add too many knobs to this because then we'll end up having to expose all the scheduler classes for iopriority, the various names of the priority classes in windows or the bitmasks, etc. I think we should just do something sane by default, and if someone wants something better they can disable our stuff by config and do whatever they please at launch time.

@canton7
Copy link
Member

canton7 commented Jan 15, 2018

Is it worth logging failures, under some debug level perhaps?

@calmh
Copy link
Member Author

calmh commented Jan 15, 2018

Logging failures added... As warning level no less. Is that too aggressive? Maybe have it like that for the RC and see what drops in?

My reasoning for warning is that once we've decided the Syncthing should not be a CPU & I/O resource hog it's worth warning the user that it might be, under the assumption that this is a very rare failure...

}
defer syscall.CloseHandle(handle)

_, _, err := syscall.Syscall(uintptr(setPriorityClass), uintptr(handle), belowNormalPriorityClass, 0, 0)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is the ioprio return value handling different from windows?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not, any more, I think

@canton7
Copy link
Member

canton7 commented Jan 15, 2018

(A note on copyright: in my understanding, the date in the copyright is the earliest year at which you assert copyright over the work, not the latest year. It says "I wrote this code in 2017, so anything which appears since then and isn't written by me is a derivative work". If you update the copyright year to 2018, you're more or less relinquishing your claim to have written the work in 2017, so if another copy pops up copyrighted 2017, your claim to hold copyright looks a little shaky...).

@AudriusButkevicius
Copy link
Member

@st-review merge

@st-review
Copy link

👌 Merged as c554ffc. Thanks, @calmh!

@st-review st-review added the pr-merged Legacy label used in the past for pull requests merged to the main tree label Jan 15, 2018
@st-review st-review closed this Jan 15, 2018
st-review pushed a commit that referenced this pull request Jan 15, 2018
@calmh calmh deleted the fix-4628 branch January 15, 2018 20:57
@st-review st-review added the frozen-due-to-age Issues closed and untouched for a long time, together with being locked for discussion label Jan 16, 2019
@syncthing syncthing locked and limited conversation to collaborators Jan 16, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
frozen-due-to-age Issues closed and untouched for a long time, together with being locked for discussion pr-merged Legacy label used in the past for pull requests merged to the main tree
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants