We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexSuggestions & BugsSoftware Bugs › cpu usage above 50%
Page Index Toggle Pages: 1
cpu usage above 50% (Read 4417 times)
cpu usage above 50%
May 12th, 2005, 3:18am
 
Hello all

This is a 'general' question rather than a specific syntax;

Is there a way to force a processing sketch to use more than 50% of CPU?

I have some high-geometry count sketch that is getting slow downs but the task manager shows it at a 50 peak usage only - it never goes beyond that.

Is there a way to free the applet to takes more advantage of the processor instead of slowing down?

I'm using a HT-enabled p4; I know that some 3D apps get faster by disabling the HT; is this somehow related? also, I'm not in a browser, I'm running the applet through processing.

thanks!
Re: cpu usage above 50%
Reply #1 - May 12th, 2005, 6:49am
 
The difficulty is that Processing is not a multithreaded renderer, and really has little reason to be one.  If you rewrote your code to be runnable on multiple threads, then it would use 100% of your CPU.

Marcello
Re: cpu usage above 50%
Reply #2 - May 12th, 2005, 8:04am
 
hmmm... this means "forget it" - for me and my skills, at least Smiley
Re: cpu usage above 50%
Reply #3 - May 12th, 2005, 11:55pm
 
It has little reason to be one, except that it's a system to enable complex and realtime 2d and 3d imaging and implements the OpenGL API Wink

I certainly have only a shaky grasp on threads and threadding at this point, but I'm starting to look into it.  I need Processing to be a total CPU hog to get the results that I want! Smiley

There's some glitch where Processing (well, java.exe) can suddenly use 100% of my CPU, and it's really nice to have more than double the frame rates.

dxtx
Re: cpu usage above 50%
Reply #4 - May 13th, 2005, 12:18am
 
I had 50% CPU issues when using OpenGL too.

Christan, toxi and I fixed this problem on my machine this evening by disabling vertical sync (vsync) on the graphics card.

You might like to try it.

Re: cpu usage above 50%
Reply #5 - May 13th, 2005, 5:35am
 
I've long wondered why my heavy java/p5 apps never get more than 50% CPU on WinXP, and have been tinkering with thread priority to no avail. Why would vertical sync keep it at 50%? I observe this even in apps where I've turned display off to optimize rendering speed. I've made sure to avoid

Would be interesting to hear an explanation of this issue and how to get around it, since I'm currently rendering some huge animations with a rendering time of 3 hours for 3000x4 PAL frames.

Cello, what you're saying implies that if one could divide the program load into two threads you would get better performance? I've thought about splitting the image saving off to a separate thread, but the rendering thread would still need to wait for the save to finish before queuing the next save.

It's at times like this I wish I had experience with using a profiler etc..
Re: cpu usage above 50%
Reply #6 - May 13th, 2005, 5:56am
 
actually this is completely news to me, i've never seen it (outside of on dual-processor machines, which is to be expected).

another related thread over here:
http://processing.org/discourse/yabb_beta/YaBB.cgi?board=SoftwareBugs;action=display;num=1115790904

supposedly it goes away when a flash app is running? something weird in java?

are you guys all using P4 hyperthreading CPUs? perhaps java doesn't use this by default?
Re: cpu usage above 50%
Reply #7 - May 13th, 2005, 6:02am
 
after some google digging, this seems as though it may be hyperthreading-oriented.. lots of reports but not a lot of solutions (outside of shutting off HT). there must be some software api for it though that flash or whatever is using to make things speedy again while they're running.

any care to do more google digging on this one?
Re: cpu usage above 50%
Reply #8 - May 13th, 2005, 6:23am
 
I didn't even think of the fact that this computer is hyperthreaded. Indeed the Task Manager shows two (one real, one virtual) CPUs. On my old non-HT laptop the CPU load jumps straight to 100% when running Java. I wonder if the "50%" is really accurate though, since a hyperthreaded CPU should still give more resources to the thread with precedence.

Found this article online http://www.2cpu.com/articles/43_1.html?53284 which seems to indicate that it could be worth experimenting with.

It would seem likely that since Processing and most of my Java apps use one thread for all the heavy work hyper-threading actually leads to part of the CPU being unused. Other sources seem to support this theory. Heh - this is the first time I've heard the term "spaghetti programming", it seems to refer to the practice of linear (i.e. non-parallell, non-threaded) programming.

Will turn HT off in BIOS and see what happens.
Re: cpu usage above 50%
Reply #9 - May 13th, 2005, 6:36am
 
I feel like a troublemaker Tongue  Processing has, in a short time, become one of my favorite things, so it is with this passion that I keep pursuing these issues.

Mostly, I'm just trying to understand what is happening with CPU usage with Processing/java.exe/JVM, etc.

As I brought up in another thread, I experience that java.exe is not using as much CPU as it could/should.  java.exe stops at around 50% CPU usage (the rest of the CPU is idle) even though with my intensive opengl processing application, it really needs more. It caps at around 30fps.

I have a single processor AMD AthlonXP 3200+, so not hyperthreaded at all, running WinXP Pro.  I've reproduced this on a Win2k machine, and java also seems to not be fully maximizing the CPU on a friend's Linux box - also, an older single-processor, non-hyperthreaded AMD.  I have no idea if this is the fault of the JVM, the way Processing creates applets, both, or none of the above, unfortunately.

