C # Production Server, am I collecting garbage?

I know there are tons of threads about it. And I read a few of them.

I am wondering if GC.Collect(); correct in my case GC.Collect();

I have a server for MMORPG, in production it works day and night. And the server restarts every other day to implement changes in the production code base. Every twenty minutes, the server pauses all other threads and serializes the current state of the game. This usually takes from 0.5 to 4 seconds.

It would be a good idea to GC.Collect(); after serialization?

The server, obviously, constantly creates and destroys game elements.

Will I have a known profit in performance or memory optimization / utilization?

Should not be manually assembled?

I read about how collecting can be bad if it is used at the wrong moments or too often, but I think these savings are a good time to collect, and not so often.

The server is in framework 4.0

Update in response to comment:

We accidentally encounter a server hang, sometimes unexpectedly the server’s memory usage will increase until it reaches the point where the server has been doing any network operation for too long. Thus, I consider many different approaches to solving the problem, this is one of them.

+6
source share
3 answers

The garbage collector knows better when to run, and you should not force him. This will not improve performance or memory optimization. The CLR may instruct the GC to collect an object that is no longer in use, if necessary.

Answer to the updated part: Forcing a collection is not a good solution to the problem. You should look a little deeper into your code to find out what is wrong. If memory usage increases unexpectedly, you may have a problem with unmanaged resources that are not properly handled or even “leaky code” in managed code.

One more thing. I would be surprised if calling GC.Collect fixed the problem.

+12
source

Every twenty minutes, the server pauses all other threads, and serializes the current state of the game. It usually takes 0.5 to 4 seconds

If all your threads are already paused, you can also call garbage collection, since at this point it should be pretty fast. I suspect that this will only mask your real problem, although it will not solve it.

We accidentally experience a server freeze, sometimes, unexpectedly, the server’s memory usage will increase more often until it reaches the point where the server takes too long to manage any network operation. Thus, I consider many different approaches to solving the problem, this is one of them.

This is similar to the fact that you are actually still referring to all these objects that use memory - if you were not a GC, they would start up due to memory pressure and try to free these objects. Perhaps you are looking at the actual error in your production code (that is, objects that still subscribe to events or otherwise refer when they shouldn't), and not something that you can fix by manually removing the garbage.

If this is possible in a script, you should run a performance analysis to find out where your bottlenecks are and what part of your code causes the bulk of the memory allocation.

+2
source

Could an increase in memory be an “attack” of a player with a fake / modified game client? How much memory is allocated by the server when it accepts a new client connection? Does the server support fake incoming data?

+1
source

Source: https://habr.com/ru/post/887533/


All Articles