Page 1 of 2 12 LastLast
Results 1 to 20 of 32
  1. #1
    Raymond is offline Member
    Join Date
    Jan 2010
    Posts
    32
    Rep Power
    0

    Default Java optimization

    Hi.

    What makes Java code more optimized, so far I have:

    • Cache
    • Dont gc.
    • Synchronization


    Help please, I need this for a game server. XMX is bad way to allocate memory? I use RMI.

  2. #2
    mrmatt1111's Avatar
    mrmatt1111 is offline Senior Member
    Join Date
    Aug 2009
    Location
    San Jose, CA, USA
    Posts
    320
    Rep Power
    6

    Default

    Using a profiler usually helps. Netbeans, for example, has a profiler plugin that can be used to look for bottlenecks in CPU usage and memory. You can even select a small subset of classes that you are interested in.

    As far as caching... that is a good idea to do when you can.

    "Dont gc." Umm... leave the garbage collection alone.

    "Synchronization" that has nothing to do with efficiency.

    "XMX" nothing wrong with this.
    My Hobby Project: LegacyClone

  3. #3
    Raymond is offline Member
    Join Date
    Jan 2010
    Posts
    32
    Rep Power
    0

    Default

    "XMX" nothing wrong with this.
    I heard its not a proper way to allocate memory, its like forcing RAM when windows cannot take.

  4. #4
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,947
    Rep Power
    19

    Default

    Are you talking the xMx switch for the JRE?

  5. #5
    Raymond is offline Member
    Join Date
    Jan 2010
    Posts
    32
    Rep Power
    0

    Default

    I think so, basically its a game server and on the channel.bat it has XMX - .

    I heard its a bad way of allocating memory.

  6. #6
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,947
    Rep Power
    19

    Default

    If you're talking about xMx (ala java -xMx512M) then I have no idea where you get the idea about memory allocation. It merely informs the JRE "this is the maximum memory you can have"...and without it it uses some rather small default value that's usually insufficient.

    I find it hard to believe someone would say that that switch is a bad thing...

  7. #7
    Raymond is offline Member
    Join Date
    Jan 2010
    Posts
    32
    Rep Power
    0

    Default

    I heard also only if you get memory leaks you use XMX.

  8. #8
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,947
    Rep Power
    19

    Default

    I do honestly wonder if we're talking about the same thing.
    Especially since you capitalise it.

    I have not worked on a web project that did not require xMx to be set to something other than the default because, otherwise, there would be an OutOfMemory error.

  9. #9
    Raymond is offline Member
    Join Date
    Jan 2010
    Posts
    32
    Rep Power
    0

    Default

    Here you will see what I mean : XiuzSource - Revision 23: / look at the .bat files. You will get what I mean.

  10. #10
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,947
    Rep Power
    19

    Default

    Can't you just post the relevant bits here?
    Not that I'm paranoid or anything...:)

  11. #11
    Raymond is offline Member
    Join Date
    Jan 2010
    Posts
    32
    Rep Power
    0

    Default

    Sure,

    @echo off
    color b
    @title XiuzSource: Channel
    set CLASSPATH=.;dist\xiuzsource.jar;dist\mina-core.jar;dist\slf4j-api.jar;dist\slf4j-jdk14.jar;dist\mysql-connector-java-bin.jar
    java -Xmx600m -Dnet.sf.odinms.recvops=recvops.properties -Dnet.sf.odinms.sendops=sendops.properties -Dnet.sf.odinms.wzpath=wz\ -Dnet.sf.odinms.channel.config=channel.properties -Djavax.net.ssl.keyStore=filename.keystore -Djavax.net.ssl.keyStorePassword=passwd -Djavax.net.ssl.trustStore=filename.keystore -Djavax.net.ssl.trustStorePassword=passwd net.sf.odinms.net.channel.ChannelServer -Dcom.sun.management.jmxremote.port=13373 -Dcom.sun.management.jmxremote.password.file=jmxrem ote.password -Dcom.sun.management.jmxremote.access.file=jmxremot e.access
    pause
    There thats the part.

  12. #12
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,947
    Rep Power
    19

    Default

    Which is setting the max memory that the JVM can use to 600m.
    At least we're talking about the same thing...:)

    There is nothing wrong with that.
    I don't see why anyone would think that's a bad thing, performance-wise.

  13. #13
    Raymond is offline Member
    Join Date
    Jan 2010
    Posts
    32
    Rep Power
    0

    Default

    How to properly allocate memory for a game server?

  14. #14
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,947
    Rep Power
    19

    Default

    How long is a piece of string?

  15. #15
    Raymond is offline Member
    Join Date
    Jan 2010
    Posts
    32
    Rep Power
    0

    Default

    I dont understand you o.o

  16. #16
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,947
    Rep Power
    19

    Default

    You asked a question we had no hope of actually answering.
    That's assuming your question was how much memory should you allocate to the server via Xmx...

    We don't know your server, what it does, what load is expected...anything in fact.

  17. #17
    Raymond is offline Member
    Join Date
    Jan 2010
    Posts
    32
    Rep Power
    0

    Default

    It's an MMO and runs over 100+ online. RAM: 1.90-2.18GB CPU: 1-10%

    Thats the info. I allocate XMX 2450. It uses MYSQL each time someone logs of or logs in and saves items.

  18. #18
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,947
    Rep Power
    19

    Default

    No, you don't understand.
    We simply cannot size your JVM for you.
    You have to run load tests based on your assumptions about what the likely load on it will be, and then see what the memory usage looks like.

    We cannot do that.

  19. #19
    Raymond is offline Member
    Join Date
    Jan 2010
    Posts
    32
    Rep Power
    0

    Default

    What do you mean troll? I want to improve on the codings.

  20. #20
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,947
    Rep Power
    19

    Default

    There isn't an 'r' in the name...

    And sizing a JVM is not something we can do.

    You've given it 2.5G (possibly), which is more than your available RAM. I can tell you that is not a good thing, since the JVM will eventually end up having to page memory. The most you can probably give is about 1G, to ensure you have enough space for OS stuff as well. But that doesn't mean you should give it that much. Which takes me back to you needing to do the legwork to figure out how big your JVM needs to be.

    If you have some other question then by all means ask that one, but the memory requirements of you app isn't one we can deal with here.

Page 1 of 2 12 LastLast

Similar Threads

  1. Circuit optimization
    By MIA6 in forum New To Java
    Replies: 1
    Last Post: 10-18-2009, 02:14 AM
  2. Optimization of code
    By new_coder in forum New To Java
    Replies: 1
    Last Post: 08-16-2009, 09:38 PM
  3. Query Optimization
    By gilbertsavier in forum JDBC
    Replies: 0
    Last Post: 08-05-2009, 10:36 AM
  4. Replies: 7
    Last Post: 12-16-2008, 06:44 PM
  5. java code optimization
    By hey in forum New To Java
    Replies: 0
    Last Post: 02-10-2008, 05:16 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •