Skip to content

Suspend screen rendering for inactive sessions to reduce server CPU usage and network traffic#425

Open
tsz8899 wants to merge 1 commit into
neutrinolabs:develfrom
tsz8899:feature/screensleep-logic
Open

Suspend screen rendering for inactive sessions to reduce server CPU usage and network traffic#425
tsz8899 wants to merge 1 commit into
neutrinolabs:develfrom
tsz8899:feature/screensleep-logic

Conversation

@tsz8899
Copy link
Copy Markdown
Contributor

@tsz8899 tsz8899 commented Mar 27, 2026

Summary

This change adds a screen-sleep mechanism for idle xorgxrdp sessions.

When a session stays idle for a configured amount of time, xorgxrdp stops sending display updates. Once user activity is detected again, display updates resume and a refresh is forced.

Why

In long-lived remote desktop sessions, the server can continue spending CPU time and network bandwidth on screen updates even when the user is idle.

This feature can save a significant amount of server CPU usage and network traffic in long-connection scenarios.

The effect is especially noticeable in these cases:

  • With H.264 encoding, the CPU savings are more obvious. sleep single-user session cpu 65%->1%
  • With RFX encoding, the network traffic savings are more obvious. sleep single-user session network traffic 50Mb->0.1Mb
  • The benefit is even greater in multi-user deployments.

Behavior

  • No change unless the feature is enabled by xrdp.
  • While user is not operating the session for a long time (the duration can be set), display updates are paused.xorgxrdp encoding CPU time and session network traffic are paused.
  • When users return and resume keyboard or mouse interaction, the session wakes up and immediately displays the latest screen.

Notes

A companion xrdp PR adds the sesman configuration and passes the configured timeout to xorgxrdp.
xrdp neutrinolabs/xrdp#3775

Is this optimization plan feasible?

@tsz8899 tsz8899 changed the title Pause display updates for idle sessions Suspend screen rendering for inactive sessions to reduce server CPU usage and network traffic Mar 27, 2026
Signed-off-by: tsz8899 <tsz8899@outlook.com>
@tsz8899 tsz8899 force-pushed the feature/screensleep-logic branch from a504617 to 0ef4ffa Compare April 1, 2026 00:33
@tsz8899
Copy link
Copy Markdown
Contributor Author

tsz8899 commented Apr 1, 2026

@metalefty

The feature is controlled by environment variables and does not rely on adding new xrdp configuration items. Currently, the following two environment variables in sesman.ini can be used to enable the feature:

[SessionVariables]
XRDP_SCREEN_SLEEP_TIME=15
XRDP_SCREEN_SLEEP_MODE=black

Where:

  • XRDP_SCREEN_SLEEP_TIME
    Specifies how long the session must be idle before entering sleep, in minutes.
    The valid range is 0..10080.
    0 means the feature is disabled.

  • XRDP_SCREEN_SLEEP_MODE
    Specifies how the screen is displayed during sleep.
    Currently supported:

    • black (default)
    • last
    • refresh:n

The behavior of each mode is as follows:

  • black
    When entering sleep, the client displays a black screen.

  • last
    When entering sleep, the client keeps the last frame unchanged, similar to RDP suppress output.

  • refresh:n
    When entering sleep, the screen content can be automatically refreshed at a fixed interval.
    For example:

XRDP_SCREEN_SLEEP_MODE=refresh:5

This means that after entering sleep, the latest screen content will be refreshed automatically every 5 minutes.

A complete example is as follows:

[SessionVariables]
XRDP_SCREEN_SLEEP_TIME=15
XRDP_SCREEN_SLEEP_MODE=refresh:5

This means:

  • If the user has no mouse or keyboard input for 15 consecutive minutes, the screen will enter sleep
  • During sleep, continuous image updates stop
  • The current screen content is automatically refreshed every 5 minutes
  • Once the user inputs again, sleep ends immediately and normal display resumes

If you want the screen to turn black directly after sleep, you can set:

[SessionVariables]
XRDP_SCREEN_SLEEP_TIME=15
XRDP_SCREEN_SLEEP_MODE=black

If you want the lightest-weight mode, you can use:

[SessionVariables]
XRDP_SCREEN_SLEEP_TIME=5
XRDP_SCREEN_SLEEP_MODE=last
  • This feature is disabled by default and only takes effect when XRDP_SCREEN_SLEEP_TIME is explicitly set.

@tsz8899
Copy link
Copy Markdown
Contributor Author

tsz8899 commented Apr 16, 2026

