Java-Gaming.org    
Featured games (91)
games approved by the League of Dukes
Games in Showcase (576)
games submitted by our members
Games in WIP (498)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  [SOLVED] Ghost thread eating performance! LWJGL...  (Read 4065 times)
0 Members and 1 Guest are viewing this topic.
Offline theagentd
« Posted 2011-09-18 15:46:17 »

So I got a lot of my programming sorted out recently and managed to get a playable part of my game working. However, I saw horrid performance. Playing around with it for a while, I realized that it "goes away" after a while, doubling my FPS like a flip of a switch. The time it takes for it to start running decently is completely random. Sometimes it's instant, sometime's it's more than a minute, which is obviously unacceptable.
First I obviously checked if anything else was running in the background. Nothing. Then I saw that my game's java.exe dances at around 40-45% processor usage during this time, dropping to 25% (100% on one of four cores) when the game starts running as it should. The game doesn't even create a single thread manually, so it should be impossible for it to use 100% on one core (25% in the task manager). I'm basically having a ghost thread draining CPU power in some weird way. I've tried to monitor threads with the profiler in Netbeans, but I can't see any thread stopping or pausing when the lag disappears.

PS: Lol, Minecraft seems to get this too.

Myomyomyo.
Offline kappa
« League of Dukes »

JGO Kernel


Medals: 70
Projects: 15


★★★★★


« Reply #1 - Posted 2011-09-18 16:56:45 »

You're not by any chance using the sleeping thread trick to fix timing issues on windows? (I do know that minecraft uses this).
Offline theagentd
« Reply #2 - Posted 2011-09-18 17:48:52 »

Like I said, I'm not doing anything with threads. I'm gonna try to use that trick now.
EDIT: Nope, nothing. Sigh... Just added a very CPU bound feature, and now it doesn't speed up even after waiting minutes. What the heck is doing that?! I've even tried both JDK 6 and 7!

Myomyomyo.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Conner_

Senior Newbie




~ Java Game Dev ~


« Reply #3 - Posted 2011-09-18 18:56:12 »

Quote
Like I said, I'm not doing anything with threads.

Your game isn't doing anything on threads? Or do I misunderstand?

Java runs multiple threads in and of itself, and if you aren't organising your program's components into threads, Java will try to run everything on a single thread. That being said, it will probably be really slow, and it will probably eat up CPU.

Find me on GitHub: connergdavis
My current project is called Obsidian Framework and is a private Minecraft server application used to play Multiplayer.
Offline theagentd
« Reply #4 - Posted 2011-09-18 19:25:38 »

I'm not creating even a single Thread object, so the fact that another thread slows down my game seems to point to a problem with LWJGL. No problem occurs if I run the exact same code, but without rendering. The scary part is that I can't identify WHICH thread is eating performance.

Myomyomyo.
Offline Riven
« League of Dukes »

JGO Overlord


Medals: 605
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #5 - Posted 2011-09-18 19:35:48 »

What happens when you put a sleep(100) in your mainloop?

This might seem like an odd question, but it might be a multi-threaded GPU driver, that will also 'calm down' when you make your game idling.

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Offline loom_weaver

JGO Coder


Medals: 17



« Reply #6 - Posted 2011-09-18 20:43:55 »

Can you post a reproducer so that we can try it on our systems?

I've been using lwjgl 2.7.1 on Mac Snow Leopard with Java 1.6.0_26 for the last couple of months and haven't had any trouble with lwjgl's performance or rogue processes.
Offline Z-Man
« Reply #7 - Posted 2011-09-18 22:01:33 »

You're not by any chance using the sleeping thread trick to fix timing issues on windows? (I do know that minecraft uses this).
Sorry slightly of topic but is this the sleep trick your talking about?
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
Thread sleeper = new Thread(new Runnable()
{
   public void run()
   {
      while(true)
         try
         {
            Thread.sleep(Long.MAX_VALUE);
         }catch(InterruptedException e)
         {
         }
   }
});
sleeper.setDaemon(true);
sleeper.start();
Offline theagentd
« Reply #8 - Posted 2011-09-18 22:41:05 »

FOUND IT! Damn you, Threaded optimization!
The problem relates to the setting Threaded optimization in the Nvidia control panel! The ghost thread was a video driver thread! I've actually been experimenting with that setting. The default is Auto, which apparently tries to use multithreading when the game is started and then falls back to single threading when it realizes it gets better performance for less CPU power from that after often less than a second. HOWEVER, if what you're doing is very CPU heavy (i.e. the graphics card is idling a lot) which I was doing it will apparently not fall back as it should. Setting the setting to Off solves this.
Thanks to everyone who posted, especially Riven! xD And yes, that is the exact same sleep fix that I used (except I didn't use an infinite loop, fixed xD).

Myomyomyo.
Offline kappa
« League of Dukes »

JGO Kernel


Medals: 70
Projects: 15


★★★★★


« Reply #9 - Posted 2011-09-18 23:07:02 »

Sorry slightly of topic but is this the sleep trick your talking about?
Yup, that's the one (or a variation of it).
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Z-Man
« Reply #10 - Posted 2011-09-19 00:36:42 »

Sorry slightly of topic but is this the sleep trick your talking about?
Yup, that's the one (or a variation of it).
Cool... so is it only needed on Windows? Does it really help if you have it running on Mac or Linux?
Offline gimbal

JGO Coder


Medals: 25



« Reply #11 - Posted 2011-09-19 11:23:27 »

It won't help, its a Windows specific fix in the JVM. As long as a thread is asleep the JVM keeps the resolution at 1ms to make waking up threads/locks/timers more precise. As soon as there is no sleeping thread the resolution is reset to the default 10 or 15ms (system dependent, happy happy joy joy).

Because the precision is already high enough (1-2ms) on Linux or Mac platforms out of the box, the JVM for those platforms does not have the workaround and so the sleeping thread trick adds nothing.
Offline ra4king

JGO Kernel


Medals: 322
Projects: 2
Exp: 4 years


I'm the King!


« Reply #12 - Posted 2011-09-20 02:08:47 »

So basically:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
if(System.getProperty("os.name").startsWith("Win")) {
    new Thread() {
        {
            setDaemon(true);
            start();
        }
       
        public void run() {
            while(true)
                try{
                    Thread.sleep(Long.MAX_VALUE);
                }
                catch(Exception exc) {}
        }
    }
}

Offline princec

JGO Kernel


Medals: 282
Projects: 3
Exp: 16 years


Eh? Who? What? ... Me?


« Reply #13 - Posted 2011-09-20 12:15:47 »

Hm we should probably just build this in to LWJGL.

Cas Smiley

Offline gimbal

JGO Coder


Medals: 25



« Reply #14 - Posted 2011-09-20 15:39:08 »

Hm we should probably just build this in to LWJGL.

Cas Smiley

As apposed to the JVM itself, yes. Sun already attempted that once with a command line switch, but they managed to fail in a very epic way:

http://bugs.sun.com/view_bug.do?bug_id=6435126

Note that the sleeping thread hack fix is actually mentioned as a workaround to this bug!
Offline delt0r

JGO Coder


Medals: 22


Computers can do that?


« Reply #15 - Posted 2011-09-20 16:09:50 »

Why is it needed? what does it fix?

I have no special talents. I am only passionately curious.--Albert Einstein
Offline kappa
« League of Dukes »

JGO Kernel


Medals: 70
Projects: 15


★★★★★


« Reply #16 - Posted 2011-09-20 16:23:42 »

As apposed to the JVM itself, yes. Sun already attempted that once with a command line switch, but they managed to fail in a very epic way:
Wow, that is epic fail indeed. Whats even worse is that they want to keep the broken switch in there.
Offline ra4king

JGO Kernel


Medals: 322
Projects: 2
Exp: 4 years


I'm the King!


« Reply #17 - Posted 2011-09-21 00:29:41 »

Why is it needed? what does it fix?
In Windows, the default resolution of the timer is about 10 ms. This trick forces the JVM to use the High Resolution timer for more accurate sleeping.

Offline gimbal

JGO Coder


Medals: 25



« Reply #18 - Posted 2011-09-22 12:49:50 »

As apposed to the JVM itself, yes. Sun already attempted that once with a command line switch, but they managed to fail in a very epic way:
Wow, that is epic fail indeed. Whats even worse is that they want to keep the broken switch in there.

Wanted. Sun is gone, Oracle is now in charge. Seeing what the last dozen updates to Java 6 have brought, it is clear that Oracle is more inclined to apply fixes that break backwards compatibility. What I don't like is that they often do so silently :/
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

xsi3rr4x (18 views)
2014-04-15 18:08:23

BurntPizza (15 views)
2014-04-15 03:46:01

UprightPath (28 views)
2014-04-14 17:39:50

UprightPath (13 views)
2014-04-14 17:35:47

Porlus (29 views)
2014-04-14 15:48:38

tom_mai78101 (54 views)
2014-04-10 04:04:31

BurntPizza (111 views)
2014-04-08 23:06:04

tom_mai78101 (212 views)
2014-04-05 13:34:39

trollwarrior1 (181 views)
2014-04-04 12:06:45

CJLetsGame (187 views)
2014-04-01 02:16:10
List of Learning Resources
by Longarmx
2014-04-08 03:14:44

Good Examples
by matheus23
2014-04-05 13:51:37

Good Examples
by Grunnt
2014-04-03 15:48:46

Good Examples
by Grunnt
2014-04-03 15:48:37

Good Examples
by matheus23
2014-04-01 18:40:51

Good Examples
by matheus23
2014-04-01 18:40:34

Anonymous/Local/Inner class gotchas
by Roquen
2014-03-11 15:22:30

Anonymous/Local/Inner class gotchas
by Roquen
2014-03-11 15:05:20
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!