I spent many, many hours trying to figure out how to get my sketch to use all the available CPU.. which is when I discovered that running certain applications (like a webpage with a Flash plugin active) causes java.exe to suddenly use 90-100% of the CPU instead of the 50%.  This in turn more than doubles my frame rate in the Processing sketches.  I was baffled for a long time why -occasionally- my sketches would run so much better.  I started to watch the Task Manager at this time, noticed that sometimes java.exe used 50% of the CPU and other times 90%, and then finally discovered that certain -other- applications caused java.exe to max out and thus speed up my sketches.

Anyway, I'm very curious as to why this is happening, partly out of a desire to learn, and partly so that I can harnass, intentionally, this ability of maxing out the CPU!

Tim
Re: cpu usage above 50%
Reply #10 - May 13th, 2005, 10:56am
 
Just to clarify if we're bug hunting - my 50% CPU issues were on Windows 2000 on a Centrino laptop with a GeForce 4 4200 Go.  No HyperThreading here.

My experience with vsync is that it doesn't just lock the frame-rate to the current refresh rate, it locks it to the highest available factor of the refresh rate.  So if your monitor is at 60Hz, but your code is running at 59Hz, your actual framerate will be 30Hz. Likewise, if your code operates at 29Hz, you'll only get 20Hz displayed.  V-sync avoids tearing at all costs.  I don't know whether it's threading issues or unfortunate code-graphics mismatching that means it's locked at 50%... what's happening when it says "trying single threaded workaround"?
Re: cpu usage above 50%
Reply #11 - May 13th, 2005, 2:33pm
 
Turning HT off yielded slightly confusing results, but ultimately no real advantage in my case. At the start of the  rendering my application reported higher framerates, but then gradually over the course of 5 minutes it stabilized around the same framerate as when I had run it without HT. In the final result it showed only a 2-3% speed increase on a 2.5 hour long process with no other applications running in both cases.

I used the Task Manager to set the priority for my app to "realtime", which made my computer almost completely non-responsive, so there's no doubt that it was running at full speed. So it seems that the CPU does give almost all resources to the rendering app under HT, even if it says only 50% CPU load in Task Manager.

It might still be worth experimenting with, but I'm turning HT back on, since other functions such as switching between applications were smoother before.
Re: cpu usage above 50%
Reply #12 - May 13th, 2005, 10:57pm
 
I've been doing more (possibily unhelpful) experimentations.  I've noticed that my sketches (with any renderer: java2d, p3d, opengl) -will- use more than 50% of CPU if pushed very hard.

For example, if I do a draw() loop that draws 1000 ellipses in random locations:

for (int i=0; i<1000; i++) {
 ellipse(random(0,width), random(0,height), 55, 55);
 }

I get the following behaviour in each renderer:

JAVA2D [javaw.exe cpu:95%] [fps:14]
P3D    [javaw.exe cpu:95%] [fps:6]
OPENGL [java.exe  cpu:65%] [fps:20]

OpenGL is by far the smoothest.  Even though it's frame rate is low, it's high compared to the others.  But why is it only using 65% of the CPU?  Wouldn't it have been even smoother if it used more CPU?  I think that's the question people in this thread are wondering about.  If I increase the number of ellipses drawn each loop to 2000, I get:

OPENGL [java.exe  cpu:80%] [fps:12]

As that shows, the only way to get it to use more CPU was to make it do more work, which in turn dropped the frame rate, and made it LESS smooth in the end.

If I lower the number of ellipses drawn to 500 per loop, and test with OpenGL again, I get the following:

OPENGL [java.exe  cpu:49%] [fps:34]

Yep, it's faster drawing only 500 ellipses, the frame rate increased to 34fps, but now the CPU is only at 49%!  What about the 50% idle?  It's not being used at all..

..and here's the real kicker from my other thread.  With that last 500 ellipse/opengl example running, I open firefox/ie and go to a page that uses the Flash plugin.

OPENGL [java.exe  cpu:80%] [fps:48]

Even JAVA2D/P3D applications see a similiar jump.  While this is not as big a jump as I've seen, it's a jump nonetheless. What is Flash (and other applications) doing that affect how Processing applications perform?  Are they tripping some switch somewhere, in memory, on the videocard?   An additional factor that revealed itself is that this weird jump in CPU usage/performance only takes affect when the applet's window is focused.  If i click back on forth on the titlebars of the applet and task manager (which is set to always be on top) the java.exe CPU jumps to 80% when the applet is focused and drops back to 49% when the task manager is focused.

Unfortunately, it's a ridiculously complicated thing to try to explain, whereas it only takes a few seconds to demonstrate in practice.. Tongue

Tim
Re: cpu usage above 50%
Reply #13 - Jul 28th, 2005, 2:19pm
 
k, the hyperthreading stuff is now being tracked here:
http://dev.processing.org/bugs/show_bug.cgi?id=106

and the issue about vsync on opengl is here:
http://dev.processing.org/bugs/show_bug.cgi?id=107

please post any follow-up there.. i don't have a hyperthreading box so unfortunately i can't really track down what's going on. i assume this is a broader java-related problem so google might turn something up, but i didn't have any luck at time of this writing.
Page Index Toggle Pages: 1