Improving Server Stability

Joined
Aug 2, 2010
Messages
190
Reaction score
91
For those people who are interested in improving their server stability, this thread is right for you. First of all, NEXON's main servers can support 1200 players on 4 GB of RAM and runs on Quad Core (Per Channel). Obviously, our OdinMS servers can't do that. However there is hope in obtaining this form of stability. Most of us here know LightPepsi and Celino. His server has supported 600+ players using only 2.2 GB of RAM. One conclusion that can be drawn from this is that server stability is not impossible. Most importantly, the way we code affects server stability.

Some ideas for improving server stability:
Object creation and fixing memory leaks.
Danger of finalizers.
Please contribute helpful ideas and opinions on your take towards a stabler server.
 
Last edited:
That's what I was trying to say


When you reach above 2500 concurrent users you will notice that 8gb are running short. But once again: Fixing this can/should not be accomplished by using smaller primitive types.

When you do reach 2500, lots of $$$$ will come.
Then, you'll have 16GB of ram and notice that you can hold 5000 concurrent users.
 
Upvote 0
Isn't the crashing of a server caused by deadlocks only? I thought it was the CPU having a harder time going through the used memory by the source to find what it needs and therefore can cause deadlocks, causing others not being able to log in.

If I am right.. wouldn't just making sure every cached data (or just heavy data) gets released after using it create less memory being used thus CPU being able to interact faster?

If not, could anyone clarify if it's better to cache data (and look out for memory leaks) and then release it again or to cache it and keep it cached all the way. *for the cpu ofcourse, if I was wrong at the deadlocks in the first place.. clarify crashing*
 
Last edited:
Upvote 0
Isn't the crashing of a server caused by deadlocks only? I thought it was the CPU having a harder time going through the used memory by the source to find what it needs and therefore can cause deadlocks, causing others not being able to log in.

If I am right.. wouldn't just making sure every cached data (or just heavy data) gets released after using it create less memory being used thus CPU being able to interact faster?

If not, could anyone clarify if it's better to cache data (and look out for memory leaks) and then release it again or to cache it and keep it cached all the way. *for the cpu ofcourse, if I was wrong at the deadlocks in the first place.. clarify crashing*
Server crashing can happen from many, many different ways.

Some popular ways that I know of are :

The CPU usage going up too high. (Deadlocks can cause this, yeah.)
The Memory Usage(RAM) is too high ( Caused by memory leaks )
Network failure (Caused by network issues, of course.)

You must remember that deadlocks occur when two threads are waiting input for each other , (Correct me if I'm wrong.). If you double-check to see if your methods are all thread-safe then there shouldn't be a problem on that side.

However, when dealing with memory leaks, the RAM usage and CPU usage both sky-rocket, which can cause a crash in a very little time frame, depending on where it originates from.

As for caching, I do believe that caching data like map files should be cached all the way. One thing I could try doing would to put a timer to release all maps that haven't been visited by a player since a certain time period. As for anything else, I'd keep it the way it is.


I'm not really good at this, these are all theoretical ideas I just thought of . :D
 
Upvote 0
Server crashing can happen from many, many different ways.

Some popular ways that I know of are :

The CPU usage going up too high. (Deadlocks can cause this, yeah.)
The Memory Usage(RAM) is too high ( Caused by memory leaks )
Network failure (Caused by network issues, of course.)

You must remember that deadlocks occur when two threads are waiting input for each other , (Correct me if I'm wrong.). If you double-check to see if your methods are all thread-safe then there shouldn't be a problem on that side.

However, when dealing with memory leaks, the RAM usage and CPU usage both sky-rocket, which can cause a crash in a very little time frame, depending on where it originates from.

As for caching, I do believe that caching data like map files should be cached all the way. One thing I could try doing would to put a timer to release all maps that haven't been visited by a player since a certain time period. As for anything else, I'd keep it the way it is.


I'm not really good at this, these are all theoretical ideas I just thought of . :D

I don't think the RAM or CPU being too high causes a crash directly.. I still think it's the speed of the CPU processing that results in deadlocks when the CPU or memory usage is too high, it just takes the cpu more effort to browse through the memory which means it's slower and if you have many different players > more threads > more chance of a deadlock.. I think that's the only crashing reason as we define crashing to be the not being able to pass char selection.

I know it isn't just the high memory because at my old server.. drakoms v62.. I used to have 150+ online at a time and memory leaks caused me to go over 70% cpu and RAM all the time yet we didn't always crash.. sometimes it took long before it crashed, sometimes it was instant. It always crashed when maple-hosting had CPU peaks from other nodes.
 
Last edited:
Upvote 0
I don't think the RAM or CPU being too high causes a crash directly.. I still think it's the speed of the CPU processing that results in deadlocks when the CPU or memory usage is too high, it just takes the cpu more effort to browse through the memory which means it's slower and if you have many different players > more threads > more chance of a deadlock.. I think that's the only crashing reason as we define crashing to be the not being able to pass char selection.

I know it isn't just the high memory because at my old server.. drakoms v62.. I used to have 150+ online at a time and memory leaks caused me to go over 70% cpu and RAM all the time yet we didn't always crash.. sometimes it took long before it crashed, sometimes it was instant. It always crashed when maple-hosting had CPU peaks from other nodes.
That is true.

While I had my old server, certain things that suggested the presence of deadlocks usually happened when the VPS was lagging.
 
Upvote 0
If your memory (RAM) usage is to high, your JVM will crash as a direct result with an OutOfMemoryError (Note that this is an Error, and not an Exception. You can in theory, try/catch an Error, but it is inadvisable: ).

High CPU usage will not crash a server, the worst it could do is cause lag. Enough lag usually causes the server to AutoDC people (A ping is sent out when an IoSession is detected as idle, and if a pong is not received within a certain interval, the client will be disconnected). Generally this will DC enough people so that the CPU usage returns to reasonable levels.
An exception are infinite loops, which are will cause constant high CPU usage, and it will generally stay that way unless the loop is interrupted somehow (I've yet to see any server with an infinite loop problem though).

Deadlocks actually consume very little CPU. The thread simply 'waits' for the lock or monitor of some object to be released by the thread that currently owns it. It does no processing while waiting...

Thread-safety (I think) is when multiple threads utilize a function or object simultaneously, but the end result is predictable. Usually, deadlocks will occur if you overlook a detail when trying to make something thread-safe. Depending on what thread is deadlocked, your server may or may not crash. For instance: a couple of deadlocked TimerManagerWorker threads may not crash your ChannelServer, but if your IoHandler(MapleServerHandler) is deadlocked, you're screwed. you won't be able to process any incoming data and it will seem like an infinitely long lag spike (I don't think this is very likely though, since you'd have to change a lot for it to have a chance at deadlocking; the default Odin setup has no problems).

A memory leak in the strictest sense, is when you do not remove a reference to an object you are done with/not using anymore (IE. Leaving MapleCharacters in a HashMap). Thus, it is implied that you forgot about removing the reference; you can't clear something you don't know about. A memory leak will continue to grow (slowly) until it consumes up all the available memory. Even if you clear caches you know about, eventually that free memory also be used up and you'll get an OOME.
You most likely won't run out of memory if you're properly caching Map and Item information (It's actually not that much... a set of XMLs is about 500 MB in size? AND that information is much bigger than it's representation in a JVM AND a lot of the XMLs aren't even utilized), so you shouldn't have to release these caches periodically.

Finally:
I still think it's the speed of the CPU processing that results in deadlocks when the CPU or memory usage is too high, it just takes the cpu more effort to browse through the memory which means it's slower and if you have many different players > more threads > more chance of a deadlock..
Um.. wtf is this? You're stringing together phrases but they don't make sense when put together that way ( sorry =/ )...
 
Last edited:
Upvote 0
- Clearing your allocated resources after using them.
- Using TCP instead of RMI (more memory available and better performance).
- Fixing any memory/performance compromising methods.
- Reusing available resources whenever possible.
- Don't write everything to the console. It will be better if you log everything in a file memory-wise, because the hard disk has it on it's memory and not the main memory.
- Don't use a GUI (optional, and memory whore with Java).

It is all about making improvements upon your already existing code, or restarting from scratch. Of course, the real question is: "is it really worth revising?"
 
Last edited:
Upvote 0
That's what I was trying to say


When you reach above 2500 concurrent users you will notice that 8gb are running short. But once again: Fixing this can/should not be accomplished by using smaller primitive types.

2.5k users isn't a good idea anyway. I think that 2000 connections per box is a good amount.

- David

---------- Post added at 08:49 AM ---------- Previous post was at 07:06 AM ----------

Also, adding one more thing: in Java a boolean is 16 bits and a byte is 8 bits, if you use a byte you could save 8 bits :)
 
Upvote 0
2.5k users isn't a good idea anyway. I think that 2000 connections per box is a good amount.

- David

---------- Post added at 08:49 AM ---------- Previous post was at 07:06 AM ----------

Also, adding one more thing: in Java a boolean is 16 bits and a byte is 8 bits, if you use a byte you could save 8 bits :)

boolean: The boolean data type has only two possible values: true and false. Use this data type for simple flags that track true/false conditions. This data type represents one bit of information, but its "size" isn't something that's precisely defined.
How'd you figure it was 16 bits?
 
Upvote 0
More people should look into this:
 
Last edited:
Upvote 0
1) Remove the RMI. RMI causes more lag because of ObjectOutputStream/ObjectInputStream.

2) Replace the RMI with a faster method, like TCP/IP

3) Most server OutOfMemoryErrors are caused by cache overflow. Occasionally clear the cache.

4) Do NOT call System.gc(). gc() will only cause more leaks to happen.

5) Xmx is not a good way of allocating extra memory. You should fix the memory leaks, rather than try to force more memory into the JVM.

6) Close all PreparedStatements/ResultSets after use. A lot of leaks happen because of that.

6) Instead of Object obj, use WeakReference<Object> obj

7) Do not call classes which DON'T have to be loaded. Even better, create 2 projects for LoginServer/WorldServer

8) Rather than String s = "String " + " String", use StringBuilder sb = new StringBuilder(); sb.append(..);

got it from here. http://forum.ragezone.com/f427/release-protips-increasing-performance-564013/
 
Upvote 0
It does nothing. Look it up. Java automatically changes a method to final if there's nothing overriding it.

I'd like to see where you got this info. Because the JVM is a dynamic virtual machine, there's no way it's able to tell whether a class is final or not at the time of loading, what if I called ClassLoader#loadClass(..) and that loaded a class that subclassed the subject class?

- David

---------- Post added at 10:58 AM ---------- Previous post was at 10:53 AM ----------

How'd you figure it was 16 bits?

The implementing JVM is free to decide however large it wants the boolean to be, but HotSpot implements it using 8 bits (said 16 by mistake, so using a byte or boolean has the same performance):

typedef unsigned char jboolean;
typedef unsigned short jchar;
typedef short jshort;
typedef float jfloat;
typedef double jdouble;

However I believe in an older version of Java it was 16 bits..

- David
 
Last edited:
Upvote 0
Oh really? :lol:

So yes, really. It's useless.


(using final in classes and methods isn't for performance...)
(methods don't necessarily improve performance at all)


Also get the new netbeans. It gives a warning and reason for all final methods and classes. Generally it's bad to make classes final since you can't do anything with them

edit:
the same goes for final local variables. the performance gain is so minimal or non-existent, it doesn't do anything (but it was mentioned before in this thread). many sites also list this fact but i'm not going to go search for them this time.
 
Last edited:
Upvote 0
So yes, really. It's useless.


(using final in classes and methods isn't for performance...)
(methods don't necessarily improve performance at all)


Also get the new netbeans. It gives a warning and reason for all final methods and classes. Generally it's bad to make classes final since you can't do anything with them

edit:
the same goes for final local variables. the performance gain is so minimal or non-existent, it doesn't do anything (but it was mentioned before in this thread). many sites also list this fact but i'm not going to go search for them this time.

Personally I love coding with this special Eclipse program which is more personalized for performance based programming.

---------- Post added at 08:26 PM ---------- Previous post was at 07:32 PM ----------

A good book to read if you want to program efficiently. I read this book, I think its a GREAT book to refer to.

jon5477 - Improving Server Stability - RaGEZONE Forums
 
Upvote 0
Back