The feature has been running in the production environment for three weeks, and users are using it normally.

With a 5-minute sleep configuration, a single server can trigger sleep more than 400 times per day, reducing CPU and network usage time by over 7,000 minutes.

4月 16 08:20:22 node7 xrdp-sesman[1595]: (II) rdpScreenSleepWake: [Session /var/run/xrdp/5505/xrdp_display_X11-60] waking after 0 min 12 sec, reason=user reinput
4月 16 08:22:31 node7 xrdp-sesman[1595]: (II) rdpScreenSleepWake: [Session /var/run/xrdp/5156/xrdp_display_X11-61] waking after 8 min 8 sec, reason=user reinput
4月 16 08:23:32 node7 xrdp-sesman[1595]: (II) rdpScreenSleepWake: [Session /var/run/xrdp/4989/xrdp_display_X11-64] waking after 16 min 50 sec, reason=user reinput
4月 16 08:27:14 node7 xrdp-sesman[1595]: (II) rdpScreenSleepWake: [Session /var/run/xrdp/5038/xrdp_display_X11-62] waking after 6 min 17 sec, reason=user reinput
4月 16 08:28:22 node7 xrdp-sesman[1595]: (II) rdpScreenSleepWake: [Session /var/run/xrdp/5156/xrdp_display_X11-61] waking after 0 min 39 sec, reason=user reinput
4月 16 08:28:30 node7 xrdp-sesman[1595]: (II) rdpScreenSleepWake: [Session /var/run/xrdp/5790/xrdp_display_X11-75] waking after 3 min 43 sec, reason=user reinput
4月 16 08:29:09 node7 xrdp-sesman[1595]: (II) rdpScreenSleepWake: [Session /var/run/xrdp/5682/xrdp_display_X11-71] waking after 7 min 20 sec, reason=user reinput
4月 16 08:29:41 node7 xrdp-sesman[1595]: (II) rdpScreenSleepWake: [Session /var/run/xrdp/5083/xrdp_display_X11-65] waking after 4 min 50 sec, reason=user reinput
4月 16 08:30:20 node7 xrdp-sesman[1595]: (II) rdpScreenSleepWake: [Session /var/run/xrdp/5475/xrdp_display_X11-69] waking after 4 min 21 sec, reason=user reinput
4月 16 08:30:45 node7 xrdp-sesman[1595]: (II) rdpScreenSleepWake: [Session /var/run/xrdp/1458/xrdp_display_X11-66] waking after 22 min 5 sec, reason=user reinput
4月 16 08:32:08 node7 xrdp-sesman[1595]: (II) rdpScreenSleepWake: [Session /var/run/xrdp/6171/xrdp_display_X11-79] waking after 4 min 48 sec, reason=user reinput
4月 16 08:37:06 node7 xrdp-sesman[1595]: (II) rdpScreenSleepWake: [Session /var/run/xrdp/5178/xrdp_display_X11-72] waking after 13 min 54 sec, reason=user reinput
4月 16 08:38:24 node7 xrdp-sesman[1595]: (II) rdpScreenSleepWake: [Session /var/run/xrdp/5156/xrdp_display_X11-61] waking after 5 min 1 sec, reason=user reinput
4月 16 08:38:44 node7 xrdp-sesman[1595]: (II) rdpScreenSleepWake: [Session /var/run/xrdp/5246/xrdp_display_X11-68] waking after 22 min 29 sec, reason=user reinput
4月 16 08:40:00 node7 xrdp-sesman[1595]: (II) rdpScreenSleepWake: [Session /var/run/xrdp/3398/xrdp_display_X11-78] waking after 12 min 16 sec, reason=user reinput
4月 16 08:42:04 node7 xrdp-sesman[1595]: (II) rdpScreenSleepWake: [Session /var/run/xrdp/5706/xrdp_display_X11-77] waking after 14 min 3 sec, reason=user reinput
4月 16 08:42:28 node7 xrdp-sesman[1595]: (II) rdpScreenSleepWake: [Session /var/run/xrdp/5505/xrdp_display_X11-60] waking after 6 min 31 sec, reason=user reinput
4月 16 08:43:14 node7 xrdp-sesman[1595]: (II) rdpScreenSleepWake: [Session /var/run/xrdp/5380/xrdp_display_X11-70] waking after 22 min 17 sec, reason=user reinput

@metalefty
Copy link
Copy Markdown
Member

Thanks for the confirmation on your production environment. It is very helpful.

We've been focused on vulnerability issues, so it will take some time before we can look at this. Hold on.

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.

2 participants