Limit CPU usage GOMAXPROCS / NICENESS on linux

Hello,

I have read at several place that using GOMAXPROCS can help to limit the number of core used. Also, I have read here that NICENESS can be set to 19 to reduce syncthing at lowest priority.

I would like to try those to reduce as much as possible the CPU footprint of syncthings, but despite many place mention GOMAXPROCS, I have no idea how to use it and set it permanently.

Is there any howto somewhere?. any help welcome!

Same also to Niceness, I found how to set it on a running process, but how to set it permanently ?

I run syncthing on a few ubuntu computers (16.04 or later) but also testing it on an old readynas ultra and place to use it on a NAS I plan to purchase)

It depends how you start syncthing how you set it, I have a start script that has something like this:

nice -n 19 ionice -c3 /path/to/syncthing

you can add GOMAXPROCS before that, should be something like

GOMAXPROCS=2 nice -n 19 ionice -c3 /path/to/syncthing with whatever number of cores you want it to use

1 Like

Doesn’t GOMAXPROCS set the number of procs per folder and the default is {number of procs in system / number of folders} but at least 1. At least it used to be that way, iirc.

GOMAXPROCS sets number of cores for go runtime to use. Can’t check code as on a mobile but we might be overwriting that for legacy reasons (as default used to be 1).

We set GOMAXPROCS to the number of CPU cores in the system, unless the environment variable is set. Which is the same thing as Go itself does since, like, Go 1.2 or so. So we could probably remove that as it does nothing.

The number of hasher routines used per folder is as wweich describes.

Hi !

the documentation says this: GOMAXPROCS Set the maximum number of CPU cores to use. Defaults to all available CPU cores.

@Alex: to start syncthings automatically, I have followed some howto.

Basically it says to create /etc/systemd/system/syncthing@.service with this content:

[Unit]
Description=Syncthing - Open Source Continuous File Synchronization for %I
Documentation=man:syncthing(1)
After=network.target
Wants=syncthing-inotify@.service
[Service]
User=%i
ExecStart=/usr/bin/syncthing -no-browser -no-restart -logflags=0
Restart=on-failure
SuccessExitStatus=3 4
RestartForceExitStatus=3 4
UMask=0002

[Install]
WantedBy=multi-user.target

and then a couple of systemctl commands:

systemctl enable syncthing@Toto.service
systemctl start syncthing@Toto.service

(replace Toto with username)

But I’m not expert enought to understand exactly what it does and how to add niceness and gomaxprocs on this setup.

Oh, what do you think about replacing:

ExecStart=/usr/bin/syncthing -no-browser -no-restart -logflags=0

by

ExecStart=GOMAXPROCS=2 nice -n 19 ionice -c3 /usr/bin/syncthing -no-browser -no-restart -logflags=0

(I merged your proposal with the content of this /etc/systemd/system/syncthing@.service file

You should look at the systemd manuals for how to set environment variables (GOMAXPROCS) and niceness in systemd.

Hi again,

Jakob, it’s not easy to understand how this is all working (manuals for things like systemd are not easy to read for basic users), but anyway I found this that may help:

If I understood correctly the example, I could modify my file this way:

[Service]
Environment=GOMAXPROCS=1
Nice=19
User=%i
ExecStart=/usr/bin/syncthing -no-browser -no-restart -logflags=0
Restart=on-failure
SuccessExitStatus=3 4
RestartForceExitStatus=3 4
UMask=0002

Also I found on some forum that Nice= may be used here (to be confirmed, a similar setting name CPUshares= seems possible too)

That looks reasonable.

I’ll give a try when I get back home and share what happened :slight_smile:

Hi!

I have modified the config file and it seems to work. I’m not sure for the core number but niceness is for sure set to 19 (checked with “top” command).

Cpu is much more available for other purposes

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.