mviereck / x11docker

Run GUI applications and desktops in docker and podman containers. Focus on security.
MIT License
5.62k stars 378 forks source link

why is xpra slow on your system? #356

Closed totaam closed 3 years ago

totaam commented 3 years ago

Hi,

I was trying to figure out why you have reported that xpra was slow and found that it was blazingly fast instead!? I start an X11 display first to mimic what x11docker does, and also to exclude this heavy setup cost from the timings.

This is the command I am using:

xpra start \
    --bind-tcp=0.0.0.0:10000 :10 \
    --no-daemon --systemd-run=no --start-via-proxy=no \
    --start-new-commands=no \
    --dbus-launch=no --dbus-control=no --dbus-proxy=no \
    -d all |& tee log

This includes full debug logging, which does slow things down.

The key entries I am seeing are:

2021-05-14 20:45:52,674 setting up tcp sockets: (('0.0.0.0', 10000), {})
2021-05-14 20:45:52,677 X11 display is ready
2021-05-14 20:45:52,712 GDK can access the display
2021-05-14 20:45:52,717 start_dbus(no) disabled
2021-05-14 20:45:52,773 GTKServerBase.__init__()
2021-05-14 20:45:52,885 init_clipboard() enabled=True, filter file=
2021-05-14 20:45:52,894 threaded_init() servercore end
2021-05-14 20:45:53,021 running <bound method ServerCore.run of <server.XpraServer object at 0x7f463cb7db80 (xpra+x11+server+XpraServer at 0x56515bb99d20)>>

So the full server started in 350 milliseconds with the latest 4.2 pre release builds - that's so fast that trying to trim it further is just not worth it.

And this is on a 6 year old Fedora 34 system, which wasn't even particularly fast when I first got it - but it does have a decent NVME drive.

On a Debian Bullseye VM with a single CPU core assigned, it takes a little bit longer: 500 to 600ms.

If I run sync; echo 3 > /proc/sys/vm/drop_caches before running xpra, things take a bit longer: up to 1 full second slower. In particular GTK initialization alone can add 500ms. (the part just before GDK can access the display)

So, if your findings differ wildly from this, please do share your full -d all server log so we can figure out why it is slow on your system.

mviereck commented 3 years ago

I was trying to figure out why you have reported that xpra was slow and found that it was blazingly fast instead!?

When I once reported that, you gave me some hints that helped a lot. The faremost greatest impact had one environment variable that disabled some xdg icon setup. Its influence wasn't obvious in the logs. Though, yet I am not sure which variable it was. It should disable some fallback check. IIRC it was XPRA_XDG_LOAD_GLOB=0.

x11docker sets:

  NO_AT_BRIDGE=1 \\
  XPRA_EXPORT_ICON_DATA=0 \\
  XPRA_EXPORT_XDG_MENU_DATA=0 \\
  XPRA_ICON_OVERLAY=0 \\
  XPRA_MENU_ICONS=0 \\
  XPRA_UINPUT=0 \\
  XPRA_XDG_EXPORT_ICONS=0 \\
  XPRA_XDG_LOAD_GLOB=0 

The startup time is quite good now, less than two seconds. From x11docker logs: Starting server:

x11docker [17:01:53,993]: Starting Xpra server
2021-05-14 17:01:54,959 pointer device emulation using XTest

Last line of client:

2021-05-14 17:01:56,567 client   1 @01.747 running

Full server log of x11docker --xpra:

x11docker [17:01:53,993]: Starting Xpra server
2021-05-14 17:01:54,959 pointer device emulation using XTest
2021-05-14 17:01:54,983 Warning: no XShm support on display :109
2021-05-14 17:01:55,003 Warning: socket directory '/home/lauscher/.cache/x11docker/xonly-04509904388'
2021-05-14 17:01:55,003  expected permissions 0o700 but found 0o755
2021-05-14 17:01:55,004 created unix domain socket '/home/lauscher/.cache/x11docker/xonly-04509904388/debianlaptop-109'
2021-05-14 17:01:55,007 xvfb pid not found

