CesiumGS / CesiumGS/cesium-unity
Investigate Shared Resource Locking and Stuttering with Multiple Unity Clients
- Dominant language
- C#
- Stars
- 535
- Forks
- 132
- Avg merge
- 6h 45m
- Merged PRs (30d)
- 1
Description
We have a multiplayer architecture with a server and multiple clients (Unity exe application) all running on the same Windows machine. Each client implementing its own Cesium plugin instance. Each client is its own process with its own heap and Cesium instance.
We have observed severe stuttering and slowdowns in 3D tile loading whenever we run multiple client instances simultaneously (starting from the second client).
This issue appears as soon as another client is instantiated on the same machine, even if tile-loading parameters are tuned to extremely minimal values:
preloadAncestors = false;
preloadSiblings = false;
forbidHoles = true;
maximumCachedBytes = 0;
maximumSimultaneousTileLoads = 1;
loadingDescendantLimit = 1;
enableFogCulling = false;
enableFrustumCulling = true;
enforceCulledScreenSpaceError = false;
generateSmoothNormals = false;
createPhysicsMeshes = false;
When using a single client, tile streaming is smooth and stable, regardless of these parameter settings. However, as soon as a second client is launched, stuttering appears immediately, no matter the parameter tuning or tile source.
**Observed Issues & Debugging Steps Taken:**
- Even with maximumCachedBytes=0, a Cache.sqlite file is created.
- Disabled optional features like preloadAncestors, preloadSiblings, generateSmoothNormals, createPhysicsMeshes, etc.
- Tested against different data sources:
- Our custom tilesets.
- Google Photorealistic 3D tiles.
- Tested on different machines.
- Tested using Cesium for Unity version 1.16.0.
**Key Findings:**
- Stuttering only occurs when multiple clients are running simultaneously.
- Even extremely conservative tile-loader settings do not resolve the issue.
- The Cache.sqlite file is still created even if maximumCachedBytes=0 - Suggests that Cesium’s SQL cache might be shared or locking across clients (can be something else as well but this is our best guess), despite each client using its own Cesium plugin instance.
- Performance bottlenecks have been ruled out, the issue appears to be a synchronization or locking issue in Cesium's caching or tile loader internals making Unity main thread to stutter.
We’d appreciate your thoughts on this phenomenon and what might cause the stuttering.
It’s definitely not a straightforward performance issue, it looks more like shared resource contention at the Cesium native level.
Contributor guide
Assessment
This issue has not been assessed yet.