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:
I'm sorry, but when you start off a source that uses listed caches and per-request database loading, you have few chances of optimizing performance or speed. Odin needs a whole new code to run fresh. Seriously, if you're a rather experienced programmer, read some of its methods, and you'll instantly notice blatant overuses of memory.

Sorry if this is a really late response, but can you elaborate and clarify on "listed cache"?
 
Last edited:
Upvote 0
Do not rely on finalizers to execute time critical code. Avoid using finalizers since there is no gaurantee that finalizers will be executed. If a finalizer is not executed, several finalizers from different threads can be waiting to completely execute. If this happens, its a great way to have your program come to a grinding halt.
An example of a finalizer:
Code:
try {
// code that throws exceptions
} finally {
// do what must be done here.
}

Also if an exception is thrown and not caught, the object can be corrupted which will return or merely do the wrong thing. This is also a fatal problem for your programs. Therefore avoid finalizers.

You are wrong. "Finally" is reserved for code to be executed no matter if the instructions that throws an Exception works or not. "Finalizers" don't come into play until the Garbage Collector gets invoked, and that has nothing to do with try, catch, and finally blocks. Each class gets finalized a different way depending on their finalize() method (which is inherited from the java.lang.Object class).

@iKnowRight
Just use isEmpty() to test an empty string.
 
Upvote 0
You are wrong. "Finally" is reserved for code to be executed no matter if the instructions that throws an Exception works or not. "Finalizers" don't come into play until the Garbage Collector gets invoked, and that has nothing to do with try, catch, and finally blocks. Each class gets finalized a different way depending on their finalize() method (which is inherited from the java.lang.Object class).

Thats fine, believe what you want. But don't think your smarter than Josh Bloch whos coded for the Java API and currently works at Google. I see you haven't been talking to or listening to developers that work at Google.

Josh Bloch said:
Finalizers are unpredictable, often dangerous, and generally unnecessary. Their use can cause erratic behavior, poor performance, and portability problems. Finalizers have a few valid uses, which we'll cover later in this item, but as a rule of thumb, finalizers should be avoided. C++ programmers are cautioned not to think of finalizers as the analog of C++ destructors. In C++, destructors are the normal way to reclaim the resources associated with an object, a necessary counterpart to constructors. In the Java programming language, the garbage collector reclaims the storage associated with an object when it becomes unreachable, requiring no special effort on the part of the programmer. C++ destructors are also used to reclaim other nonmemory resources. In the Java programming language, the try-finally block is generally used for this purpose. There is no guarantee that finalizers will be executed promptly. It can take arbitrarily long between the time that an object becomes unreachable and the time that its
finalizer is executed. This means that nothing time-critical should ever be done by a finalizer. For example, it is a grave error to depend on a finalizer to close open files because
open file descriptors are a limited resource. If many files are left open because the JVM is tardy in executing finalizers, a program may fail because it can no longer open files.The promptness with which finalizers are executed is primarily a function of the garbage
collection algorithm, which varies widely from JVM implementation to JVM implementation.
The behavior of a program that depends on the promptness of finalizer execution may
likewise vary. It is entirely possible that such a program will run perfectly on the JVM on
which you test it and then fail miserably on the JVM favored by your most important customer. Tardy finalization is not just a theoretical problem. Providing a finalizer for a class can, under rare conditions, arbitrarily delay reclamation of its instances. A colleague recently debugged a long-running GUI application that was mysteriously dying with an OutOfMemoryError. Analysis revealed that at the time of its death, the application had thousands of graphics objects on its finalizer queue just waiting to be finalized and reclaimed. Unfortunately, the finalizer thread was running at a lower priority than another thread in the application, so objects weren't getting finalized at the rate they became eligible for finalization. The JLS makes no guarantees as to which thread will execute finalizers, so there is no portable way to prevent this sort of problem other than to refrain from using finalizers.
Not only does the JLS provide no guarantee that finalizers will get executed promptly, it
provides no guarantee that they'll get executed at all. It is entirely possible, even likely, that a
program terminates without executing finalizers on some objects that are no longer reachable. As a consequence, you should never depend on a finalizer to update critical persistent state. For example, depending on a finalizer to release a persistent lock on a shared resource such as a database is a good way to bring your entire distributed system to a grinding halt.
 
Last edited:
Upvote 0
Thats fine, believe what you want. But don't think your smarter than Josh Bloch whos coded for the Java API and currently works at Google. I see you haven't been talking to or listening to developers that work at Google.
*face palm* The example you gave is completely wrong though, and after reading over the quote you misinterpreted what he said.
Josh Bloch said:
C++ destructors are also used to reclaim other nonmemory resources. In the Java programming language, the try-finally block is generally used for this purpose.
Since Java lacks a destructor method with objects (like C++), some programmers use the "try-finally" block to free no longer used resources, and that is purely based on style alone and STILL has nothing to do with finalizers.
 
