Page 1 of 2 12 LastLast
Results 1 to 20 of 28
  1. #1
    varann is offline Member
    Join Date
    Sep 2009
    Posts
    8
    Rep Power
    0

    Default Performance problem

    Hi all,
    for a long time I've been avoiding forums because most of the things are already solved :) But now I am stuck. I made an application. It consists of simple animation and reading/writing to DB. I run it on xUbuntu with java6, apache and mysql (from repos)

    I read status from DB every 5 - 10 sec and write to DB if the button is pressed.

    Every thing works OK, but after 6, 7 hours the animation gets stuck and button response is slow (first insert into DB is OK but the next one can be done 5 or more sec. later). Reading from DB is normal. I guess I have a DB connection problem?
    Somewhere I read that closing the statement and connection can be omitted so i didn't closed it. Maybe this is the problem?
    Connection is made to localhost so actually connecting and closing isn't such a big problem...

    Any tips?

    Tnx

  2. #2
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    8

    Default

    Quote Originally Posted by varann View Post
    Hi all,
    for a long time I've been avoiding forums because most of the things are already solved :) But now I am stuck. I made an application. It consists of simple animation and reading/writing to DB. I run it on xUbuntu with java6, apache and mysql (from repos)

    I read status from DB every 5 - 10 sec and write to DB if the button is pressed.

    Every thing works OK, but after 6, 7 hours the animation gets stuck and button response is slow (first insert into DB is OK but the next one can be done 5 or more sec. later). Reading from DB is normal. I guess I have a DB connection problem?
    Somewhere I read that closing the statement and connection can be omitted so i didn't closed it. Maybe this is the problem?
    Connection is made to localhost so actually connecting and closing isn't such a big problem...

    Any tips?

    Tnx
    1.) Always close the connections.
    2.) Make sure you are not running the database connection code from the EDT.

  3. #3
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,183
    Rep Power
    20

    Default

    Quote Originally Posted by varann View Post
    Hi all,
    Any tips?

    Tnx
    I think you're going to need to post some code, but it sounds like you're leaking something somewhere. If you're only doing this every 5-10 seconds then reconnect each time, just to be sure.

    Keeping the connection open on a single threaded, standalone app isn't a problem, though you need to take into account that it could time out if you don't use it for a while. Shouldn't be the case with yours.

    ETA: Sorry, got interrupted...where was I? I wouldn't hold onto Statements, but you might keep your PreparedStatements. That used to give you a gain, but I'm not sure it's still the case with most drivers which (I think) do some level of cacheing these days.

    ETA again: Apache? So this isn't a standalone then?
    Last edited by Tolls; 09-09-2009 at 01:09 PM.

  4. #4
    corlettk is offline Member
    Join Date
    Apr 2009
    Location
    Brisbane
    Posts
    86
    Rep Power
    0

    Default

    I can only reiterate that anything that slows down the longer it runs is probably suffering from a resource leak. I would (forgive me) suspect your code as apposed to a JDBC implementation (which is presumably from a reputable source?).

    Try profiling your application. Two general rules of thumb:
    1. If you open it, close it... Allways.
    2. Never eat an exception.

    Cheers. Keith.

  5. #5
    varann is offline Member
    Join Date
    Sep 2009
    Posts
    8
    Rep Power
    0

    Default

    Oh... tnx for the replys!

    Apache? So this isn't a standalone then?
    I use apache just for stats that can be read from other PC.

    I think you're going to need to post some code, but it sounds like you're leaking something somewhere. If you're only doing this every 5-10 seconds then reconnect each time, just to be sure.
    I closed the connections now. But still the same.

    which is presumably from a reputable source?
    from article www .kitebird. com/articles/jdbc.html

    Try profiling your application.
    Tnx, I've installed it. Would it (you) help if I attach some printscreen?
    For now I can see that the Heap is slowly increasing. More concerning is the CPU from VisulVM which is increasing (in 4 hours it went from 10% to 50%)

    I probbably did something dumm here... Since I can't poste the code (to many rows :) ), I can describe what am I doing.

    I have a runnable class for the animation. It's a frame with background image and a clock (time date). Every few seconds I redraw the part of the frame (animation). I invoke the redraw from the other class.

    In other class I do the math. I have 2 timers. One for redrawing the animation, and one for a button delay (you can press it every few seconds). At every refresh I read from DB and recalculate the values based on current time increase the counter and write it to DB.

    Ok, I don't know if this description will help, but I just need few pointers what could be the cause (timer, redrawing, DB,..?).

  6. #6
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,183
    Rep Power
    20

    Default

    Quote Originally Posted by varann View Post
    Oh... tnx for the replys!


    I use apache just for stats that can be read from other PC.


    I closed the connections now. But still the same.


    from article www .kitebird. com/articles/jdbc.html


    Tnx, I've installed it. Would it (you) help if I attach some printscreen?
    For now I can see that the Heap is slowly increasing. More concerning is the CPU from VisulVM which is increasing (in 4 hours it went from 10% to 50%)

    I probbably did something dumm here... Since I can't poste the code (to many rows :) ), I can describe what am I doing.

    I have a runnable class for the animation. It's a frame with background image and a clock (time date). Every few seconds I redraw the part of the frame (animation). I invoke the redraw from the other class.

    In other class I do the math. I have 2 timers. One for redrawing the animation, and one for a button delay (you can press it every few seconds). At every refresh I read from DB and recalculate the values based on current time increase the counter and write it to DB.

    Ok, I don't know if this description will help, but I just need few pointers what could be the cause (timer, redrawing, DB,..?).
    Try and get some memory dumps and stick 'em in an analyser (Eclipse has a plugin), early on, as it starts to slow down, then when it gets quite bad. Should give you a good idea what objects are filling up the memory.

  7. #7
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    8

    Default

    Is your code unit testable? i.e can you test just the DB insert part separately from the animation part?

  8. #8
    emceenugget is offline Senior Member
    Join Date
    Sep 2008
    Posts
    564
    Rep Power
    7

    Default

    it might be possible that you're creating objects faster than the garbage collector can remove them. don't know what your code is so i can really say is that where possible, try to reuse objects. i really don't know

  9. #9
    varann is offline Member
    Join Date
    Sep 2009
    Posts
    8
    Rep Power
    0

    Default

    I played arround with disabling animation an doing only DB inserts and the other way arround. The only diference is in Heap size. CPU usability is growing...

    I've installed Memory Analizer and I get this:

    Problem Suspect 1
    The class "java.lang.ref.Finalizer", loaded by "<system class loader>", occupies 22.277.704 (57,30%) bytes.

    Keywords
    java.lang.ref.Finalizer


    Problem Suspect 2
    One instance of "sun.awt.image.IntegerInterleavedRaster" loaded by "<system class loader>" occupies 5.243.216 (13,49%) bytes. The memory is accumulated in one instance of "int[]" loaded by "<system class loader>".

    Keywords
    sun.awt.image.IntegerInterleavedRaster
    int[]


    Problem Suspect 3
    One instance of "sun.awt.image.IntegerInterleavedRaster" loaded by "<system class loader>" occupies 5.243.216 (13,49%) bytes. The memory is accumulated in one instance of "int[]" loaded by "<system class loader>".

    Keywords
    sun.awt.image.IntegerInterleavedRaster
    int[]

    Any help?

  10. #10
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,183
    Rep Power
    20

    Default

    The analyser should allow you to see where those things are built. That is, the owning objects. The Finalizer bit is the thing that stocks up finalizers to be called after an object is unreachable, but before it gets garbage collected. So you have a bunch of them queued up. Not sure what you have in there that might have finalisers, though.

    The two rasters are probably just the graphic your using, possibly at a time when you have two of them up? No idea how big it is supposed to be (that is how big the graphic is), so I can't say if that's a lot or not. Those don't look to me like the problem, though.

    I'd say emceenugget is closest in that something to do with objects containing finalisers is causing the collector to run slow trying to clear out dead objects. Dig into the Finalizer in the memory analyser.

  11. #11
    varann is offline Member
    Join Date
    Sep 2009
    Posts
    8
    Rep Power
    0

    Default

    Hi :)

    Well I left the program running whole night. Animation is s(t)ucking, and insertion into DB can be done every few seconds. CPU is at 4%, memory is normal! I'm just guessing that if the animation would be the problem, CPU or memory would be full?

    In this case, first insertion into DB (button pressed) is done "normally" the second can not be done. After second or two, insert can be done.

    Yesterday actually JavaVM was increasing my CPU usage.

    I only need help because I don't have much time. Could anyone take a look of the heap dump or can I send the code???

    Right now I've changed animation speed and selection from DB. While making selection from DB more rapidly increasing of heap is much biger than in fast animation.

  12. #12
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,183
    Rep Power
    20

    Default

    Quote Originally Posted by varann View Post
    Hi :)

    Well I left the program running whole night. Animation is s(t)ucking, and insertion into DB can be done every few seconds. CPU is at 4%, memory is normal! I'm just guessing that if the animation would be the problem, CPU or memory would be full?

    In this case, first insertion into DB (button pressed) is done "normally" the second can not be done. After second or two, insert can be done.

    Yesterday actually JavaVM was increasing my CPU usage.

    I only need help because I don't have much time. Could anyone take a look of the heap dump or can I send the code???

    Right now I've changed animation speed and selection from DB. While making selection from DB more rapidly increasing of heap is much biger than in fast animation.
    You must be able to post something up here, though.

    Without knowing your code the heap dump by itself isn't much use (frankly). You really are in the best position for figuring out what's going on...you know your code.

    This is the bit I can't quite understand:
    "
    In other class I do the math. I have 2 timers. One for redrawing the animation, and one for a button delay (you can press it every few seconds). At every refresh I read from DB and recalculate the values based on current time increase the counter and write it to DB.
    "

  13. #13
    varann is offline Member
    Join Date
    Sep 2009
    Posts
    8
    Rep Power
    0

    Default

    Witch part should I post?

    About finalizers... Connection to DB uses finally after creating the connection?!

    I tried to PM you but I'm not allowed. I wouldn't like to post my whole code here...

  14. #14
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    8

    Default

    Which code do you suspect to be the cause?

  15. #15
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    8

    Default

    Quote Originally Posted by varann View Post
    ..

    About finalizers... ....
    Do you really have any finalizers or did you mean finally?

  16. #16
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,183
    Rep Power
    20

    Default

    Quote Originally Posted by varann View Post
    Witch part should I post?

    About finalizers... Connection to DB uses finally after creating the connection?!

    I tried to PM you but I'm not allowed. I wouldn't like to post my whole code here...
    OK, let's start with the db side. Show how you're getting and releasing connections, statements and resultsets.

    Also, which MySQL driver are you using? I don't think the Connection will have a finalise() on it. It's also possible that the Finalizer is a red herring.

    How much memory have you got assigned to your JVM when you run this?

  17. #17
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,183
    Rep Power
    20

    Default

    Quote Originally Posted by r035198x View Post
    Do you really have any finalizers or did you mean finally?
    The biggest thing in the heap is this:
    java.lang.ref.Finalizer

    At 22Mb, that's not insignificant, however it's also not crippling.

    Really need more than 1 heap dump to actually get a picture of the fluctuations in the heap over time. I usually go for 6 or so over a reasonable span (which is pretty much program dependent). The size of the dump also gives a reasonable indicator if memory is going.

  18. #18
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    8

    Default

    They shouldn't be relying on the finalizer methods (if they have them).
    They are not guaranteed to run.

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

    Default

    Quote Originally Posted by r035198x View Post
    They shouldn't be relying on the finalizer methods (if they have them).
    They are not guaranteed to run.
    Quite.
    Largely pointless and can delay things being garbage collected...which might be what we're seeing here. Then again, maybe not. This is one of those things that's not terribly easy to do remotely.

  20. #20
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    8

Page 1 of 2 12 LastLast

Similar Threads

  1. Replies: 1
    Last Post: 06-06-2009, 12:30 AM
  2. loop performance (no problem, just investigating)
    By CJSLMAN in forum New To Java
    Replies: 3
    Last Post: 01-18-2009, 04:02 AM
  3. Applet performance problem...
    By pmrenaud in forum Java Applets
    Replies: 0
    Last Post: 01-07-2009, 04:47 PM
  4. performance problem on osx
    By coldnebo in forum Advanced Java
    Replies: 3
    Last Post: 08-01-2008, 10:39 PM
  5. Performance Of Collections
    By thomasprabu in forum Advanced Java
    Replies: 0
    Last Post: 01-05-2008, 12:17 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
  •