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:
Just curious... where did you get these numbers from? Other than that, good idea for a thread, let's just hope it remains as a discussion that sticks to the topic.

I talked to a GM on MSEA years ago. He was talking about each channel with a capacity of 1200 players and the system specs. I know he said quad core and 4 GB RAM.

Another thing, a way to save memory is coding singleton classes or even static classes so that you would need to create an instance of the class to use the methods. To stop instance creation altogether, refer below.
Code:
protected SampleClass() {
    // This class is static.
}
 
Upvote 0
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. 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:
1. Don't depend on Garbage Collection to free up all of your memory. This is useless when it comes to arrays.
2. For objects that you do not intend to change, make them constant by adding the final keyword.
3. Optimize Threads to run your program efficiently. The trade-off for threading is much harder programming.
4. Limit object creation, create the least amount of objects possible. The less objects you create, the less memory you use.
5. Don't be afraid to use TimerManager often. However, do synchronize methods that will be called by the Thread.
Please contribute helpful ideas and opinions on your take towards a stabler server.

I don't think so. According to GoldenKevin's findings on KDev, it is 2 channels per server. The 'other' servers are probably isolated, e.g. database server, for better resource management. I would also like to know where you obtained your statistics from, stating a mere 'Quad Core' does not mean anything. Bear in mind there is the Intel C2Q series, Xeon, AMD Phenom Quad series, etc, that posses 4 cores.
 
Upvote 0
1. Don't depend on Garbage Collection to free up all of your memory. This is useless when it comes to arrays.
lolwut... if the array is null, it would have been collected by GC due to no reference
just set it to null or removing the entire parent object/ class holding it.

If it's on a method itself, it would be marked for deletion once it's done doing what's specified in the method unless it's reference is being set somewhere else.

5. Don't be afraid to use TimerManager often. However, do synchronize methods that will be called by the Thread.
Not very helpful in terms of stability or speed, it'll just slow down things. sync only when necessary, critical sections such as the objects being handled by multiple players (Eg : Mapobjects, events)
-------------------


Not just this, it's your usual coding practice, how careful you are, how lazy you are and such. As you can see from my v.82 source, I've practically recoded everything.

5 days of uptime, btw our server isn't running on 2.2gb as we have other things such as MySQL, Cash shop server, Login Server, World Server and Channel server.
Code:
[root@celino ~]# top
top - 23:21:51 up 24 days,  5:02,  1 user,  load average: 0.75, 0.77, 0.79
Tasks:  40 total,   1 running,  39 sleeping,   0 stopped,   0 zombie
Cpu(s):  2.7%us,  1.1%sy,  0.0%ni, 96.1%id,  0.1%wa,  0.0%hi,  0.0%si,  0.0%st
Mem:   6291456k total,  3061744k used,  3229712k free,        0k buffers
Swap:        0k total,        0k used,        0k free,        0k cached

  PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND
13741 root      20   0 4442m 2.1g 9576 S 26.0 34.8 183:38.39 java
11703 mysql     15   0  859m 104m 5380 S  2.3  1.7 102:34.47 mysqld
 5633 root      15   0 12608 1200  932 R  0.7  0.0   0:00.03 top
13689 root      17   0 1842m  75m 9324 S  0.7  1.2   2:43.60 java
 5552 root      15   0 97348 3732 2876 S  0.3  0.1   0:00.03 sshd
13655 root      17   0 1827m 114m 9240 S  0.3  1.9   5:08.85 java
    1 root      15   0 10348  320  284 S  0.0  0.0   0:10.45 init
 5606 root      16   0 12064 1716 1280 S  0.0  0.0   0:00.03 bash
 6110 apache    15   0  295m  14m 4412 S  0.0  0.2   0:07.57 httpd
 7403 root      16  -4 12604  196  192 S  0.0  0.0   0:00.00 udevd
 9916 root      15   0  5908  356  304 S  0.0  0.0   0:14.25 syslogd
10237 root      15   0 62616  492  388 S  0.0  0.0   0:49.03 sshd
11617 root      16   0 22536  528  428 S  0.0  0.0   0:00.23 xinetd
11668 root      22   0 11928 1420 1180 S  0.0  0.0   0:00.00 mysqld_safe
11736 root      17   0 40920  256  252 S  0.0  0.0   0:00.00 couriertcpd
11740 root      18   0 33608  220  216 S  0.0  0.0   0:00.00 courierlogger
11807 root      24   0 40920  256  252 S  0.0  0.0   0:00.00 couriertcpd

all :
Code:
  PID TTY          TIME CMD
    1 ?        00:00:10 init
 6110 ?        00:00:07 httpd
 7403 ?        00:00:00 udevd
 7968 ?        00:00:00 sshd
 7971 pts/1    00:00:00 bash
 7993 pts/1    00:00:00 ps
 9916 ?        00:00:14 syslogd
10237 ?        00:00:49 sshd
11617 ?        00:00:00 xinetd
11668 ?        00:00:00 mysqld_safe
11703 ?        01:46:26 mysqld
11736 ?        00:00:00 couriertcpd
11740 ?        00:00:00 courierlogger
11807 ?        00:00:00 couriertcpd
11809 ?        00:00:00 courierlogger
11821 ?        00:00:03 couriertcpd
11823 ?        00:00:01 courierlogger
11839 ?        00:00:00 couriertcpd
11843 ?        00:00:00 courierlogger
11864 ?        00:00:00 qmail-send
11889 ?        00:00:00 splogger
11890 ?        00:00:00 qmail-lspawn
11891 ?        00:00:00 qmail-rspawn
11892 ?        00:00:00 qmail-clean
13589 ?        00:00:27 httpd
13617 ?        00:00:02 crond
13654 ?        00:00:00 launch_world.sh
13655 ?        00:05:19 java
13660 ?        00:00:00 saslauthd
13684 ?        00:00:00 saslauthd
13688 ?        00:00:00 launch_login.sh
13689 ?        00:02:49 java
13740 ?        00:00:00 launch_channel.
13741 ?        03:09:36 java
14046 ?        00:00:00 launch_cs.sh
14047 ?        00:02:14 java
21587 ?        00:00:07 httpd
22358 ?        00:00:05 httpd
23650 ?        00:00:05 httpd
26134 ?        00:00:05 httpd

Frantech ftw :thumbup:

I talked to a GM on MSEA years ago. He was talking about each channel with a capacity of 1200 players and the system specs. I know he said quad core and 4 GB RAM.

Another thing, a way to save memory is coding singleton classes or even static classes so that you would need to create an instance of the class to use the methods. To stop instance creation altogether, refer below.
Code:
protected SampleClass() {
    // This class is static.
}

Hey, those are quite unnecessary since it will be done by the java compiler.
You can simply skip this line when unnecessary.
 
Last edited:
Upvote 0
I might be wrong but declaring all your variables as final won't improve the server stability at all. The compiler replaces final variables with their value at compiling time, not at runtime (how would the compiler do that?). Else than that it's used as flag for classes.
 
Upvote 0
Just a thought I had,

Fix all variables(ex: private int level, could be private short level)...
Not sure if it'll make any diffrence, perhaps a tiny less ramusage? ;D
 
Upvote 0
Just a thought I had,

Fix all variables(ex: private int level, could be private short level)...
Not sure if it'll make any diffrence, perhaps a tiny less ramusage? ;D

If it does make a difference, it's probably 2 bytes difference which means 2 bytes per character.
Not sure if it works this way though :O.
 
Upvote 0
If it does make a difference, it's probably 2 bytes difference which means 2 bytes per character.
Not sure if it works this way though :O.

Well, I don't really think 2 bytes is really sufficient to improve stability... I would personally look out for maps, huge arrays, lists.. maybe loops.
 
Upvote 0
Deagen there's more then one variable that can be "changed".

Even then, variables which aren't references don't really take up much ram compared to all the other things I mentioned. If you want to improve your server's stability, don't go and look for variables that could be an int instead of a long.
 
Upvote 0
Just change integer types where necessary in map loading.

That alone drastically lowered my memory usage.
 
Last edited:
Upvote 0
Don't declare variables within for statements. For example, this is wrong:

Code:
for (int i = 0; i < 5; i++) {
     int a = 0;
     a = mob.getHp();
}


Instead, you would want to do:

Code:
int a;
for (int i = 0; i < 5; i++) {
     a = mob.getHp();
}
 
Upvote 0
Don't declare variables within for statements. For example, this is wrong:

Code:
for (int i = 0; i < 5; i++) {
     int a = 0;
     a = mob.getHp();
}
Instead, you would want to do:

Code:
int a;
for (int i = 0; i < 5; i++) {
     a = mob.getHp();
}
It depends. If "a" isn't needed anywhere else in the statement, there's no use in keeping it.

Also, why did you do a for loop? o_o .
 
Upvote 0
If you have a ResultSet and you are asking for the same row more than once or twice, store the value in a variable...

...instead of
Code:
if (rs.next()) {
Fag fag1 = new Fag(rs.getString("name"));
Fag fag2 = new Fag(rs.getString("name"));
Fag fag2 = new Fag(rs.getString("name"));
}
do
Code:
if (rs.next()) {
String fag = rs.getString("name");
Fag fag1 = new Fag(fag);
Fag fag2 = new Fag(fag);
Fag fag3 = new Fag(fag);
}

Don't declare variables within for statements. For example, this is wrong:

Code:
for (int i = 0; i < 5; i++) {
     int a = 0;
     a = mob.getHp();
}


Instead, you would want to do:

Code:
int a;
for (int i = 0; i < 5; i++) {
     a = mob.getHp();
}

This as far as I know makes no difference. At least David told me so.
 
Upvote 0
Back