Преминете към основното съдържание

How to fix lag and "SteamNetworkingSockets lock held" warnings

If players on your Counter-Strike 2 server complain about lag and your console is full of messages like the one below, your server does not get enough CPU time.

SteamNetworkingSockets lock held for 57.4ms. (Performance warning.) SendMessages
This is usually a symptom of a general performance problem such as thread starvation.

What this message means​

The server works in "ticks" — at 64 tick one tick is about 15.6 ms. The message says that the network thread had to wait 55-60 ms for the CPU, which is several ticks. During that time packets to the players are late, and the players feel it as lag, rubber-banding or hit registration problems.

This is almost never a network or datacenter problem. It means that something on the server uses all of its CPU.

Step 1) Check the CPU usage​

Step 1) Go to your console and click on your server.

Step 2) Look at the CPU box below the console while players are on the server. It shows the usage and the limit of your plan, for example 188% / 200%.

TIP

100% equals one full CPU core. If the value is close to the limit of your plan while the server is full, the server is CPU-starved and you will see the warnings above.

Step 2) Find what uses the CPU​

These are the most common causes we see on CS2 servers:

CauseWhat to do
Two plugins doing the same job — for example two anti-wallhack plugins, two map choosers, VIP plugins for both CounterStrikeSharp and SwiftlyS2Keep only one of them.
Anti-wallhack / fog-of-war plugins with a very short update interval or many worker threadsUse the default values. An update interval of 1 ms recalculates visibility about 15 times per tick. Keep worker threads at 1 on a 2-core plan.
Anticheat plugins with every detection enabledDisable the detections you don't need.
Both CounterStrikeSharp and SwiftlyS2 installedEach one runs its own .NET runtime. See CounterStrikeSharp vs SwiftlyS2.
Bots (bot_quota)Every bot is simulated by the server. Lower bot_quota or use bot_quota_mode "fill".
Players reconnecting on every map change because of workshop addonsSee How to install and configure MultiAddonManager and enable mm_cache_clients_with_addons.

Step 3) Test which plugin is heavy​

Step 1) Stop your server.

Step 2) Disable the plugin you suspect. Move its folder to plugins > disabled for CounterStrikeSharp plugins, or move its .vdf file out of game > csgo > addons > metamod for Metamod plugins.

Step 3) Start the server and compare the CPU value with the same number of players.

If the CPU drops a lot, you found the heavy plugin. Check its settings or look for a lighter alternative.

Still not enough CPU?​

If your server is optimized and still reaches the CPU limit when it is full, you need a bigger plan. You can upgrade your server from the Client Area — open your service and click "Upgrade".