Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Severe Lag When Dragging Chrome/Warp-Terminal Windows with Mujoco Simulate Viewer Open, Possibly Related to Rendering or V-Sync #2132

Open
2 tasks done
tqolf opened this issue Oct 11, 2024 · 11 comments
Assignees
Labels
bug Something isn't working

Comments

@tqolf
Copy link

tqolf commented Oct 11, 2024

Intro

Severe Lag and high CPU load

My setup

MuJoCo 2.3.3, Python
amd64, Linux/Ubuntu 22.04

What's happening? What did you expect?

  1. When running the simulation with no other actions, CPU usage stays around 2-10%, and dragging the built-in Ubuntu terminal is still very smooth.
  2. With the simulation running under default settings, dragging Chrome or Warp-Terminal results in CPU usage spiking to 80-100%, with severe lag. perf shows sched_yield accounting for over 80% of the CPU time.
  3. When running the simulation with Vertical Sync disabled, CPU usage reaches 100%, but the lag when dragging Chrome/Warp-Terminal improves significantly, though there is still noticeable lag at the beginning of the drag.

Steps for reproduction

See

Minimal model for reproduction

Maybe unrelated to the model.

Code required for reproduction

Maybe unrelated.

Confirmations

@tqolf tqolf added the bug Something isn't working label Oct 11, 2024
@yuvaltassa
Copy link
Collaborator

You are using a very old version. Does this also happen with latest MuJoCo?

@tqolf
Copy link
Author

tqolf commented Oct 11, 2024

Yeah, there is a plan to upgrade, but we are still working on migration. Currently, we want to first understand what is causing this phenomenon.

@tqolf
Copy link
Author

tqolf commented Oct 12, 2024

You are using a very old version. Does this also happen with latest MuJoCo?

I tried to upgrade, but the new code is very slow, elasped_time > 0.008

import mujoco
import mujoco.viewer

m = mujoco.MjModel.from_xml_path(xx)
d = mujoco.MjData(m)

viewer = viewer.launch_passive(m, d)
viewer.sync()

while viewer.is_running():
       last_time = time.time()
      # ...
      mujoco.mj_step(m, d)
      viewer.sync()

     elasped_time = time.time() - last_time
     if elasped_time < 0.001:
           await asyncio.sleep(0.001 - elasped_time)

@tqolf
Copy link
Author

tqolf commented Oct 12, 2024

You are using a very old version. Does this also happen with latest MuJoCo?

And I have tried the latest MuJoCo, Severe Lag still exists when I draging Chrome/Warp-Terminal.

@yuvaltassa
Copy link
Collaborator

Can you please post a video of what you're seeing?

@tqolf
Copy link
Author

tqolf commented Oct 14, 2024

Screencast.from.2024.10.14.21.30.15.webm

Can you please post a video of what you're seeing?

@tqolf
Copy link
Author

tqolf commented Oct 14, 2024

You are using a very old version. Does this also happen with latest MuJoCo?

I tried to upgrade, but the new code is very slow, elasped_time > 0.008

import mujoco
import mujoco.viewer

m = mujoco.MjModel.from_xml_path(xx)
d = mujoco.MjData(m)

viewer = viewer.launch_passive(m, d)
viewer.sync()

while viewer.is_running():
       last_time = time.time()
      # ...
      mujoco.mj_step(m, d)
      viewer.sync()

     elasped_time = time.time() - last_time
     if elasped_time < 0.001:
           await asyncio.sleep(0.001 - elasped_time)

@yuvaltassa And How about this? When I use the old version, it's no need to call view.sync(). Also, the C++ version didn't require it and ran smoothly. Does python sync API synchronize all the data for rendering? Are there any alternative optimization methods?

@tqolf
Copy link
Author

tqolf commented Oct 14, 2024

Screencast.from.2024.10.14.21.30.15.webm

Can you please post a video of what you're seeing?

And I use perf to analyze performance, sched_yield accounting for over 80% of the CPU time.

@yuvaltassa
Copy link
Collaborator

@saran-t might be able to help

@saran-t
Copy link
Member

saran-t commented Oct 15, 2024

What GPU are you using?

@tqolf
Copy link
Author

tqolf commented Oct 16, 2024

What GPU are you using?

CPU: 13th Gen Intel(R) Core(TM) i7-13700K
GPU: NVIDIA GeForce RTX 4060

And I think GPU is not releated to this problem, 'cause sched_yield too frequently and GPU usage is very slow

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants