bugGNU Octave - Bugs: bug #46845, usleep sleeps much too long on...

 
 

bug #46845: usleep sleeps much too long on macOS

Submitted by:  None
Submitted on:  Thu 07 Jan 2016 03:45:23 PM UTC  
 
Category:  Octave Function Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Inaccurate Result
Status:  Works For Me Assigned to:  None
Originator Name:  Daniel Betz Originator Email:  -email is unavailable-
Open/Closed:  Closed Release:  4.0.0
Operating System:  Mac OS

Add a New Comment (Rich Markup)
   

You are not logged in

Please log in, so followups can be emailed to you.

 

( Jump to the original submission)

Fri 17 Jun 2016 10:09:58 PM UTC, comment #15: 

Seems like no one has been able to reproduce this other than the reporter. Still affecting the OP? Will be closed as "works for me" if no further information can identify that there is a bug in Octave.

Mike Miller <mtmiller>
Project Administrator
Fri 15 Jan 2016 10:10:44 PM UTC, comment #14: 

Strange, I thought I did answer that already.... Terminal.app goes to sleep after some time (probably 30sec) but it wakes up immediately on mouse click. The Octave process never sleeps on my machine (10.11).

However, I still do not see how this is an octave bug?

Sebastian <sschoeps>
Fri 15 Jan 2016 06:17:00 PM UTC, comment #13: 

@Sebastian and Carlo: do you also see that AppNap gets active after Octave is running for 30 seconds? (See comment #12)

Andreas Weber <andy1978>
Project Member
Tue 12 Jan 2016 09:38:37 AM UTC, comment #12: 

step by step procedure

  • Open "Activity Monitor" ("Aktivit├Ątsanzeige" in german) in Applications/Utilities, select tab "CPU", add column "App Nap" to table. Search for octave
  • Run "octave -f --no-gui" in a terminal

You should now see "octave-gui.. App Nap = (Nein in german, I don't know if its "false", "disabled" or "no" in english) in Activity Monitor

  • Now wait 30 seconds until "App Nap" switches to "Ja/Yes"
  • Go back to terminal to the octave> prompt and execute

    tic; pause (0.1); toc

  • Run it multiple times

I wonder why the "App Nap" indicator never goes back to "Nein/No". Even If I do some calculations, for example

 for k=1:100 x=primes(1e8); endfor

AppNap gets activated after 30 seconds.

Anonymous
Sun 10 Jan 2016 07:33:04 AM UTC, comment #11: 

I can't reproduce the issue on OSX 10.9 either:

$ defaults read NSGlobalDomain NSAppSleepDisabled
The domain/default pair of (kCFPreferencesAnyApplication, NSAppSleepDisabled) does not exist
$ octave -q
$ octave -q
>> n = 1e3; t = zeros (n, 1); for ii=1:n, tic, pause (.1), t(ii)=toc; endfor
>> mean (t)
ans =  0.10106
>> std (t)
ans =    2.6900e-04
>> version
ans = 4.1.0+
>>

Carlo de Falco <cdf>
Project Member
Sat 09 Jan 2016 03:53:44 PM UTC, comment #10: 

My question was obviously not clear. According to my tests this timing problem is NOT present on 10.11 (darwin15.3.0) or 10.10 (darwin14.5.0). At least not with my default (!?) settings. So what do I have to do to see the problem on 10.11?

octave:2> tic; pause (0.01); toc
Elapsed time is 0.0101621 seconds.
octave:3> tic; pause (0.1); toc
Elapsed time is 0.104318 seconds.
octave:4> tic; pause (1); toc
Elapsed time is 1.00532 seconds.

Also the new "Octave.app" does not show this behavior (neither on 10.10 nor 10.11). All built using homebrew.

Sebastian <sschoeps>
Sat 09 Jan 2016 03:32:02 PM UTC, comment #9: 

@Sebastian: use

tic; pause (0.1); toc

Daniel sees here much more than 100ms (sometimes 3 up to 10 seconds).

Anonymous
Sat 09 Jan 2016 02:33:47 PM UTC, comment #8: 

The problem seems to be not present on Mac OS X 10.11 with octave 4.1+ (via homebrew). Can you give instructions how I can reproduce the problem on 10.11?

defaults read NSGlobalDomain NSAppSleepDisabled
The domain/default pair of (kCFPreferencesAnyApplication, NSAppSleepDisabled) does not exist

However, how do you start Octave on Mac OS X, e.g. via Terminal.app? I would expect that the "appnap property" is inherited in the precess tree, then you can set the
defaults write com.apple.Terminal NSAppSleepDisabled -bool true

Sebastian <sschoeps>
Sat 09 Jan 2016 02:30:21 PM UTC, comment #7: 

The problem seems to be not present on Mac OS X 10.11 with octave 4.1+ (via homebrew). Can you give instructions how I can reproduce the problem on 10.11?

Sebastian <sschoeps>
Fri 08 Jan 2016 04:41:56 PM UTC, comment #6: 

@Andreas: reverted to "None". "Works for me" was meant as: "There exists a Workaround" by the same user who created this bug report, thus might be of minor interest. And another user looking for this report might consider this more interesting as with "None".

Kai Torben Ohlhus <siko1056>
Project Member
Fri 08 Jan 2016 03:52:05 PM UTC, comment #5: 

One can disable AppNap application-specific via e.g.

defaults write com.microsoft.Excel NSAppSleepDisabled -bool true

(see here: https://jamfnation.jamfsoftware.com/discussion.html?id=10566#responseChild59756)

The command "defaults" has read/write access to application-specific files called .plist ("property list"), which represent app-specific key-value data. One of these keys is called "NSAppSleepDisabled" which can be set to true for disabling App Nap.
Octave does not have such functionality (there appears nothing when searching via "defaults domains | grep octave" on a mac) which leads to my workaround: disabling AppNap globally.

Anonymous
Fri 08 Jan 2016 02:57:40 PM UTC, comment #4: 

What does

Because octave has no .plist to set the boolean "NSAppSleepDisabled" to true

mean?

John W. Eaton <jwe>
Project Administrator
Fri 08 Jan 2016 12:00:21 PM UTC, comment #3: 

@Kai: You are tagging this as "Works for Me", have you really tried this on Mac OSX? As Daniel already discovered this is a issue with App Nan which was intrioducted with OSX 10.9.

If enabled, "pause (0.1)" could for example run 10 seconds (seen here). This has a major impact on user experience since pause/sleep is used at some places in core.

So at least we should add Note for Mac OSX >= 10.9 users if we can't find a way to disable it.

Andreas Weber <andy1978>
Project Member
Fri 08 Jan 2016 11:32:23 AM UTC, comment #2: 

The accuracy of usleep is very system depended, and on most systems you cannot sleep reliably for less 1e-3 seconds. Recently, sleep and usleep were deprecated in the development release in favor of the MATLAB compatible pause-function, which internally does nothing despite calling the POSIX compliant nanosleep:

http://hg.savannah.gnu.org/hgweb/octave/rev/58263bea2fdf

Thus replace usleep(100) by pause(1e-4).

If there is nothing more about this issue, I can close it.

Kai Torben Ohlhus <siko1056>
Project Member
Fri 08 Jan 2016 08:01:55 AM UTC, comment #1: 

As I heard from a colleague, disabling AppNap should help. Because octave has no .plist to set the boolean "NSAppSleepDisabled" to true, I disabled it globally via

defaults write NSGlobalDomain NSAppSleepDisabled -bool YES

Executing the same commands results in the following times (which are way more accurate!):

>> tic; usleep (10), toc
Elapsed time is 6.38962e-05 seconds.
>> tic; usleep (10), toc
Elapsed time is 5.60284e-05 seconds.
>> tic; usleep (100), toc
Elapsed time is 0.000151873 seconds.
>> tic; usleep (100), toc
Elapsed time is 0.00014782 seconds.
>> tic; usleep (100), toc
Elapsed time is 0.000244856 seconds.

Anonymous
Thu 07 Jan 2016 03:45:23 PM UTC, original submission:  

Installed using brew from https://github.com/Homebrew/homebrew-science/blob/master/octave.rb

>> tic; usleep (10), toc
Elapsed time is 0.316622 seconds.
>> tic; usleep (10), toc
Elapsed time is 0.315173 seconds.
>> tic; usleep (100), toc
Elapsed time is 3.26147 seconds.
>> tic; usleep (100), toc
Elapsed time is 0.127848 seconds.
>> tic; usleep (100), toc
Elapsed time is 3.2693 seconds.

as you can see the time sleeped is much longer than requested.

Anonymous

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:
   
   
Comment:
   

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by mtmiller (Posted a comment)
  • -email is unavailable- added by cdf (Posted a comment)
  • -email is unavailable- added by sschoeps (Posted a comment)
  • -email is unavailable- added by jwe (Posted a comment)
  • -email is unavailable- added by andy1978 (Posted a comment)
  • -email is unavailable- added by siko1056 (Posted a comment)
  • -email is unavailable- added by None (Submitted the item)
  •  

    Do you think this task is very important?
    If so, you can add your encouragement to it.
    This task has 0 encouragements so far.

    Only project members can vote.

     

     

     

    Follow 7 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2016-11-23 mtmiller Open/ClosedOpen => Closed
    2016-06-17 mtmiller StatusNone => Works For Me
        Summaryusleep sleeps much too long on Mac OSX => usleep sleeps much too long on macOS
    2016-01-08 siko1056 StatusWorks For Me => None
        Assigned tosiko1056 => None
    2016-01-08 siko1056 StatusNone => Works For Me
        Assigned toNone => siko1056

    Back to the top


    Powered by Savane 3.5