Search Unity

Unity 2021.2: Dedicated Server target and stripping optimizations now live! Please share feedback!

Discussion in 'Multiplayer' started by UnityGio, Jul 20, 2021.

Thread Status:
Not open for further replies.
  1. cristianm_unity

    cristianm_unity

    Unity Technologies

    Joined:
    Oct 16, 2018
    Posts:
    259
    Hey @vis2k, could you please provide some details about the test case so we can try to reproduce it and investigate? or even better, do you already have a project we could check?
     
  2. mischa2k

    mischa2k

    Joined:
    Sep 4, 2015
    Posts:
    4,347
    Reported it as IN-3335 in May :)
     
  3. AlexanderArbuznikov

    AlexanderArbuznikov

    Joined:
    Nov 18, 2021
    Posts:
    4
    Any news on the issue? Is it possible to make Dedicated Server builds on UCB now?
     
  4. cristianm_unity

    cristianm_unity

    Unity Technologies

    Joined:
    Oct 16, 2018
    Posts:
    259
    Could you please open a support ticket with Cloud Build? that could help properly prioritize this on their side.
     
  5. iCrise

    iCrise

    Joined:
    Jun 6, 2022
    Posts:
    7
    How to build for a Dedicated Server an android/ios project ?
     
  6. cristianm_unity

    cristianm_unity

    Unity Technologies

    Joined:
    Oct 16, 2018
    Posts:
    259
    Dedicated Server is built as any other platform. So you can:
    1. Download the Dedicated Server module for the target you want to build to (Linux, Mac, Windows).
    2. Switch to Dedicated Server target in the build settings. Take into account that Dedicated Server targets Desktop platforms, some adjustments might be required for your project.
    3. Hit the Build button.
     
  7. VRGroupRWTH

    VRGroupRWTH

    Joined:
    Oct 23, 2021
    Posts:
    10
    Hey all,
    Are there any further plans to include shader stripping? Shader variants are absolutely mad right now in general, would be great to circumvent those issues in server builds at least.
    Feels a bit strange to compile actual billions of variants just to never load them at all.
     
    andreyshade likes this.
  8. cristianm_unity

    cristianm_unity

    Unity Technologies

    Joined:
    Oct 16, 2018
    Posts:
    259
    We are working on providing more ways for you to better optimize the Dedicated Server builds, and yes, that includes shaders.
    That's all the details I can share for now :)
     
  9. iCrise

    iCrise

    Joined:
    Jun 6, 2022
    Posts:
    7
    upload_2022-8-25_19-52-58.png
    i did a little improvement for my builds, when i hit "Build Server", it automatcly build an linux build and switch to android when its finished :))
     
    cristianm_unity likes this.
  10. Karsten

    Karsten

    Joined:
    Apr 8, 2012
    Posts:
    187
    What is the current "official" method to find out at runtime if the app running is a server build or not ?
    I know the trick with the if (SystemInfo.graphicsDeviceName == null)
    but are there other ways ?
    Is Appliocation.isBatchMode still a thing ?
    is RuntimePlatform.LinuxServer RuntimePlatform.WindowsServer
    reliable ? the docs are hopeless little and strange there "in the server on Linux" ...
     
    Last edited: Aug 28, 2022
  11. NuclearCookieTF

    NuclearCookieTF

    Joined:
    Mar 29, 2021
    Posts:
    17
    I confirmed Application.isBatchMode still works in builds that are built with dedicated server
     
    Karsten likes this.
  12. cristianm_unity

    cristianm_unity

    Unity Technologies

    Joined:
    Oct 16, 2018
    Posts:
    259
    You can use the UNITY_SERVER define
     
  13. Karsten

    Karsten

    Joined:
    Apr 8, 2012
    Posts:
    187
    Thanks, but very ugly,defines clutter code and degrade readability they are disturbing similar to XML comments.
    I keep going with isBatchMode and Application.platform combination wrote my own methods , isSeverBuild, isClientBuild
     
  14. mischa2k

    mischa2k

    Joined:
    Sep 4, 2015
    Posts:
    4,347
    Any update on dedicated server builds being significantly slower than regular builds?

    M1 Macbook Pro, Unity 2021.3.8, IL2CPP, dedicated build with 100k entities.
    Connecting to it from Editor to show tick rate etc.
    14 Hz.
    2022-09-07 - remote control dedicated server mac 100k.png

    Here's the same project with a regular build and camera disabled:
    24 Hz.
    2022-09-07 - remote control regular build mac 100k.png
     
  15. SenseEater

    SenseEater

    Joined:
    Nov 28, 2014
    Posts:
    84
    What's up with 14hz vs 24hz?

    Also , have you tried profiling it to check the bottleneck ?
     
  16. TCROC

    TCROC

    Joined:
    Aug 15, 2015
    Posts:
    230
    Any update on this issue that @vis2k found?
     
    mischa2k likes this.
  17. cristianm_unity

    cristianm_unity

    Unity Technologies

    Joined:
    Oct 16, 2018
    Posts:
    259
    Hi all! Thanks for your patience on the Dedicated Server - Mac performance issue, this is the public issue tracker.
    It has been identified that it happens only on Apple Silicon machines and we are currently investigating the causes, I will let you know as soon as we have news.
     
    mischa2k likes this.
  18. Kamyker

    Kamyker

    Joined:
    May 14, 2013
    Posts:
    1,091
    I'll give you example, there's https://docs.unity3d.com/ScriptReference/AudioSource.GetSpectrumData.html api that requires sound to be played at the moment when method is used. Many rhythm games use it and there's no way to run it to prepare data before it's actually needed.
     
    Last edited: Sep 29, 2022
  19. JeroChan

    JeroChan

    Joined:
    Sep 27, 2022
    Posts:
    1
    Is there an optimization plan for Asset Bundles in subsequent versions?
     
  20. Flow-Fire-Games

    Flow-Fire-Games

    Joined:
    Jun 11, 2015
    Posts:
    305
    Had the same issue, all of our content is in Addressables.
    In the meantime I figured out a custom solution for building for servers.

    You'll need to fork the Unity package Scriptable Build Pipeline.
    In the file CalculateAssetDependencyData around line 300
    var includedObjects = ContentBuildInterface.GetPlayerObjectIdentifiersInAsset(asset, input.Target);
    the code returns an array of files to include.
    Using
    BuildCacheUtility.GetMainTypeForObject(includedObjects[index]);
    you can check the System.Type for Texture2D, AudioClip etc and replace the asset reference with an empty dummy Texture/etc.

    Few lines below
    ObjectIdentifier[] referencedObjects;
    requires the same treatment.

    It will fail some Asserts in the native building but works fine for us.
    Use some bool, for example CommandLineArgs, to enable/disable your stripping.
     
  21. cristianm_unity

    cristianm_unity

    Unity Technologies

    Joined:
    Oct 16, 2018
    Posts:
    259
    As I mentioned in a previous comment, we are working on providing more ways for you to better optimize the Dedicated Server builds. We know that Asset Bundles represent an important part of the workflow, so we are also looking into it. :)
     
    Vladnee likes this.
  22. Karsten

    Karsten

    Joined:
    Apr 8, 2012
    Posts:
    187
    which enumeration to use to build a linux dedicated server from a script containing BuildPipeline.BuildPlayer(....) in 2021.3x
    the docs contain things that dont exist like BuildTarget.LinuxHeadlessSimulation and other wild stuff
    Edit: I found a way using -> new BuildPlayerOptions{...} but the docs about programmatic builds really need some love
     
    Last edited: Oct 21, 2022
    cristianm_unity likes this.
  23. david_joo

    david_joo

    Joined:
    Feb 24, 2022
    Posts:
    3
    can i get a manual or document about this feature?
     
  24. ierostenko

    ierostenko

    Joined:
    Feb 3, 2022
    Posts:
    1
    Hello Unity Team!
    Could you please clarify couple details for me, in case of Dedicated Server build:
    1. Is GPU utilized? Or all processing occurs on CPU only?
    2. For Linux platform, do I need to have display and xserver installed?

    Thank you
     
  25. hugeandy

    hugeandy

    Joined:
    Nov 2, 2016
    Posts:
    131
    @cristianm_unity

    Do you have a tracker page for this? We're experiencing the same issue (we're very glad we found this forum page!) and would like to track the bug progress

    Cheers!
     
  26. cristianm_unity

    cristianm_unity

    Unity Technologies

    Joined:
    Oct 16, 2018
    Posts:
    259
  27. cristianm_unity

    cristianm_unity

    Unity Technologies

    Joined:
    Oct 16, 2018
    Posts:
    259
    Hello @ierostenko !

    GPU is not used. Dedicated Server will run only in the CPU.

    No display is required, when targeting to Dedicated Server platform, your game is meant to run as a console application.
     
    ierostenko likes this.
  28. unity_5B43D1FCB57EFE0F47FF

    unity_5B43D1FCB57EFE0F47FF

    Joined:
    Jan 4, 2022
    Posts:
    3
    I'm using a linux dedicated server build to control 2 clients for a game session after matchmaking. But, this is launching new server build instance on the server on every new room created. Hence, if there are 5 games running in parallel, server shows 5 linux build instances running in parallel in server using TOP command. Due to 1 server instance for each room, server occupies higher memory and I can't able to play more than 6 instances in parallel. Any solutions to optimise the memory would be appreciated.

    Server build contains only server related code, and assets used in the Prefabs having NetworkObject and It's running using batch-mode.

    Here is a snap of the process running in the server. It shows 2 instance running of the server build for 2 rooms created.
    Here, you can see 1 instance is using 13% of memory, hence I can't launch more then 6 instances.
     

    Attached Files:

  29. Claytonious

    Claytonious

    Joined:
    Feb 16, 2009
    Posts:
    904
    Have you profiled to see where the memory is being used in your build? Once you narrow down to something specific, THEN ask for help with those specifics.
     
  30. sebas77

    sebas77

    Joined:
    Nov 4, 2011
    Posts:
    1,643
    So did anyone found out what linuxheadlesssimulation actually is? :D
     
  31. BenjaminHugecalf

    BenjaminHugecalf

    Joined:
    Sep 22, 2021
    Posts:
    14
    Hi,

    We have noticed that our server builds are taking significantly longer to build than our actual game. The actual build time is around 19 minutes for the game, and around 40 for the server - is this a known issue/behaviour, or possibly linked to the mentioned incoming optimisations ? Bee itself takes about half an hour and doesn't seem to output logs.
     
  32. cristianm_unity

    cristianm_unity

    Unity Technologies

    Joined:
    Oct 16, 2018
    Posts:
    259
    Could you please report a bug (and let me know the bug id)?
     
  33. JoJoJoX

    JoJoJoX

    Joined:
    Jun 23, 2022
    Posts:
    52
    ??? Do server development(using Unity)?
     
  34. CDF

    CDF

    Joined:
    Sep 14, 2013
    Posts:
    1,311
    Want to ask this again, what’s the plan with Addressables/Asset bundles?

    will the dedicated build target ever support stripping assets that are addressable?

    for example, scenes that are marked addressable.
     
  35. cristianm_unity

    cristianm_unity

    Unity Technologies

    Joined:
    Oct 16, 2018
    Posts:
    259
    Hey! There has been some progress about this. In 2023.1 you will find a subtarget parameter when building Asset Bundles, see this.

    That means that you should be able to build Asset Bundles for dedicated server now (+2023.1) and they should also contain the Textures and Meshes optimizations.
     
    Claytonious and CDF like this.
  36. AllocTFP

    AllocTFP

    Joined:
    Mar 30, 2021
    Posts:
    3
    Is there any place for documentation that covers the whole system instead of having to crawl this thread for pieces of information? Like, what does it do exactly, what kinds of assets are affected in what way, how do you control those assets (like not stripping some of the textures), how do you use it in code for custom build scripts etc?
     
  37. MrG

    MrG

    Joined:
    Oct 6, 2012
    Posts:
    368
    So it's been over 18 months...when will shaders, lighting, audio files be stripped? When will we be able to configure exclusion of animations, terrain details (reduce do bare terrain collider and primitive colliders)?
     
  38. uthon

    uthon

    Joined:
    Nov 23, 2015
    Posts:
    14
    Found a bug and reported it (UNITY_SERVER isn't defined correctly in scripted builds); I thought there might be others interested here.

    --

    New Incident created: IN-32156 - UNITY_SERVER defined incorrectly in builds from scripts

    Description:

    The UNITY_SERVER symbol is not correctly defined when built using a build script.

    Steps to Reproduce:
    1. From the BUGTEST menu, choose "Build All"
    2. Open up the Build/Windows folder.
    3. Double click WindowsClient.exe. When it is done loading, exit with Alt-F4.
    4. Open the player log for the WindowsClient.exe, located at C:\Users\USER\AppData\LocalLow\DefaultCompany\BugTest\Player.log
    4.1. Expected Result: "I am a client!"
    4.2. Actual Result: "I am a server!"
    4.3. Player.log:
    Mono path[0] = 'D:/unity/BugTest/Build/Windows/WindowsClient_Data/Managed'
    Mono config path = 'D:/unity/BugTest/Build/Windows/MonoBleedingEdge/etc'
    Found 3 interfaces on host : 0) 192.168.254.21 1) 192.168.56.1 2) 192.168.176.1
    Multi-casting "[IP] 192.168.254.21 [Port] 55000 [Flags] 2 [Guid] 3431861291 [EditorId] 2650939441 [Version] 1048832 [Id] WindowsPlayer(2,CaryPC) [Debug] 0 [PackageName] WindowsPlayer [ProjectName] BugTest" to [225.0.0.222:54997]...
    Initialize engine version: 2021.3.18f1 (3129e69bc0c7)
    [Subsystems] Discovering subsystems at path D:/unity/BugTest/Build/Windows/WindowsClient_Data/UnitySubsystems
    GfxDevice: creating device client; threaded=1; jobified=1
    Direct3D:
    Version: Direct3D 11.0 [level 11.1]
    Renderer: NVIDIA GeForce RTX 3090 Ti (ID=0x2203)
    Vendor: NVIDIA
    VRAM: 24327 MB
    Driver: 31.0.15.2849
    Begin MonoManager ReloadAssembly
    - Completed reload, in 1.202 seconds
    <RI> Initializing input.
    <RI> Input initialized.
    <RI> Initialized touch support.
    UnloadTime: 1.005200 ms
    I am a server!
    UnityEngine.StackTraceUtility:ExtractStackTrace () (at C:/build/output/unity/unity/Runtime/Export/Scripting/StackTrace.cs:37)
    UnityEngine.DebugLogHandler:LogFormat (UnityEngine.LogType,UnityEngine.Object,string,object[])
    UnityEngine.Logger:Log (UnityEngine.LogType,object)
    UnityEngine.Debug:Log (object)
    UNITY_SERVER_test:Start () (at D:/unity/BugTest/Assets/Scripts/UNITY_SERVER_test.cs:11)
    (Filename: D:/unity/BugTest/Assets/Scripts/UNITY_SERVER_test.cs Line: 11)
    5. Transfer the linux build files to a linux machine and run it
    5.1 chmod +x lds.x86_64
    5.2 ./lds.x86_64
    5.2.1 Expected Result: "I am a server!"
    5.2.2 Actual Result: "I am a client!"
     

    Attached Files:

  39. cristianm_unity

    cristianm_unity

    Unity Technologies

    Joined:
    Oct 16, 2018
    Posts:
    259
    Hey @uthon! Thanks for reporting this and the detailed steps.

    I think that's caused by a bug where switching to Dedicated Server target was not triggering the scripts compilation.
    It has been fixed and it's reported to be in 2021.3.19f1. So when you have a chance, could you please check to validate it works for you now?

    Cheers!
     
  40. uthon

    uthon

    Joined:
    Nov 23, 2015
    Posts:
    14
    Hi Christian! Thanks for the quick investigation, I will regress the issue when 19f1 is released and get back to you.
     
  41. AllocTFP

    AllocTFP

    Joined:
    Mar 30, 2021
    Posts:
    3
    @cristianm_unity Any word on this? Also would be interested in an answer to MrG's question from last Friday ;)
     
  42. cristianm_unity

    cristianm_unity

    Unity Technologies

    Joined:
    Oct 16, 2018
    Posts:
    259
    Thank you all for your patience. All that I can say for now is that we are working on it, and that we will let you know as soon as we have something you can try. We are looking forward to get your feedback on some new cool stuff, so please stay tuned.
     
  43. cristianm_unity

    cristianm_unity

    Unity Technologies

    Joined:
    Oct 16, 2018
    Posts:
    259
    As for documentation, you can find it here.
    As it seems it is a bit difficult to discover it, we will see if we can find a better place for it.
     
    AllocTFP likes this.
  44. MrG

    MrG

    Joined:
    Oct 6, 2012
    Posts:
    368
    Can you at least tell us if you're backporting any improvements to LTS releases of Unity, e.g. 2021?

    Code (CSharp):
    1. [UnityMemory] Configuration Parameters - Can be set up in boot.config
    2.     "memorysetup-bucket-allocator-granularity=16"
    3.     "memorysetup-bucket-allocator-bucket-count=8"
    4.     "memorysetup-bucket-allocator-block-size=4194304"
    5.     "memorysetup-bucket-allocator-block-count=1"
    6.     "memorysetup-main-allocator-block-size=16777216"
    7.     "memorysetup-thread-allocator-block-size=16777216"
    8.     "memorysetup-gfx-main-allocator-block-size=16777216"
    9.     "memorysetup-gfx-thread-allocator-block-size=16777216"
    10.     "memorysetup-cache-allocator-block-size=4194304"
    11.     "memorysetup-typetree-allocator-block-size=2097152"
    12.     "memorysetup-profiler-bucket-allocator-granularity=16"
    13.     "memorysetup-profiler-bucket-allocator-bucket-count=8"
    14.     "memorysetup-profiler-bucket-allocator-block-size=4194304"
    15.     "memorysetup-profiler-bucket-allocator-block-count=1"
    16.     "memorysetup-profiler-allocator-block-size=16777216"
    17.     "memorysetup-profiler-editor-allocator-block-size=1048576"
    18.     "memorysetup-temp-allocator-size-main=4194304"
    19.     "memorysetup-job-temp-allocator-block-size=2097152"
    20.     "memorysetup-job-temp-allocator-block-size-background=1048576"
    21.     "memorysetup-job-temp-allocator-reduction-small-platforms=262144"
    22.     "memorysetup-temp-allocator-size-background-worker=32768"
    23.     "memorysetup-temp-allocator-size-job-worker=262144"
    24.     "memorysetup-temp-allocator-size-preload-manager=262144"
    25.     "memorysetup-temp-allocator-size-nav-mesh-worker=65536"
    26.     "memorysetup-temp-allocator-size-audio-worker=65536"
    27.     "memorysetup-temp-allocator-size-cloud-worker=32768"
    28.     "memorysetup-temp-allocator-size-gfx=262144"
    29. Mono path[0] = 'C:/Unity/Mirror2021/Builds/Server/Mirror2021_Data/Managed'
    30. Mono config path = 'C:/Unity/Mirror2021/Builds/Server/MonoBleedingEdge/etc'
    31. Initialize engine version: 2021.3.18f1 (3129e69bc0c7)
    32. [Subsystems] Discovering subsystems at path C:/Unity/Mirror2021/Builds/Server/Mirror2021_Data/UnitySubsystems
    33. Forcing GfxDevice: Null
    34. GfxDevice: creating device client; threaded=0; jobified=0
    35. NullGfxDevice:
    36.     Version:  NULL 1.0 [1.0]
    37.     Renderer: Null Device
    38.     Vendor:   Unity Technologies
    39. Begin MonoManager ReloadAssembly
    40. - Completed reload, in  2.042 seconds
    41. ERROR: Shader Sprites/Default shader is not supported on this GPU (none of subshaders/fallbacks are suitable)
    42. Microsoft Media Foundation video decoding to texture disabled: graphics device is Null, only Direct3D 11 and Direct3D 12 (only on desktop) are supported for hardware-accelerated video decoding.
    43. ERROR: Shader Sprites/Mask shader is not supported on this GPU (none of subshaders/fallbacks are suitable)
    44. ERROR: Shader Legacy Shaders/VertexLit shader is not supported on this GPU (none of subshaders/fallbacks are suitable)
    45. WARNING: Shader Unsupported: 'Standard' - All subshaders removed
    46. WARNING: Shader Did you use #pragma only_renderers and omit this platform?
    47. WARNING: Shader If subshaders removal was intentional, you may have forgotten turning Fallback off?
    48. ERROR: Shader Standard shader is not supported on this GPU (none of subshaders/fallbacks are suitable)
    49. WARNING: Shader Unsupported: 'Standard' - All subshaders removed
    50. WARNING: Shader Did you use #pragma only_renderers and omit this platform?
    51. WARNING: Shader If subshaders removal was intentional, you may have forgotten turning Fallback off?
    52. UnloadTime: 0.581700 ms
    53. KcpTransport initialized!
    54. Unloading 4 Unused Serialized files (Serialized files now loaded: 0)
    55. There is no texture data available to upload.
    56. ERROR: Shader UI/Default shader is not supported on this GPU (none of subshaders/fallbacks are suitable)
    57. ERROR: Shader Skybox/6 Sided shader is not supported on this GPU (none of subshaders/fallbacks are suitable)
    58. UnloadTime: 0.142500 ms
    59. Unloading 3 unused Assets to reduce memory usage. Loaded Objects now: 909.
    60. Total: 1.095400 ms (FindLiveObjects: 0.028600 ms CreateObjectMapping: 0.009700 ms MarkObjects: 1.052400 ms  DeleteObjects: 0.004600 ms)
    61.  
    62. ERROR: Shader GUI/Text Shader shader is not supported on this GPU (none of subshaders/fallbacks are suitable)
    63.  
     
    Last edited: Feb 15, 2023
    mischa2k and AllocTFP like this.
  45. uthon

    uthon

    Joined:
    Nov 23, 2015
    Posts:
    14
     
  46. MrG

    MrG

    Joined:
    Oct 6, 2012
    Posts:
    368
    That was the failure to recompile script bug when switching to Dedicated Server target, not improvements to the actual builds, like stripping lighting, shaders, etc. @uthon
     
  47. uthon

    uthon

    Joined:
    Nov 23, 2015
    Posts:
    14
    Hi Christian,

    The bug appears to be fixed in 2021.3.19f1!
     
    cristianm_unity likes this.
  48. uthon

    uthon

    Joined:
    Nov 23, 2015
    Posts:
    14
    I have to take that back, it is being very finicky depending on which build configuration I am in when starting the script. I'm having to toggle the platform between two targets to get Unity to build the correct target.
     
  49. uthon

    uthon

    Joined:
    Nov 23, 2015
    Posts:
    14
    I think I have a workaround for the issue.

    By setting the build target and subtarget manually before the build, I seem to get a correct build of the Dedicated Server each time.

    Code (csharp):
    1.  
    2.  
    3.     /// <summary>
    4.     /// Build Linux dedicated server.
    5.     /// </summary>
    6.     /// <param name="inDebug">True to build a Development (Debug) build.</param>
    7.     public static void BuildLinuxDedicatedServer(bool inDebug)
    8.     {
    9.         BuildOptions opts = BuildOptions.None;
    10.         string loc;
    11.  
    12.         // Switch to the desired build target. As of 2021.3.19f1 there is a bug where
    13.         // appropriate scripts are not being executed by BuildPlayer.
    14.         EditorUserBuildSettings.standaloneBuildSubtarget = StandaloneBuildSubtarget.Server;
    15.         EditorUserBuildSettings.SwitchActiveBuildTarget(BuildTargetGroup.LinuxHeadlessSimulation, BuildTarget.StandaloneLinux64);
    16.  
    17.         if (inDebug)
    18.         {
    19.             Debug.Log($"Building Linux dedicated server, Debug");
    20.             opts = BuildOptions.Development;
    21.             loc = "Build/autobuild/Debug/linuxds/GAMENAME.x86_64";
    22.         }
    23.         else
    24.         {
    25.             Debug.Log($"Building Linux dedicated server, Release");
    26.             loc = "Build/autobuild/Release/linuxds/GAMENAME.x86_64";
    27.         }
    28.  
    29.         var buildPlayerOptions = new BuildPlayerOptions()
    30.         {
    31.             scenes = scenes,
    32.             locationPathName = loc,
    33.             target = BuildTarget.StandaloneLinux64,
    34.             subtarget = (int)StandaloneBuildSubtarget.Server,
    35.             options = opts
    36.         };
    37.  
    38.         BuildReport report = BuildPipeline.BuildPlayer(buildPlayerOptions);
    39.         PostBuild(report);
    40.     }
    41.  
     
  50. cristianm_unity

    cristianm_unity

    Unity Technologies

    Joined:
    Oct 16, 2018
    Posts:
    259
    Thanks for the details @uthon, will take a closer look at the original bug you reported.
     
Thread Status:
Not open for further replies.