feat(envd): set higher CPU priority for envd and reset it for child processes#2003
feat(envd): set higher CPU priority for envd and reset it for child processes#2003
Conversation
| // 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 { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
5cd7cd6 to
6675e9d
Compare
|
I have bumped the |
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
setpriorityfails or is applied inconsistently.Overview
Runs
envdwith 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 reportedenvdversion to0.5.4.Written by Cursor Bugbot for commit aed26be. This will update automatically on new commits. Configure here.