[Help]Ram Usage

09/26/2010 23:25 ryuchetval#1
Hey guys...I don't know if anything like this have happened to you too but the source is eating up RAM slowly...I was wondering if all of this happens because of the timers (that repeat every .1 second) if so ... I have a lot of "if's" in them checking the servertime...would it reduce the ram usage by using a switch (Servertime.hr/day/blahblah) and make with cases?

if this is not the problem of the ram usage can anybody tell me what causes this ram usage?

EDIT: i'm talking about tanel's 5165 ini source
09/27/2010 02:46 pro4never#2
Sounds like a memory leak if you are consistently using more an more ram as the server is online.

This can be caused by all sorts of things but mostly make sure you are disposing of things when done (if applicable. EG: socket connections, mysql connections, reader/writers)

If you have a thread for various server functions make sure you are repeating it properly

Eg: if you have a thread that runs a function (lets call it Run()) and at the end you are calling the function again every time, you tend to cause memory leaks vs a while statement or something better.

If statements vs switches is more an efficiency issue afaik.

Timers are.... to be avoided in many case (what the FUCK are you using .1 second timers for? use a god damn thread lol)
09/27/2010 07:31 ryuchetval#3
well yes it's a thread...actually idk what's the difference... but the thread runs every .1 second i believe...

and what about "afaik" ... you mean that you don't know?
somebody told me that using switches is a more effective way than by using those "if's" but idk if it's like that...
09/27/2010 08:09 Ian*#4
Quote:
Originally Posted by ryuchetval View Post
well yes it's a thread...actually idk what's the difference... but the thread runs every .1 second i believe...

and what about "afaik" ... you mean that you don't know?
somebody told me that using switches is a more effective way than by using those "if's" but idk if it's like that...
Okay first, what is this thread doing? Depending on the situation it's better to use a switch (sounds like in this case it might be just because of the frequency it's running the function).

afaik = As far as I know.

Everyone says this is more efficient than that blah blah... depends what it is.

Like, a do while block is great to use for certain things like...

while (botting)
{
if (this)
doThis();
else
botting = false;
}

just have to make sure you turn it off when you don't need it.

if/ else statements... those are about as basic as it gets tbh,
only use them if (needed) :))
09/27/2010 08:29 ryuchetval#5
the thread is to do several things in the world...like cheking broadcasts, items on ground, and then check the server times for several things like : vote reset points, gw start/end, dis city start/end...all of these are using a lot of "if" statements....so if it's better to use a switch or more tell me :)
09/27/2010 08:34 pro4never#6
Sounds like you should be splitting this into multiple threads...

Personally I prefer to split things by how often they are called. Eg: a slow thread that runs once per second for things that are less common and something that runs every 100 ms for more often things.

Hell even a 3rd thread that runs every minute may be appropriate for things like events.

Think about it... if you are using a thread that runs every 100 ms, you don't wanna be checking every single time to see if an event needs to start (That may only start once a day lol)
09/27/2010 08:38 ryuchetval#7
yea it's true that it doesn't need to check every .1 second for this
thanks for your opinion i'll do it :)
09/27/2010 13:55 pro4never#8
For a fairly 'finished' server when it comes to feature I'd do something like 2 server threads and 2 client threads (MANY will disagree with me as there are some knowledgeable people who stress the importance of minimizing thread usage but this seems like a reasonable amount to me.)

Fast server thread: Once per 500 ms or so (mob movement/attacks, removing ground items)
Slow server thread: Once per minute: Control events, server states, etc)

Fast client thread: Once per 100 ms or so (removal of client effects, check if attacks need to be happening, other 'often' stuff)

Slow client thread: once per second or so. Adding clients stamina, xp, decreasing pk points. etc... things that don't need to be checked super fast but still happen fairly often.


If you structure your server correctly this + your main thread should be all you ever really need. Maybe a packet queue thread for handling sending of packets but I don't see that being TOO much of an issue.

If you aren't creating threads left right and center (Eg: Thread per client, thread per event, etcetc that I've seen done all over) and you are using your resources correctly (removing from dictionary when not needed. Eg: Players, mobs, items, etc) and are not doing bad loops timers or anything like that then your ram usage shouldn't be all that high. Just as you code things always check the ram to ensure you aren't developing memory leaks. If you do, look at your code and try to revise it so that you fix the problem before it becomes a true issue.
09/27/2010 14:19 Nullable#9
Thread usage should not be as low as you're proposing; IMO a good server should make good use of resources available (eg. threads, memory etc.), and the best optimization for threads is a listener thread per server (auth/game), one or two I/O workers (receiving data), and a threadpool of worker threads for processing clients' requests provided that the threadpool will spawn/abort threads as number of requests increase/decrease.
Then for proper database usage a multi-threaded core with a thread-safe queue for queries sounds like a good deal.

As for events etc a thread or two spawning other threads as needed is a good strategy as well.
09/27/2010 14:25 Basser#10
Some of you have to keep in mind RAM != CPU.
09/27/2010 18:40 ryuchetval#11
Quote:
Originally Posted by Basser View Post
Some of you have to keep in mind RAM != CPU.
well these threads could also use ram couldn't they?
09/27/2010 18:43 KraHen#12
Quote:
Originally Posted by Basser View Post
Some of you have to keep in mind RAM != CPU.
.
09/27/2010 21:20 pro4never#13
Quote:
Originally Posted by ryuchetval View Post
well these threads could also use ram couldn't they?
My concern with the threads was mostly for creating memory leaks. Spawning threads uses up some amount of ram (fairly small from what I remember hearing) but the main concern/advantage of managing your threads is to make processing fast and efficient.

Ram more becomes an issue when you are not disposing objects and over the course of your server, you are getting more and more ram usage. Aka a memory leak.

In most co servers your ram usage should remain fairly low unless you are doing something really strange. Loading dmaps, itemtypes, mob spawns and alike should NOT be using some fantastic amount of ram and if it is... you should track down which is using that amount of ram and fix the problem.

EG: try loading only 1 thing at a time and check ram usage.
09/27/2010 22:28 ryuchetval#14
ok now after we talked so much about threads and others i remembered that i used an anti bot system released on here : [Only registered and activated users can see links. Click Here To Register...]
could this be the problem of the memory leak as it's a timer not a thread...even though i don't know what i really say and i don't really know the difference between a timer and a thread if there is any...
09/27/2010 22:45 _tao4229_#15
You can't get a true memory leak in C# unless you SERIOUSLY fuck up (or get fucked by Microsoft unknowingly, which I doubt will happen to any of you guys).
The only way to get a true memory leak is by calling native functions and then not calling the functions to clean up native resources.