Understanding C# performance on servers

Disclaimer: This is completely unrelated to the recent update about the resource tick warning! This thread is related to server-side scripting.

Dear FiveM community :wave:

We recently enabled OneSync Infinity on our server. We still need to fix a few script migrations but are after some tweaking overall happy with what it provides to our community.

However, since then our server had some infrequent crashes (around 1-2 days apart) that had error messages like

fivem  | [BigMode] Update thread loopTime: 12 ms (your server is lagging or updateThreadTimeThreshold is too low)

At some point it reached

fivem_1  | Error: Loop svMain seems hung! (last checkin 95 seconds ago)
fivem_1  | Warning: svMain watchdog stack: root
fivem_1  | Error: Loop svSync seems hung! (last checkin 137 seconds ago)
fivem_1  | Warning: svSync watchdog stack: root
fivem_1  | Error: Loop svNetwork seems hung! (last checkin 135 seconds ago)
fivem_1  | Warning: svNetwork watchdog stack: root
fivem_1  | Error: Loop default seems hung! (last checkin 130 seconds ago)
fivem_1  | Warning: default watchdog stack: root

So I assumed it’s a resource time problem. I remembered that there was the profiler and recorded some ticks on the server.

What immediately catched my eye was the fact that there are 4 major performance eaters.

  • PocceMod
  • vMenu
  • Hypnonema
  • and our own resourcepack alternate-universe

They are all C# resources. All other resources are LUA and as you can see in the screenshot, they bare take any time to run.

I am aware that PocceMod and vMenu are not the most performant resources and we plan to merge their codebases into ours or rework these plugins, but this thread is not about 3rd-party resource support.

Our framework alternate-resources however is still at the very beginning of development. Right now it only consists of a local chat function which is only using one command and events, no ticks. And still it somehow takes over 5 ms on it’s own to run per tick. :thinking:

Our server is currently running artifact 3071 on Linux on a ZAP Hosting root server (not GSP). From some conversations on Discord I gathered that there is some overhead to C# resources due to AppDomain but I dont understand why it’s this bad for a practically empty resource. After all other users are using C# as well and since I can’t find any info about this issue elsewhere I assume we are doing something wrong.

I have tested this on a local windows server and observed the same results. C# resources took multiple ms on the server compared to <0.1ms LUA resources.

Also out of curiosity I profiled the client and didn’t see such a dramatic difference between client and server, even though our resource contains roughly the same amount of code on both sides.

Any help or suggestions for fixes or tests are greatly appreciated. Is the crash even related to the C# resources or could something else cause them? Still I’d like to know how to optimize C# resources server side so the are not that heavy on a tick.

no, if you’d run Windows you’d at least get a livedump and such so you could at least provide actual useful info.

same tbh

Hey bubble, thanks for taking the time for answer my question again!

That is unfortunately not possible with our current setup and I assume by your answer that getting these dumps is not possible with Linux based servers. But it will add another consideration for Windows to the future of our server when this does provide more insight for debugging problems.

What do you mean with that statement? Do you confirm my suspicion that C# just can’t run any better on servers? I assume this has to do with AppDomain again, right? You mentioned it on Discord. Which as far as I understand is only used to provide support for Linux servers :confused:

To summarize I understand that the only way to make a performant C# resource is to bundle all C# logic into one resource so the base overhead is only added once? Please correct me if I’m wrong.

I know we talked about this on Discord already but I created this thread to sum up the info in a clearer form. The forums are propably better suited for this kind of questions and I may not have expressed myself clearly on Discord.

no, it’s mainly that the client uses some specific hacks to run without too much transition overhead, but the server can’t do this as linux versions of mono would need out-of-band updating.

1 Like