(Xpra:31703): Gtk-CRITICAL **: 17:01:55.253: gtk_widget_realize: assertion 'widget->priv->anchored || GTK_IS_INVISIBLE (widget)' failed
2021-05-14 17:01:55,306 xpra is ready.
2021-05-14 17:01:55,308 xpra X11 seamless version 4.2-r29076 (gddb99ea17) 64-bit
2021-05-14 17:01:55,394 7.7GB of system memory
2021-05-14 17:01:55,519  uid=1000 (lauscher), gid=1000 (lauscher)
2021-05-14 17:01:55,519  running with pid 31703 on Linux Debian testing bullseye
2021-05-14 17:01:55,520  connected to X11 display :109 with 24 bit colors
2021-05-14 17:01:56,233 New unix-domain connection received
2021-05-14 17:01:56,233  on '/home/lauscher/.cache/x11docker/xonly-04509904388/debianlaptop-109'
2021-05-14 17:01:56,238 Handshake complete; enabling connection
2021-05-14 17:01:56,255  mmap is enabled using 256MB area in /run/user/1000/xpra/xpra.s9n5y0ai.mmap
2021-05-14 17:01:56,257 Python/GTK3 Linux Debian testing bullseye x11 client version 4.2-r29076 64-bit
2021-05-14 17:01:56,258  OpenGL is enabled with NVA5
2021-05-14 17:01:56,258  connected from 'debianlaptop' as 'lauscher' - 'Lauscher'
2021-05-14 17:01:56,261 setting key repeat rate from client: 500ms delay / 37ms interval
2021-05-14 17:01:56,264 setting keymap: rules=evdev, model=a4techKB21, layout=de
2021-05-14 17:01:56,303 setting keyboard layout to 'de'
2021-05-14 17:01:56,535  client root window size is 1600x900 with 1 display:
2021-05-14 17:01:56,536   :0.0 (423x238 mm - DPI: 96x96) workarea: 1563x864 at 37x36
2021-05-14 17:01:56,536     LEN LVDS-1 (344x193 mm - DPI: 118x118)
2021-05-14 17:01:56,538 cannot find a temporary resolution for Xinerama workaround!
2021-05-14 17:01:56,540 server virtual display now set to 1600x900
2021-05-14 17:01:56,546  automatic picture encoding enabled, also available:
2021-05-14 17:01:56,546   rgb24, rgb32
2021-05-14 17:01:56,563 client   1 @01.733 Xpra X11 seamless server version 4.2-r29076 64-bit
2021-05-14 17:01:56,563 client   1 @01.734  running on Linux Debian testing bullseye
2021-05-14 17:01:56,564 client   1 @01.737 Attached to socket:///home/lauscher/.cache/x11docker/xonly-04509904388/debianlaptop-109
2021-05-14 17:01:56,564 client   1 @01.738  (press Control-C to detach)
2021-05-14 17:01:56,566 DPI set to 100 x 100
2021-05-14 17:01:56,567 client   1 @01.747 running

Full client log:

x11docker [17:01:54,073]: Starting Xpra client
2021-05-14 17:01:54,818 Xpra GTK3 X11 client version 4.2-r29076 (gddb99ea17) 64-bit
2021-05-14 17:01:55,054  running on Linux Debian testing bullseye
2021-05-14 17:01:55,059  window manager is 'Xfwm4'
2021-05-14 17:01:55,274 created unix domain socket '/run/user/1000/xpra/clients/debianlaptop-31752'
2021-05-14 17:01:55,483 No OpenGL_accelerate module loaded: No module named 'OpenGL_accelerate'
2021-05-14 17:01:55,981 OpenGL enabled with NVA5
2021-05-14 17:01:56,186  keyboard settings: rules=evdev, model=a4techKB21, layout=de
2021-05-14 17:01:56,218  desktop size is 1600x900 with 1 screen:
2021-05-14 17:01:56,219   :0.0 (423x238 mm - DPI: 96x96) workarea: 1563x864 at 37x36
2021-05-14 17:01:56,219     LEN LVDS-1 (344x193 mm - DPI: 118x118)
2021-05-14 17:01:56,551 enabled fast mmap transfers using 256MB shared memory area
2021-05-14 17:01:56,551 enabled remote logging
2021-05-14 17:01:56,552 Xpra X11 seamless server version 4.2-r29076 64-bit
2021-05-14 17:01:56,553  running on Linux Debian testing bullseye
2021-05-14 17:01:56,556 Attached to socket:///home/lauscher/.cache/x11docker/xonly-04509904388/debianlaptop-109
2021-05-14 17:01:56,557  (press Control-C to detach)