Upvote 0
.... Jon5477, You fundamentally misunderstand what a finalizer is..

finalize() is a method from the Object class which is inherited by every Object. It is correct that finalizers should not be used for time-critical code, but I have not seen ANY source which even overrides finalize().


The following is a Try-Finally block, which is COMPLETELY different from a finalizer:
Code:
try {} finally {}
It is highly useful in ensuring critical code (like closing a PreparedStatement or releasing a lock) is run, even if the method gets thrown an unexpected exception.
 
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 (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.

Your right about "that server stability is not impossible".
It just takes a dedicated team. However, every now and then a drama queen becomes part of the team.
Well, it could be done alone, but would be quicker with a team, and a plan.
 
Upvote 0
*face palm* The example you gave is completely wrong though, and after reading over the quote you misinterpreted what he said.

Since Java lacks a destructor method with objects (like C++), some programmers use the "try-finally" block to free no longer used resources, and that is purely based on style alone and STILL has nothing to do with finalizers.

.... Jon5477, You fundamentally misunderstand what a finalizer is..

finalize() is a method from the Object class which is inherited by every Object. It is correct that finalizers should not be used for time-critical code, but I have not seen ANY source which even overrides finalize().


The following is a Try-Finally block, which is COMPLETELY different from a finalizer:
Code:
try {} finally {}
It is highly useful in ensuring critical code (like closing a PreparedStatement or releasing a lock) is run, even if the method gets thrown an unexpected exception.
My reply:
Josh Bloch said:
Not only does the JLS provide no guarantee that finalizers will get executed promptly, it
provides no guarantee that they'll get executed at all. It is entirely possible, even likely, that a
program terminates without executing finalizers on some objects that are no longer reachable. As a consequence, you should never depend on a finalizer to update critical persistent state. For example, depending on a finalizer to release a persistent lock on a shared resource such as a database is a good way to bring your entire distributed system to a grinding halt.

Your programs might work fine and dandy with finalizers, but know this. Mass distributed programs have a more likely chance of failing because each system is entirely different. So stick with whatever you believe. I'm not going to convince you not to use finalizers. Its not my program thats going to crash, so I dont give a **** what you do with your programs.
 
Upvote 0
@jon5477

Well, since you're gonna keep invoking the fallacy of Argument from Authority, while being completely wrong in understanding that a try-finally block is NOT a finalizer anyway... Let me respond with an article written by your hero.


Joshua Bloch said:
So what should you do instead of writing a finalizer for a class whose objects encapsulate resources that require termination, such as files or threads? Just provide an explicit termination method ...

Explicit termination methods are typically used in combination with the try-finally construct to ensure termination. Invoking the explicit termination method inside the finally clause ensures that it will get executed even if an exception is thrown while the object is being used:

// try-finally block guarantees execution of termination method
Foo foo = new Foo(...);
try {
// Do what must be done with foo
...
} finally {
foo.terminate(); // Explicit termination method
}
See? He actually suggests Try-Finally blocks AS A CORRECT ALTERNATIVE to finalizers in explicit termination. Please look up words or concepts you don't understand BEFORE quoting wildly. Thanks.
 
Last edited:
Upvote 0
@jon5477

Well, since you're gonna keep invoking the fallacy of Argument from Authority, while being completely wrong in understanding that a try-finally block is NOT a finalizer anyway... Let me respond with an article written by your hero.



See? He actually suggests Try-Finally blocks AS A CORRECT ALTERNATIVE to finalizers in explicit termination. Please look up words or concepts you don't understand BEFORE quoting wildly. Thanks.

Finalizers can be used, however to release non-time-critical resources such as bytes uploaded to the graphics card. For example, since we know that when the GC collects an object, all strong references to it have perished and we can use a finalizer:

Code:
class Texure {
  int [][] pixels;
  int texID;

  ... omitted

  @Override public void finalize() throws Exception { 
      super.finalize();
      glDeleteTextures(1, texID);
  }
}

As you can see, the above snippet releases a texture uploaded to the graphics driver when the garbage collector determines that this object is obsolete. A finalizer used in this way is OK, although there are better ways.
 
Upvote 0
A finalizer is for garbage collecting for cleanup code and not for try-catch-finally. It is called when there are no more references to the code. My guess is that things like PrepareStatement has a finalizer that closes it since I've heard it closes itself when it goes out of scope.

@emilyx3
LocalMS source has a finalize in some map object thing
 
Last edited:
Upvote 0
Back