Journal Entries By Tag: #Ubuntu

Assorted journal entries with the tag #Ubuntu.


Making SyncThing Play (IO)Nice

TL;DR — My SyncThing instance was using too much CPU, and CPU Limit didn't help reign it in, so I wound up using IO Nice.

👓 2 minutes

Every now and then, my laptop (running #Ubuntu 18.04) would freeze up: all the screens would lock, and although my mouse cursor was still on the screen, it was completely unable to interact with anything. After 30-40 seconds, everything would start moving again and return to normal.

The very first thing that I usually did when I get control of my system back was to run the top command, and what I frequently saw was SyncThing, an open source application that I use for backups, pegging 100% or higher on my CPU usage:

A screenshot showing SyncThing using too much CPU.

Now, I knew that this wasn’t supposed to happen, and until I could figure out what was triggering the sudden jump in utilization, I decided to try and limit SyncThing’s consumption via some other way.

Fix #1 - CPU Limit

First, I tried CPU Limit, a utility designed to put a hard limit on the CPU usage for a process, which I installed and used as outlined here:

# Install CPU Limit
> sudo apt install cpulimit
  • I edited the syncthing.service file to make my ExecStart directive look like this:
# Limit SyncThing to no more than 50% of the available processor
ExecStart=/usr/bin/cpulimit -v -l 50 /usr/bin/syncthing -- -no-browser -no-restart -logflags=0
  • Finally, I restarted the SyncThing service:
# Reload the service files
> systemctl daemon-reload
# or use `systemctl --user daemon-reload` for user-specific services

# Restart the SyncThing service
> systemctl restart syncthing.service
# or use `systemctl --user restart syncthing.service` for user-specific services

This worked for a while, but apparently broke after I updated SyncThing from v0.14.43 to v0.14.50 (the service file kept crashing out).

And that’s when I switched to…

Fix #2 - IO Nice

The IO Nice utility (part of the util-linux package in Debian and Ubuntu) allows system users / admins to adjust the scheduling class for an application, which indicates when the process should run: in real-time, as a best-effort (but giving way real-time applications), or only when the system is otherwise idle.

# Install util-linux
> sudo apt install util-linux
  • again, I edited the syncthing.service file, but this time, I made my ExecStart directive look like this:
# We want syncthing to be run as a "best-effort" application
ExecStart=/usr/bin/ionice -c 2 /usr/bin/syncthing -no-browser -no-restart -logflags=0
  • Finally, I restarted the SyncThing service (aain):
# Reload the service files
> systemctl daemon-reload
# or use `systemctl --user daemon-reload` for user-specific services

# Restart the SyncThing service
> systemctl restart syncthing.service
# or use `systemctl --user restart syncthing.service` for user-specific services

It’s been a little over a month since I made this change, and I haven’t experienced a laptop freeze-up since. I did have a similar problem with SyncThing on the machine that I’m backing up to, and wound up implementing the IO Nice limit on that box, too (with the same result).

I’ll update this post (again) if I run into any other issues with SyncThing.


Fixing Gedit

TL;DR — Notes about some of the settings that I recommend for gedit.

👓 less than 1 minute

I tend to use Atom when I’m working on code, but given the choice, I prefer to use more basic text editors when I’m just making / re-reading notes (something I do alot).

In my laptop’s previous life, it had a runaway memory issue with #gedit that made it impossible to use, but since upgrading to #Ubuntu 18.04, I haven’t had any troubles with it, so it’s been my default text editor once again.

Unfortunately, one issue I’ve continued to run into is that, no matter how many times I adjust the editor settings in the GUI (for tab size, auto-indent, and use-spaces-for-tabs-goddammit), those changes are lost on reboot.

So, this time, rather than making the same futile changes in the application, I decided to use (what I think are) the commands to permanently change those settings.

If you’re having the same problems, type this in your shell of choice (ENTER after each one):

> gsettings set org.gnome.gedit.preferences.editor tabs-size 2
> gsettings set org.gnome.gedit.preferences.editor auto-indent true
> gsettings set org.gnome.gedit.preferences.editor insert-spaces true

I’ve rebooted the machine since I put these commands in, and so far, so good. Of course, this may change by the next LTS release, but these settings should keep my happy for the next couple of years, at least (and I’m posting it here primarily as a #NoteToMyFutureSelf ).