xpra server command:

env XAUTHORITY=/home/lauscher/.cache/x11docker/xonly-05353863421/share/Xauthority.client \
  GDK_BACKEND=x11 \
  NO_AT_BRIDGE=1 \
  XPRA_EXPORT_ICON_DATA=0 \
  XPRA_EXPORT_XDG_MENU_DATA=0 \
  XPRA_ICON_OVERLAY=0 \
  XPRA_MENU_ICONS=0 \
  XPRA_UINPUT=0 \
  XPRA_XDG_EXPORT_ICONS=0 \
  XPRA_XDG_LOAD_GLOB=0 \
   xpra start :110 --use-display \
  --csc-modules=none \
  --encodings=rgb \
  --microphone=no \
  --notifications=no \
  --pulseaudio=no \
  --socket-dirs='/home/lauscher/.cache/x11docker/xonly-05353863421' \
  --speaker=no \
  --start-via-proxy=no \
  --webcam=no \
  --xsettings=no \
  --clipboard=yes\
  --dbus-proxy=no \
  --daemon=no \
  --fake-xinerama=no \
  --file-transfer=off \
  --html=off \
  --opengl=noprobe \
  --mdns=no \
  --printing=no \
  --session-name='xonly' \
  --start-new-commands=no \
  --systemd-run=no \
  --video-encoders=none \
  --dpi='96'

xpra client command:

env DISPLAY=:0.0 XAUTHORITY=/home/lauscher/.cache/x11docker/xonly-05353863421/Xauthority.host.0-0 \
  XSOCKET=/tmp/.X11-unix/X0 \
  XDG_RUNTIME_DIR=/run/user/1000 \
  NO_AT_BRIDGE=1 \
  XPRA_EXPORT_ICON_DATA=0 \
  XPRA_EXPORT_XDG_MENU_DATA=0 \
  XPRA_ICON_OVERLAY=0 \
  XPRA_MENU_ICONS=0 \
  XPRA_UINPUT=0 \
  XPRA_XDG_EXPORT_ICONS=0 \
  XPRA_XDG_LOAD_GLOB=0 \
   xpra attach :110 \
  --csc-modules=none \
  --encodings=rgb \
  --microphone=no \
  --notifications=no \
  --pulseaudio=no \
  --socket-dirs='/home/lauscher/.cache/x11docker/xonly-05353863421' \
  --speaker=no \
  --start-via-proxy=no \
  --webcam=no \
  --xsettings=no \
  --clipboard=no \
  --compress=0 \
  --modal-windows=no \
  --opengl=auto \
  --quality=100 \
  --video-decoders=none

I've tested your command example and found that at least the server startup is pretty fast here, too, even without all my additional settings. Maybe I can/should drop several of them:

lauscher@debianlaptop:~/tmp$ head log
2021-05-14 17:23:37,673 setting up tcp sockets: (('0.0.0.0', 10000), {})
2021-05-14 17:23:37,673 <socket.socket fd=3, family=AddressFamily.AF_INET, type=SocketKind.SOCK_STREAM, proto=0, laddr=('0.0.0.0', 0)>.bind(('0.0.0.0', 10000))
2021-05-14 17:23:37,673 tcp: 0.0.0.0:10000 : <module 'socket' from '/usr/lib/python3.9/socket.py'>
2021-05-14 17:23:37,673 created tcp socket '0.0.0.0:10000'
2021-05-14 17:23:37,674 setting up ssl sockets: 
2021-05-14 17:23:37,674 setting up ssh sockets: 
2021-05-14 17:23:37,674 setting up ws sockets: 
2021-05-14 17:23:37,674 setting up wss sockets: 
2021-05-14 17:23:37,674 setting up rfb sockets: 
2021-05-14 17:23:37,674 setting up UDP sockets: 

