Forum

> > CS2D > Scripts > CS2D memory leak in general.
Forums overviewCS2D overview Scripts overviewLog in to reply

English CS2D memory leak in general.

18 replies
To the start Previous 1 Next To the start

old CS2D memory leak in general.

Mami Tomoe
User Off Offline

Quote
I have a fairly big script, overtime players' FPS and latency will grow.
Reconnecting results in nothing (I think), but restarting the game fixes it.

Which means the leak is clientsided but is caused by the server.
It might be caused by all servers but since the script is big the problem is bigger.

@user DC: Does CS2D have a memory leak that you know of?


EDIT:
Looking at task manager, the CS2D.EXE executable uses a set amount of ram and slowly it uses more and more until the client becomes unresponsive.

EDIT 2:
The server with that leak is:
NAME: [DEV] Terraria RPG
PASSWORD: 99153
edited 3×, last 17.02.19 06:30:48 pm

old Re: CS2D memory leak in general.

DC
Admin Off Offline

Quote
I think there have been reports that the memory consumption slowly increases over time. So there probably is a leak but not a super critical one. (critical in the sense of huge increase of memory consumption in a very short time).

It's also possible that there's a leak in the Lua version I'm using in CS2D or that the leak is caused by the way Lua is used by CS2D. There have been issues with that before.

The bad thing about such leaks is that it is very hard to find the reason for them. Right now I don't have any clues which might help me to find possible reasons for a leak. So without narrowing it down to specific actions/Lua calls I won't be able to improve it.

old Re: CS2D memory leak in general.

Mami Tomoe
User Off Offline

Quote
Can't you join the server with a debugging version of CS2D and check stuff?

This is the result of leaving CS2D open for 30~ minutes in that server:
IMG:https://i.imgur.com/he1D4G7.png


CS2D is almost surpassing Chrome, that's an achievement.

FPS changes:
Solid 59-60 > Spikey 30-50 FPS

old Re: CS2D memory leak in general.

DC
Admin Off Offline

Quote
Hey, that's not true. Chrome is using much more ram if you sum up all its processes

Unfortunately BlitzMax' debugging is extremely basic and doesn't provide profiling / memory usage info. I can join with a debug version but it won't give me any additional info (except for debug outputs I add myself).

Are you using a lot of Lua images? This would be one of the most obvious candidates which could possibly cause a behavior like this.

Others are server triggered sounds, effects and (HUD)texts.

old Re: CS2D memory leak in general.

Mami Tomoe
User Off Offline

Quote
Yes I do use a lot of images but it's a fixed amount of images that doesn't change unless a player changes them.
It's about 50 max images that have opacity of 0 if they're far from the player.

EDIT:
I left CS2D open since my last reply, it has reached about 300,000K usage with around 20FPS.

And then suddenly the usage dropped to 87,000~K but the CPU usage stayed at 25%.
The FPS dropped to 7-16.

old Re: CS2D memory leak in general.

DC
Admin Off Offline

Quote
Do you set the opacity to 0 for performance reasons? If yes: You don't have to do that. CS2D does not render images which are outside the visible screen area.

If you do certain things frequently (like in always, ms100 or with timers) this is probably something to take a closer look at. But like I said: It's no trivial to find the reason for such a leak unfortunately.

old Re: CS2D memory leak in general.

Mami Tomoe
User Off Offline

Quote
If I wont set the opacity to 0 players who join and have to load all the images at once will have their game crash (not entirely but they will have to reconnect which will result in the same problem preventing them from being able to play).
It has been tested and proved that setting the opacity to 0 on RPG servers for images that aren't used or supposed to be seen will allow more players to join.

I don't use ALWAYS, I do use MS100, SECOND and MINUTE.

I'm going to assume MINUTE has nothing to do with this because the leak is growing under a minute per chunk.

It might be the MS100 or SECOND hooks but I don't really know what is that I'm supposed to be looking for.

EDIT (1):
I decided to leave the server.
10% less CPU usage
20k more RAM usage?

Reconnected (without restarting game):
10% more CPU usage
15K~ more RAM usage

While spectating there is no lag.

EDIT (2):
Is there a way to track this blue bar's source?
IMG:https://i.imgur.com/cVsZSO4.png


EDIT (3):
Could using the
player()
function often cause this?
edited 1×, last 15.02.19 04:00:29 am

old Re: CS2D memory leak in general.

Elfing
User Off Offline

Quote
At first "Render" was the big one for me:
IMG:https://media.discordapp.net/attachments/313062876933783554/545814018581987353/render.JPG


