Server-side loops lag a LOT, while single actions don't

Hello,

My game (Dynamic Ship Simulator III) has been experiencing a strange, server-side lag issue recently, which slows down all server loops dramatically. It doesn’t have ANY impact on the ping or heartbeat though (they are mostly stable), and all singular actions, like firing a remote function for example, act normally without delays. The server memory seems to rise over time, rising to as much as 3450 (MB I think???) after 24 hours.

I’ve been trying to find the reason of this mess, but I couldn’t find any power consuming script on the server’s side. This has been happening since the last update I introduced, so this must be fixable on my end.

The issue doesn’t happen always, but tends to appear more on older and more populated servers. I have no idea what exactly could cause this, but something must “build up” over time. I don’t even know how to find the problematic script, since according to the dev console, everything is fine “on paper”.

Players don’t report any crashes or disconnections because of this. In fact, the average play time is even longer than before.

I’m not sure if this is going to help, but the main thing I introduced in the most recent update was a localscript which manually streams the terrain on the client (it turns little WedgeParts with meshes inside into actual, big WedgeParts). This was done to reduce the load on the server, and on the client as well, and seems to function pretty well. Thanks to it, I’m able to expand the map much easier and shorten the joining times.

After 24 hours, this is the server memory:

There are no scripts on the list which could have such a terrible impact on the server:

The ping, as well as the heartbeat, is acceptable:

I believe it’s because of how fast you’re doing the loop. Is there any chance you could slow the loop? In an old game of mine, it suffered horribly due to simple wait()s triggering each loop, which did a LOT of calculations, which would be fine if it was ran once, but running that loop very fast caused ~10 zombies to use about 25% of the server memory. By slowing the loop down to 1 calculation every 5 seconds, I managed to get it down to about 2% of sever memory.

Are you talking about the script from one of the screenshots, which has a rate bigger than 1300 times per second? I don’t think it’s the cause of the lag because it has a very low activity, despite the high frequency. Even without it, the server would lag a lot. I’ve heard of memory leaks, maybe they could be related?

Maybe, that could be why.

Perhaps you are creating instances and the connections to those instances remain after the end of the code inside the loop, I’m not really very good with this sort of thing but from what I’ve gathered from other posts it can be a big problem when you don’t cut the connections to instances.

1 Like

But would a memory leak only slow down the server-side loops? As I said, there is no impact on the ping or the heartbeat. All single script actions run fine, remotes respond well. The only things affected are loops on the server, which have a wait() inside. If a loop doesn’t have any wait(), it runs instantly.

edit: Sorry for not being so specific in the first post. The only loops affected are those which have a wait() (with any number, or blank) inside.

Now that I’m sure that it’s a memory leak, I decided to compare the memory taken by a fresh server (on the right), and an old one (on the left). Could anyone advise me, what should I especially look into while diagnosing the problem?