Server network usage spikes and general lags, cause?

I am an experienced Lua programmer and have just made a gamemode for a server of mine from scratch, it is rather big in size, but all of the code is optimized and there’s no abundant network or resource usage occurring, yet the server is experiencing some extraordinary lags. As far as I know, these lags have nothing to do with the actual server it is running on.

I suspect most of you know the console command ‘net_graph’, perhaps some even use ‘net_graph 4’. I have opened this up on the server with my gamemode and took a screenshot of it with about 10 players online.

The lag doesn’t seem to be present all the time, but it occasionally kicks in. What you see if this in the net_graph is that the two variables at the bottom, sv and var (I have NO idea what those are, but I presume sv is the server tickrate. Var I don’t know but I would like to know - Couldn’t find it anywhere), suddenly start spiking up. sv will heavily fluctuate between 90 and 110 during a spike (lasts ~0.5 seconds) and the var can increase from 2-4 normally to anything between 10 an 40 msec, where 40 msec completely dislocates players.

I can’t put a finger of what is causing this, and I have completely searched through my gamemode for possible causes of this issue, with no result.

Also, when a player joins the server, other connected players have a similar spike, but the sv or var do not change. (A spike like this can be seen in the visual chart, the most right spike)

Since these problems occur even with no further addons but the gamemode installed and a tickrate enabled (Tickrate_Enabler v0.4, the only one there is?), I would like to blame the tickrate addon, even though I can’t be sure. I am not sending massive amounts of data on player connect either. There are no timers that are constantly running in the gamemode.

I hope someone can think with me and hopefully point out what could be the golden tip to a lag-less server.

You could try using oubliette’s tool

It may be caused by sending mass amounts of data to a player, or using resource intensive functions such as map.cleanup()

Sv is server fps.

I’ve tried using DBug before but without success, mainly because I couldn’t see a clear stack trace of what was called and where the longest execution time is. How would I approach using this?

Thank you Robotboy for telling, but would you or someone else know what ‘var’ shows?

A simple Google search led to this:

You should use Google more often.

I shouldn’t use Google more often, I should provide the correct search terms next time :slight_smile:
I was searching for something entirely different.

I think the problem has been fixed, but I’ll update this tomorrow when I have more information.

This isn’t a problem with the server itself, but the clients. Let me break it down for you;
If you take a look at the very bottom of the net graph, you can see a blue line. That line shows if the server lags or not. When red spikes appears on that very blue line, the server is having a rough time keeping up with all physics happening on the server. The line where there is a huge red spike in, is the client’s game, in this case your game.
If any of these spikes occur when there are red spikes at the very bottom blue line, then you know it’s the server that can’t handle all the physics, and that’s when you know that you have to either reduce your servers tickrate or get your server hosted on a more powerful machine.

If you end up deciding to get the server hosted on a more powerful box, the only thing you should focus on finding is a server machine that has a CPU with as high clockrate as you can find. The higher clockrate, the better the server will operate. Also, don’t bother going for an overkill and get a quad or hexa core CPU as SRCDS isn’t multi-threaded meaning it won’t utilize any of the cores except two. One for handling the server itself and one for handling the network traffic, which I believe you are aware of being a developer yourself.

Hope this helps out a little bit!