#15 ✓resolved
Pedro Almeida

Processor usage over 100%

Reported by Pedro Almeida | July 23rd, 2009 @ 08:52 PM

There is a performance issue with the application. When running it, I found that it consumes more that 100%.
The reason of being consuming OVER than 100%, is because of the threads, they are sent to both processors (or cores), and they use 100% of one processor (or core) and the remaining threads are using some of the other processor.

It is possible to corrected this behavior by inserting a "pause" to the program. It works if we add the call to sleep function in the main "quasi-runLoop" around line 646 of CWMain.m for the program to "sleep" for 1 second.

 while(bytes = read(fd,buf_stream,255)){

    sleep(1);</code>



This way the program refresh rate will be at least 1 second, which is sufficient, and reduces from about 120% of CPU usage to about 0.01% in average.

I'm not sure if this will influence any other code in the program that might be measuring anything else.
It's up to you to decide how to overcome this issue, but is a very important thing to solve.

Comments and changes to this ticket

  • Patrick Quinn-Graham

    Patrick Quinn-Graham July 24th, 2009 @ 02:50 AM

    • State changed from “new” to “open”

    Unless something is going very wrong with the output from your modem this shouldn't be the cause of the CPU spike you are seeing (that I am not) - this is because the read() call blocks until either a \n or 255 characters are supplied from the modem (the modem usually produces a usage report every two seconds, for example).

    It's worth further investigation as to what the additional output is from the modem that is causing the high CPU load, as putting a sleep() in here will likely cause it to get very behind on usage updates/signal strength/connection mode/network updates. ie. if that loop is ending up running 120 times a second on your computer, just one execution with your sleep() in place will then cause that seconds worth of data to drip in over two minutes - and the backlog will only increase. A sleep would have to also include something to drain the (now ignored) incoming notifications from the modem, while also ensuring anything important in those ignored ones weren't actually ignored!

    It'd be worth capturing the output on the Pcui /dev object (can't recall the exact path - it's in the source code) to see what's actually happening.

  • Nick Hibma

    Nick Hibma January 12th, 2010 @ 09:08 PM

    This is actually a programming error. You opened the file O_NDELAY, which means read() will return -1 and errno == EAGAIN if no data is available. If you want to wait for data to become available you need to remove the O_NDELAY from the call to open().

    However: Another solution is to sleep and continue the while if -1 is returned. You do not check for this return value. Why not?

    Note: ignoring the -1 for bytes is a bug which makes you scribble into the buffer before its start!

    diff --git a/Classes/CWMain.m b/Classes/CWMain.m
    index d365378..a9552bb 100644
    --- a/Classes/CWMain.m +++ b/Classes/CWMain.m @@ -643,6 +643,10 @@ void calloutProc (SCNetworkConnectionRef connection, SCNetworkConnectionStatus s

        [mainController sendATCommandsTimer:@"AT^HWVER\r"];
    
        while(bytes = read(fd,buf_stream,255)){
    
    •         if (bytes == -1) {
      
    •                 usleep(100000);
      
    •                 continue;
      
    •         }
              buf_lineStart=strchr(buf_stream,'^');
              if(buf_lineStart == 0) {
                      buf_lineStart=strchr(buf_stream,'+');
      
  • Nick Hibma

    Nick Hibma January 13th, 2010 @ 12:27 AM

    The commit log by Frank makes me think that someone committed something to make things work for him, without proper checking. What was the problem that Frank resolved with the commit below?

    commit e6236dcbeb84ea8fcb6b59ce7166b21a115b6e5f
    Author: Frank <frank@BigMac.local>
    Date:   Fri Mar 6 04:55:45 2009 +0800
    
        Discovered by accident that I must open with the O_NDELAY option, otherwise it did not work for me.
        
        Signed-off-by: Patrick Quinn-Graham <make-contact@pftqg.com>
    
  • Nick Hibma

    Nick Hibma January 21st, 2010 @ 08:19 PM

    What's the ETA for this? I hate having local modifications in other people's sources.

  • Nick Hibma
  • Patrick Quinn-Graham

    Patrick Quinn-Graham February 2nd, 2010 @ 12:34 PM

    Hi Guys,

    Apologies for the wait on this - I've just moved countries and don't yet
    have reliable internets at home.

    Version 1.4 is currently nearing completion - currently has a couple of
    blocking bugs (like not working at all on Leopard) but hopefully I can get a
    beta for interested parties to test asap.

    cheers,
    Patrick

  • Nick Hibma

    Nick Hibma February 18th, 2010 @ 07:12 PM

    [donkey's voice] Me!
    Me!
    Pick me!

  • Patrick Quinn-Graham

    Patrick Quinn-Graham February 18th, 2010 @ 07:38 PM

    You can download a preview beta of v1.4 (b2) (note it has bugs beyond the Leopard compatibility issue) from http://static.patrick.geek.nz/cheetahwatch/CheetahWatch_1.4b2.zip.

  • Nick Hibma

    Nick Hibma March 23rd, 2011 @ 08:36 PM

    • Milestone order changed from “0” to “0”

    100% CPU usage seems to be no longer the case, with modem plugged or unplugged.

  • Patrick Quinn-Graham

    Patrick Quinn-Graham March 24th, 2011 @ 01:50 PM

    • State changed from “open” to “resolved”

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.

New-ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile ยป

This little mac app provides you with signal strength, network mode (GRPS/WCDMA/HSDPA), network name control over your connection, and statistics about your current connection (current throughput, total data transferred, connection time). It does this through a little icon in your menu bar (and a bigger window, if you want to see it), and also helps you keep track of your usage - no need for a nasty surprise from your provider.

People watching this ticket

Tags

Referenced by

Pages