lauscher@debianlaptop:~/tmp$ tail log
2021-05-14 17:23:48,149 add_address(172.17.0.1, 22, AddressFamily.AF_INET) ports={22}
2021-05-14 17:23:48,150 ZeroconfPublisher(b'\xac\x11\x00\x01', '172.17.0.1', 22, 'debianlaptop :10 (ssh-2)', '_xpra._tcp.', {'display': ':10', 'username': 'lauscher', 'uuid': '9e998f4c0f624bc5be1aebc88b79a280', 'platform': 'linux', 'type': 'seamless', 'clients': 0, 'mode': 'ssh'})
2021-05-14 17:23:48,150 ServiceInfo((), {'type_': '_xpra._tcp.local.', 'name': 'debianlaptop-10-ssh-2._xpra._tcp.local.', 'port': 22, 'properties': {'display': ':10', 'username': 'lauscher', 'uuid': '9e998f4c0f624bc5be1aebc88b79a280', 'platform': 'linux', 'type': 'seamless', 'clients': '0', 'mode': 'ssh'}, 'addresses': [b'\xac\x11\x00\x01']})=ServiceInfo(type='_xpra._tcp.local.', name='debianlaptop-10-ssh-2._xpra._tcp.local.', addresses=[b'\xac\x11\x00\x01'], port=22, weight=0, priority=0, server='debianlaptop-10-ssh-2._xpra._tcp.local.', properties={'display': ':10', 'username': 'lauscher', 'uuid': '9e998f4c0f624bc5be1aebc88b79a280', 'platform': 'linux', 'type': 'seamless', 'clients': '0', 'mode': 'ssh'})
2021-05-14 17:23:48,150 vethe338b84: {}
2021-05-14 17:23:53,116 Worker_Thread.run() calling <bound method ServerCore.do_print_run_info of <server.XpraServer object at 0x7fc040d27280 (xpra+x11+server+XpraServer at 0x1fa3340)>> (queue size=0)
2021-05-14 17:23:53,116 xpra X11 seamless version 4.2-r29076 (gddb99ea17) 64-bit
2021-05-14 17:23:53,129  uid=1000 (lauscher), gid=1000 (lauscher)
2021-05-14 17:23:53,129  running with pid 38940 on Linux Debian testing bullseye
2021-05-14 17:23:53,130  connected to X11 display :10 with 24 bit colors
2021-05-14 17:24:38,215 touch_sockets() unix socket paths=['/run/user/1000/xpra/debianlaptop-10', '/home/lauscher/.xpra/debianlaptop-10']

However, xpra attach :10 is rather slow (disabled -d in server):

$ xpra attach :10
2021-05-14 17:35:01,945 Xpra GTK3 X11 client version 4.2-r29076 (gddb99ea17) 64-bit
2021-05-14 17:35:02,131  running on Linux Debian testing bullseye
2021-05-14 17:35:02,132  window manager is 'Xfwm4'
2021-05-14 17:35:04,828 GStreamer version 1.18.4 for Python 3.9.2 64-bit
2021-05-14 17:35:05,057 created unix domain socket '/run/user/1000/xpra/clients/debianlaptop-41983'
2021-05-14 17:35:05,196 No OpenGL_accelerate module loaded: No module named 'OpenGL_accelerate'
2021-05-14 17:35:05,557 OpenGL enabled with NVA5
2021-05-14 17:35:05,980  keyboard settings: rules=evdev, model=a4techKB21, layout=de
2021-05-14 17:35:06,001  desktop size is 1600x900 with 1 screen:
2021-05-14 17:35:06,001   :0.0 (423x238 mm - DPI: 96x96) workarea: 1563x864 at 37x36
2021-05-14 17:35:06,001     LEN LVDS-1 (344x193 mm - DPI: 118x118)
2021-05-14 17:35:06,186 enabled fast mmap transfers using 256MB shared memory area
2021-05-14 17:35:06,187 enabled remote logging
2021-05-14 17:35:06,187 Xpra X11 seamless server version 4.2-r29076 64-bit
2021-05-14 17:35:06,188  running on Linux Debian testing bullseye
2021-05-14 17:35:06,202 Attached to socket:///run/user/1000/xpra/debianlaptop-10
2021-05-14 17:35:06,203  (press Control-C to detach)

2021-05-14 17:35:06,238 running
2021-05-14 17:35:06,668 audio playback found 2 audio output devices:
2021-05-14 17:35:06,669 audio playback  * Internes Audio Analog Stereo
2021-05-14 17:35:06,669 audio playback    alsa_output.pci-0000_00_1b.0.analog-stereo
2021-05-14 17:35:06,669 audio playback  * GT216 HDMI Audio Controller
2021-05-14 17:35:06,669 audio playback    alsa_card.pci-0000_01_00.1
2021-05-14 17:35:06,669 audio playback  to select a specific one,
2021-05-14 17:35:06,669 audio playback  use the environment variable 'XPRA_PULSE_SINK_DEVICE_NAME'
2021-05-14 17:35:06,669 audio playback using default pulseaudio device
2021-05-14 17:35:07,207 audio playback using 'opus' audio codec

Other than at the time I asked you, the environment variables make not great difference now. Though, meanwhile xpra and debian testing got several updates that might make a difference. Also I should note that I transferred the hard drive with system into another old laptop. Especially XPRA_XDG_LOAD_GLOB=0 saves one second here, down from 5s to 4s:

$ NO_AT_BRIDGE=1   XPRA_EXPORT_ICON_DATA=0   XPRA_EXPORT_XDG_MENU_DATA=0   XPRA_ICON_OVERLAY=0   XPRA_MENU_ICONS=0   XPRA_UINPUT=0   XPRA_XDG_EXPORT_ICONS=0   XPRA_XDG_LOAD_GLOB=0  xpra attach :10
2021-05-14 18:58:10,414 Xpra GTK3 X11 client version 4.2-r29076 (gddb99ea17) 64-bit
2021-05-14 18:58:10,586  running on Linux Debian testing bullseye
2021-05-14 18:58:10,587  window manager is 'Xfwm4'
2021-05-14 18:58:13,112 GStreamer version 1.18.4 for Python 3.9.2 64-bit
2021-05-14 18:58:13,344 created unix domain socket '/run/user/1000/xpra/clients/debianlaptop-57157'
2021-05-14 18:58:13,476 No OpenGL_accelerate module loaded: No module named 'OpenGL_accelerate'
2021-05-14 18:58:13,806 OpenGL enabled with NVA5
2021-05-14 18:58:14,206  keyboard settings: rules=evdev, model=a4techKB21, layout=de
2021-05-14 18:58:14,244  desktop size is 1600x900 with 1 screen:
2021-05-14 18:58:14,245   :0.0 (423x238 mm - DPI: 96x96) workarea: 1563x864 at 37x36
2021-05-14 18:58:14,245     LEN LVDS-1 (344x193 mm - DPI: 118x118)
2021-05-14 18:58:14,337 enabled fast mmap transfers using 256MB shared memory area
2021-05-14 18:58:14,338 enabled remote logging
2021-05-14 18:58:14,339 Xpra X11 seamless server version 4.2-r29076 64-bit
2021-05-14 18:58:14,339  running on Linux Debian testing bullseye
2021-05-14 18:58:14,354 Attached to socket:///run/user/1000/xpra/debianlaptop-10
2021-05-14 18:58:14,355  (press Control-C to detach)

2021-05-14 18:58:14,380 running

The faster startup of xpra in x11docker at about 2s will be caused by some of the several options. I would have to track down which ones make a significant difference now.

In early days I had xpra startup times at about 15s. Now I am at 2s what is great. Setting only XPRA_XDG_LOAD_GLOB=0 is at about 4s, still good.

So, if your findings differ wildly from this, please do share your full -d all server log so we can figure out why it is slow on your system.

The server debug log file: server.log

I've attached a log file for xpra attach :10 -d all, too, just in case. I had to interrupt with CTRL+C because it did not stop to print messages. client.log

totaam commented 3 years ago

OK, so it's fast enough then, great. I'm closing this issue.

From your log. The client takes 5 seconds to get to the point where it starts receiving data from the server. It is a bit slower than the server because of:

FYI: with newer versions, you can start the client in parallel with the server. The client will just wait for the server socket to show up. This can save time. In particular the opengl probing happens before the connection is established. The client will just print:

xpra attach :10
(..)
server socket for display :10 not found
 waiting up to 20 seconds