Skip to content

feat(envd): set higher CPU priority for envd and reset it for child processes#2003

Open
arkamar wants to merge 3 commits intomainfrom
feat/envd-nice
Open

feat(envd): set higher CPU priority for envd and reset it for child processes#2003
arkamar wants to merge 3 commits intomainfrom
feat/envd-nice

Conversation

@arkamar
Copy link
Contributor

@arkamar arkamar commented Feb 26, 2026

Set Nice=-20 in envd.service to improve responsiveness under load. Reset nice to the default level (0) for user processes, PTY processes, and socat port-forwarding processes so only envd itself benefits from the elevated priority.


Note

Medium Risk
Medium risk because it changes process scheduling priority at the systemd level and actively adjusts child process niceness, which could affect responsiveness and behavior under load if setpriority fails or is applied inconsistently.

Overview
Runs envd with elevated CPU priority (Nice=-20) while explicitly resetting spawned process nice levels back to normal (0) after start, so only the daemon retains the higher priority. Also bumps the reported envd version to 0.5.4.

Written by Cursor Bugbot for commit aed26be. This will update automatically on new commits. Configure here.

// This is needed because envd runs with Nice=-20 (set in the systemd unit),
// and child processes inherit this priority. User processes should run at
// normal priority.
func resetNice(pid int) error {
Copy link

Choose a reason for hiding this comment

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

syscall.Setpriority(PRIO_PROCESS, pid, 0) called from the parent process only resets the nice value of the thread identified by pid (the thread group leader). On Linux, sibling threads already spawned by the child process before this call are not affected — they permanently retain nice=-20, since thread creation inherits the creating thread's nice at the moment of creation.

For multi-threaded runtimes that spin up OS threads during process initialization — Node.js (libuv worker pool), JVM (GC/JIT threads), etc. — those runtime-internal threads will permanently run at highest CPU priority, contrary to the intent of this change.

A cleaner alternative is to use a small wrapper executable/shell snippet as the process entry point that calls setpriority(PRIO_PROCESS, 0, 0) (targeting PID 0 = self, which does apply to the whole thread group in the PRIO_PROCESS + self case on Linux) before exec-ing the real command. This avoids the race entirely, since by the time the runtime's threads are created, the process is already at nice=0.

Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

…rocesses

Set Nice=-20 in envd.service to improve responsiveness under load.
Reset nice to the default level (0) for user processes, PTY processes,
and socat port-forwarding processes so only envd itself benefits from
the elevated priority.
Socat is critical infrastructure — if it gets CPU-starved by user
processes, connections drop silently. Let it inherit envd's Nice=-20
like other infrastructure processes.
@arkamar
Copy link
Contributor Author

arkamar commented Feb 27, 2026

I have bumped the envd version to 0.5.4.

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

Successfully merging this pull request may close these issues.

3 participants