google-deepmind / mujoco

Multi-Joint dynamics with Contact. A general purpose physics simulator.
https://mujoco.org
Apache License 2.0
8.08k stars 807 forks source link

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

Open tqolf opened 1 week ago

tqolf commented 1 week ago

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

yuvaltassa commented 1 week ago

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

tqolf commented 1 week ago

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 commented 1 week ago

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 commented 1 week ago

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 commented 5 days ago

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

tqolf commented 5 days ago

Screencast from 2024年10月14日 21时30分15秒.webm

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

tqolf commented 5 days ago

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 commented 5 days ago

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 commented 5 days ago

@saran-t might be able to help

saran-t commented 4 days ago

What GPU are you using?

tqolf commented 4 days ago

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