Skip to content

Remove useless (or undocumented) sleep() calls that were slowing down Python scipy build#599

Merged
boegel merged 5 commits intoeasybuilders:developfrom
gribozavr:remove-useless-sleep
Apr 19, 2013
Merged

Remove useless (or undocumented) sleep() calls that were slowing down Python scipy build#599
boegel merged 5 commits intoeasybuilders:developfrom
gribozavr:remove-useless-sleep

Conversation

@gribozavr
Copy link
Copy Markdown
Contributor

This removes useless (or undocumented) sleep() calls. Calling read() on a pipe will block until data is available, so there is no reason to sleep().

There is one more sleep() that I marked with a comment in run_cmd_qa. But because the function tries to emulate human input, the sleep() might be needed there if the program we interact with expects a delay (quite unlikely).

@stdweird
Copy link
Copy Markdown
Contributor

@gribozavr on a general note, the idea is to replace the run_cmd and run_cmd_qa with RunAsyncLoopLog.run (or subclass thereof for qa) from vsc-base. the slowness that you encounter is fixed in https://github.com/hpcugent/vsc-base/blob/master/lib/vsc/utils/run.py#L444. the qa code in vsc-base/run is not finished however.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this cannot be causing the issue (for very short commands, this is a speedup)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please explain why this is a speedup?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

well, not a speedup if you remove the inner sleep or make it conditional. (but the sleep will not cause real delay).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, so it does not hurt, but it is not helping either. Thus it should be removed.

@boegel
Copy link
Copy Markdown
Member

boegel commented Apr 19, 2013

I discussed this a bit with Stijn, and it seems the sleeps are indeed a bit of overkill.

However, running unit tests on this branch revelas an issue. A simple test like the ones below fails with the sleeps removed...

(out, ec) = run_cmd_qa("echo question", {"question":"answer"})
self.assertEqual(out, "question\n")

So, simply removing the sleeps seems to break run_cmd_qa?

@stdweird
Copy link
Copy Markdown
Contributor

can you run this with debug and check what goes wrong? and try with recv_some(...,t=1)

@boegel
Copy link
Copy Markdown
Member

boegel commented Apr 19, 2013

Rerunning the test with the initial sleep that was removed in run_cmd_qa added again and removing the sleep in the loop fixes the problem, i.e. the following patch on top of this PR:

diff --git a/easybuild/tools/filetools.py b/easybuild/tools/filetools.py
index 910e10e..0663034 100644
--- a/easybuild/tools/filetools.py
+++ b/easybuild/tools/filetools.py
@@ -495,6 +495,7 @@ def run_cmd_qa(cmd, qa, no_qa=None, log_ok=True, log_all=False, simple=False, re
     except OSError, err:
         _log.error("run_cmd_qa init cmd %s failed:%s" % (cmd, err))

+    time.sleep(0.1)
     ec = p.poll()
     stdoutErr = ''
     oldLenOut = -1
@@ -561,7 +562,7 @@ def run_cmd_qa(cmd, qa, no_qa=None, log_ok=True, log_all=False, simple=False, re
                                                                                     ))

         # This sleep should not be needed.
-        time.sleep(1)
+        #time.sleep(1)
         ec = p.poll()

     # Process stopped. Read all remaining data

@boegel
Copy link
Copy Markdown
Member

boegel commented Apr 19, 2013

The run_cmd_qa testcase was rubbish, since it never wait for input as an actual interactive command would, so I corrected the test to:

(out, ec) = ft.run_cmd_qa("echo question; read x; echo $x", {"question": "answer"})
self.assertEqual(out, "question\nanswer\n")

The patch mentioned above breaks this test, the sleep in the loop is quite critical to run_cmd_qa to be able to ignore non-questions (see also https://github.com/hpcugent/easybuild-framework/pull/599/files#r3874464).

@boegel
Copy link
Copy Markdown
Member

boegel commented Apr 19, 2013

PR gribozavr#5 enhances the unit tests to make sure the proposed changes are OK.

Whether they'll cause any issues should become clear when a full regtest is run.

add/enhance unit tests, adjust comment
@gribozavr
Copy link
Copy Markdown
Contributor Author

@boegel I think I now understand why that sleep was needed.

@boegel
Copy link
Copy Markdown
Member

boegel commented Apr 19, 2013

OK, this seems ready to merge in.

boegel added a commit that referenced this pull request Apr 19, 2013
Remove useless (or undocumented) sleep() calls that were slowing down Python scipy build
@boegel boegel merged commit abb076e into easybuilders:develop Apr 19, 2013
@gribozavr gribozavr deleted the remove-useless-sleep branch April 19, 2013 19:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants