TurboVNC / turbovnc

Main TurboVNC repository
https://TurboVNC.org
GNU General Public License v2.0
746 stars 136 forks source link

Mouse delay is very serious. #368

Closed binzhai closed 5 months ago

binzhai commented 1 year ago

When I use Turbo VNC to play War3 game remotely, there is a serious mouse delay. By adding logs, I found that it takes 15 milliseconds for a mouse event to be transmitted from the VNC Viewer to the VNC Server.The higher the game resolution, the greater the mouse delay.Are there any optimization methods for this issue?

binzhai commented 1 year ago

If I install TurboVNC Viewer and Server on the same physical machine, is there a way to directly read mouse events from /dev/input instead of sending them from TurboVNC Viewer to Server? This way, mouse event processing would be much faster.

dcommander commented 1 year ago

TurboVNC is meant to be a remote display solution, so hacks for reading mouse events directly from the local device wouldn't make sense for the most common use case. TurboVNC's mouse handling is dead simple. When the TurboVNC Viewer gets notified by the client O/S that a mouse button or motion event has occurred, the viewer immediately translates the mouse event into an RFB mouse event and sends it to the VNC server. The TurboVNC Server, however, is single-threaded like all X servers are, so whether or not it can immediately read the mouse event and deliver it to X clients depends on how busy the X server is. If you are running the game using VirtualGL and a decently fast GPU, then TurboVNC should be able to keep up with no problem. If you are running the game using software OpenGL, however, then that will definitely bog down the TurboVNC X server. The rate at which TurboVNC can deliver mouse events from client to TurboVNC Server to X clients is subject to the client O/S's mouse sampling rate, the network latency, and the X server load, but 15 ms is definitely not expected on a LAN. If you are using a Linux or Windows client and VirtualGL is set up on the server, then you can test the mouse delay in isolation by running vglrun /opt/VirtualGL/bin/glxspheres64 -i in the TurboVNC session and then using tcbench (in the VirtualGL packages) on the client to drive mouse events continuously into the TurboVNC Viewer while measuring the frame rate. If you are observing a 15 ms delay at the low level-- that is, if it is not specific to the game-- then it should reflect in the frame rate observed through tcbench when performing the aforementioned tests.

If you are using VirtualGL, then I can think of a couple of other possible causes, so do let me know whether that is the case.

binzhai commented 1 year ago

Thank you for your prompt response. Currently, I am using turbo vnc server in Docker and turbo vnc viewer on the host, so turbo vnc server and turbo vnc viewer are on the same machine. Also, I am using virtual GL. What is the reason for the delay issue? Or can the server directly access the mouse device?

binzhai commented 1 year ago

If there is no change in the VNC screen, the mouse will not delay. However, when playing games or constantly rendering the screen, the mouse will experience significant delays

dcommander commented 1 year ago

I don't know. You could try setting a frame rate limit in VGL (VGL_FPS=60, for instance) and see if that helps. I haven't ever seen this issue, but I also don't use VGL/TurboVNC for gaming. Do you see the same issue with all games or just this one?

binzhai commented 1 year ago

Yes, I have tried many games that have this issue

dcommander commented 1 year ago

In https://github.com/TurboVNC/turbovnc/issues/368#issuecomment-1525671040, I specified the tests that you should run in order to narrow down the cause of the delay. I cannot proceed without knowing the outcome of those tests.