After 15 minutes, it was like this mostly, with "Wait for render" and "Update" being more prominent:
IMG:https://media.discordapp.net/attachments/313062876933783554/545814021115478036/render2.JPG
edited 1×, last 15.02.19 04:51:13 am

old Re: CS2D memory leak in general.

SQ
Moderator Off Offline

Quote
@user Elfing: This means after 15 minutes CS2D started having better GPU performance, worse CPU. Lel, nice.
I do think that's caused by some background stuff happening in computer. The leak in memory doesn't necessary mean worse performance for CPU.

old Re: CS2D memory leak in general.

Mami Tomoe
User Off Offline

Quote
The CPU usage grew up to 25% in my i3-7100 over up to 1 hour.


EDIT:

Done some experiments:

Under the same circumstances of which:
No Lua scripts.
rpg.terraria map is used.

Dedicated server:
RAM & CPU are fine.

CS2D New Game:
Spectating: RAM & CPU are fine.
Spawned: RAM & CPU slowly crawl higher and higher.

Here is a video footage of me downloading CS2D and causing the leak to occur: https://youtu.be/mEkx54F3NBE

Note that the cleaner the server the lighter the leak would be.
edited 1×, last 16.02.19 07:18:49 pm

old Re: CS2D memory leak in general.

Mami Tomoe
User Off Offline

Quote
IMG:https://i.imgur.com/skkMBXh.png



• New CS2D client.
• 60K > 140K ~ RAM usage over almost 15 minutes of standing still.

1. Install and launch CS2D.
2. Start new game.
3. Spawn.
4. Unfocus CS2D (background CS2D).
5. Wait.

Note 1: This probably scales with the amount of load CS2D is having, bigger scripts mean bigger leaks.
Note 2: My script has this leak no matter if you focus CS2D or not.




EDIT 1:
I have a feeling this has something to do with spawning and unfocusing the game, tested.

EDIT 2:
Comparing 2 clients connected to the same server, my client is connected for longer.

IMG:https://i.imgur.com/e0H1LsA.png


EDIT 3:
Is anything going to be done about this? I need to know.
edited 3×, last 19.02.19 08:09:22 pm

old Re: CS2D memory leak in general.

DC
Admin Off Offline

Quote
As explained above it's really hard to find the source of leaks. And if it is really related to window focus/unfocus it's even harder because it might not even be a problem in the code of CS2D but something going wrong in low level BlitzMax stuff or third party libraries.

So chances that this will be fixed aren't good.

old Re: CS2D memory leak in general.

mrc
User Off Offline

Quote
This also happen with cs2d_dedicated on Linux. After some hours the RAM consumption increase and the server FPS start dropping no matter if the server is full or empty. I'm using an 1GB RAM and Debian 8 for hosting. Someone else have this problem with the dedicated?

@edit

utsfx was causing the fps drops.
edited 2×, last 28.02.19 12:20:22 am

old Re: CS2D memory leak in general.

Masea
Super User Off Offline

Quote
user DC has written
Are you using a lot of Lua images? This would be one of the most obvious candidates which could possibly cause a behavior like this.
Hey, is it only the number of images or also the size of every particular image too that needs to be considered? Sorry me if it is a dumb question as it really seems but I gotta know that so hard.

What is the difference between spawning an image whose size is around 50 MB and another image whose size is around 1 MB in cs2d lua hook ms100? I am not questioning the frequency and how is being spawned but what is being spawned.

old Re: CS2D memory leak in general.

DC
Admin Off Offline

Quote
@user Masea: Of course a big image will consume more memory.
• as a client: it should consume VRAM (on your GPU, depending on image size) only (+ only a few b/kb in RAM, always about the same amount though, image size doesn't matter here)
• as a dedicated server: a compressed copy of the image data needs to be kept in RAM in order to be able to transfer that data to clients. So here the RAM consumption is also affected by image size.
• as a listen server (non dedicated): both of the above! VRAM and RAM consumption depending on image size!

btw: When clients receive image data from a server (via the transfer system) they will load it into RAM, decompress it and then load it in the VRAM (GPU). Stuff should be removed from RAM afterwards.

It's also very important to note that CS2D loads every image only once. So in case you spawn the 50 mb image 100 times it will still only consume 50 mb (VRAM on GPU) + a few bytes / kb in RAM for the instances you spawned.

Also of course loading a 50 mb image is much slower than loading a 1 mb image. It will only be slow ONCE though (the first time it is loaded after joining the server).
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview