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.
IndexProgramming Questions & HelpPrograms › High CPU load even for simple scenes
Page Index Toggle Pages: 1
High CPU load even for simple scenes (Read 2471 times)
High CPU load even for simple scenes
Sep 9th, 2007, 12:00am
 
(I hope this is the right forum to post my question. As I'm not sure whether this is a processing bug I post here instead of adding a bug to the database)

As soon as I run a processing program which contains an animation or which reacts on user input my X server's CPU usage goes up to around 97% to 100%. This happens even for simple scenes (e.g. [1], [2]) and it happens both if I run a program in the browser ([1] and [2]) or my own programs via the IDE ([3]). I understand that the frameRate() and delay() commands can be used to reduce CPU usage, and by using them I can reduce CPU usage to 40% in [3] (Without them this uses 100% CPU, too). It is maybe also worth mentioning that the Java VM process uses around 2-3% CPU in the same time. But I do believe that this is still way too much for such a simple scene. Any hints on why this is the case are greatly appreciated.

My system specs:
- Processing 0125 Beta
- Gentoo Linux, 2.6.20 kernel
- Xorg 7.2 X server
- openbox 3.4.2 window manager
- Sun JDK 1.5.0.12
- Intel Core 2 Duo Prozessor T7200, 2x 2 GHz
- 1 GB RAM

Example programs that cause high CPU usage:
[1] http://processing.org/learning/topics/continuouslines.html
[2] http://processing.org/learning/topics/wolfram.html

[3] The following program:

void setup() {
 frameRate(25);
}

int x = 0;

void draw() {
 background(255);
 line(x, 0, x, height);
 x = (x - 1 == width ? 0 : x + 1);
 delay(20);
}

Re: High CPU load even for simple scenes
Reply #1 - Sep 9th, 2007, 3:07pm
 
processing will use as much cpu is available, except unless otherwise specified with frameRate(). it's redrawing the scene on each frame because it's built for interactive animation. if you don't want to update the screen on each frame, use noLoop().
Re: High CPU load even for simple scenes
Reply #2 - Sep 9th, 2007, 4:56pm
 
I do know about noLoop() and about frameRate(), but still I do not understand how such simple examples as the ones I mentioned in my original posts could use the whole power of a 2 Ghz CPU -- it may be that that power is available, but IMHO it is not needed. What I also don't understand is that it's not the Java process that causes the high CPU load -- as I said before that process only uses around 3% CPU, something I'd expect for the mentioned sketches. Instead it's the X server who runs under full load while sketches are running. The result is that all parts of the GUI (window manager, other running applications) get slowed down. I am pretty sure that this is not the intended behaviour. Note that I also didn't say it's a bug in processing. It could be anyone of the tools I'm using that causes this symptons in combination with processing. I just thought I'd ask here because here it is most likely that people may have encountered similar problems.
Re: High CPU load even for simple scenes
Reply #3 - Sep 10th, 2007, 8:08pm
 
Small update: After removing $processing_dir/java/bin/java and creating a link to my system version of Java, I have tested my problem with the following versions of Java:

- Blackdown JDK 1.4.2.03
- Sun JDK 1.5.0.12
- Sun JRE 1.6.0.02

With all three I get the same high CPU load behaviour. (BTW, is there a reason for not using the system's Java by default?)

EDIT: This is for custom sketches run through the IDE.
Re: High CPU load even for simple scenes
Reply #4 - Sep 11th, 2007, 7:12am
 
I just did a test on my Powerbook running OSX, and I have to say, I'm not seeing anything like the mentioned behavior, so this may be a Linux or Gentoo specific bug.  I ran the code listed under [3] and watched my CPU usage, and it barely moved at all - the Java process used maybe a few (less than 10) percent CPU, and overall CPU usage was always well below 50% even with a lot of other programs open.  In other words, all is as expected.

Can anyone running Linux verify this problem?  My Ubuntu box is gutted right now, so I can't help until I get it put back together.  That said, I don't ever remember having these problems.  I'm wondering, do you see the same behavior with all Java applets/applications, or is it just Processing ones?  It sounds like something's going awry with event handling, maybe, which would indicate that it's Sun's bug (or maybe your X server's), in which case there's little we can do, but if it's only Processing applets, maybe it has to do with the Linux threading issues that have been popping up here and there...
Re: High CPU load even for simple scenes
Reply #5 - Sep 11th, 2007, 2:11pm
 
Just to rule some possibilities out, here some more information after some tests:

- The X server logs contain no errors. Everything besides the processing issue works fine.

- I get no high CPU load on the X server if the skretch uses OpenGL ([1] for example, uses less that 2% CPU for the whole system)

- I do not get high CPU loads with other (not processing-based) Java applets that do animations: None of [2], [3] and [4] uses more than 10% CPU.

- The >90% CPU usage on the X server is still present for non-OpenGL animated sketches like [5] (Just to make sure I'm not hallucinating Smiley)

- I have not found anything about problems with high CPU load on the X server while using Java programs on the net or the Gentoo forums. The Gentoo forums are currently read-only for maintenance reasons, so I couldn't ask for help there.

For these reasons, this looks like a "processing + linux" issue, may it could of course "only" be a "processing + gentoo" or "processing + my x server version" or something like this. I'd really appreciate it if other people who run processing on linux could report if they encountered similar problems.

I also tried to download older versions of processing to check if they cause the same problem, but they have been removed from the server -- Is there a place one can still download them?

[1] http://processing.org/learning/3d/cubeswithincube.html
[2] http://www.colorstereo.com/applets/undrpool.apl/poolwave.html
[3] http://www.atmo.arizona.edu/products/wximagery/usradar.html
[4] http://johnbokma.com/Wave2/
[5] http://processing.org/learning/topics/spore1.html
Re: High CPU load even for simple scenes
Reply #6 - Sep 11th, 2007, 9:24pm
 
Hm, the part that interests me is that you're not seeing high CPU use with OpenGL.  That the spore example pins the CPU is not too surprising, since cellular automata tend to be pretty CPU intensive.  But if OpenGL mode clears up some of the issues that rules out a lot of the Processing core as being at fault, indicating that it's probably a graphics thing exclusively.

Have you tried running sketches using P3D as the renderer instead of the default (JAVA2D)?  That might help pin this down a bit more.
Re: High CPU load even for simple scenes
Reply #7 - Sep 12th, 2007, 1:12am
 
Thanks for the hint ewjordan, I didn't know about P3D before (I'm totally new to the whole processing thing). I'm not sure if I got this right, but P3D is just 3D without relaying on OpenGL for the rendering? So, [1] would be using P3D, right? I just checked, and CPU usage is around 2% for [1], so everything fine here.

About cellular automata using lot of CPU cycles: You're right, that was probably not a good example (Although I still doubt it should be around 100%). But you can pick any 2D scene that contains animation or user input from [2], I get the high CPU load for all of them.

Seems we're getting closer to the core of the problem! Thanks for any input so far and keep the ideas flowing Smiley

[1] http://processing.org/learning/3d/rotate1.html
[2] http://processing.org/learning/basics/index.html


Update:
I just went through the 3D examples and found that I also get high CPU cycles for [3], which uses user input. But for [4], which also uses user input, I get normal CPU usage. But it get's even more confusing: If I copy the code from [3] and run it through the IDE I get normal CPU load (Same for [4]). But [5] (2D + user input) causes high CPU load both as an applet and when run through the IDE.

[3] http://processing.org/learning/3d/moveeye.html
[4] http://processing.org/learning/3d/perspective.html
[5] http://processing.org/learning/basics/mouse1d.html
Re: High CPU load even for simple scenes
Reply #8 - Aug 19th, 2009, 2:21am
 
Hi,
I'm new to the forum. I don't use processing much, only as a mouse/serial port hub.

TorfusPolymorphus wrote on Sep 9th, 2007, 12:00am:
(
As soon as I run a processing program which contains an animation or which reacts on user input my X server's CPU usage goes up to around 97% to 100%. This happens even for simple scenes

I got the same exact problem, and I solved it this morning :).

For some time, I used processing on an Ubuntu 9.04, but since the USB stack sucks for my serial adapters, I reverted to Debian 5.0 (Lenny), which feels way more stable.
However, on Ubuntu, I did not have any graphical trouble with processing. On Debian, running my very basic program hogs the Xorg process to 99%. So I knew this was most likely a configuration issue with X.

First, adding the "P3D" option in size() solves the problem. (eg size(512, 200, P3D)).

Second, adding the following options in my Xorg solves the problem even without the P3D option (and speeds up all other application such as eagle CAD, which is cool) :
Code:

Section "Device"
       Identifier "Card0"
       Driver    "radeon"
       Option    "AccelMethod"  "EXA"    # here
       Option    "RenderAccel"  "true"   # and here
       Option    "backingstore" "true"
EndSection

The "AccelMethod" line is the key. It seems it's not the default on all Linux distributions at the time. YMMV with other chipsets. I did not see improvements with the backingsore stuff.
I can now use p5 at 60 fps and still have a snappy computer ;)

Regards,
Charles
Page Index Toggle Pages: 1