Ticket #5824 enhancement new

Opened 10 months ago

Last modified 4 weeks ago

Add automatic detection of the number of CPU core to trial -j

Reported by: therve Owned by:
Priority: normal Milestone:
Component: trial Keywords: easy review
Cc: jml, rachee.singh@… Branch:
Author: Launchpad Bug:

Description

It'd be nice if trial -j auto twisted detected the number of available cores and used that as the number of local workers.

Attachments

ticket5824.patch Download (1.6 KB) - added by racheesingh 5 weeks ago.
Patch file for the proposed fix for Ticket #5824
ticket5824-round2.patch Download (2.6 KB) - added by racheesingh 5 weeks ago.
Proposed fix along with test case.
ticket5824-round3.patch Download (3.5 KB) - added by racheesingh 5 weeks ago.
Proposed fix along with test case, incorporating review comments.

Change History

1

Changed 10 months ago by DefaultCC Plugin

  • cc jml added

2

Changed 6 weeks ago by itamar

  • keywords easy added

The Python standard library multiprocessing module has a function that exposes the number of available CPUs.

3

Changed 5 weeks ago by racheesingh

  • owner set to racheesingh
  • status changed from new to assigned

4

Changed 5 weeks ago by racheesingh

I looked at the Python docs for multiprocessing. multiprocessing.cpu_count() seems like something we could use to get the number of CPUs. But the  docs also mention this:

Return the number of CPUs in the system. May raise NotImplementedError.

Apparently, on Windows machines cpu_count may result in a NotImplementedError. So should we use this at all?

5

Changed 5 weeks ago by racheesingh

Does this seem like a reasonable thing to do? [I tried out multiprocessing.cpu_count and modified the opt_jobs method like so.]

    def opt_jobs(self, number):
        """
        Number of local workers to run, a strictly positive integer.
        """
        # Case insensitive check if jobs was "auto"
        if number.lower() == "auto":
            try:
                number = multiprocessing.cpu_count()
            except NotImplementedError:
                # Windows might raise NotImplementedError while accessing cpu_count
                raise usage.UsageError(
                    "-j AUTO option not supported for your system.")
        else:
            try:
                number = int(number)
            except ValueError:
                raise usage.UsageError(
                    "Expecting integer argument to jobs, got '%s'" % number)
            if number <= 0:
                raise usage.UsageError(
                    "Argument to jobs must be a strictly positive integer")
        self["jobs"] = number

6

Changed 5 weeks ago by racheesingh

  • cc rachee.singh@… added

Changed 5 weeks ago by racheesingh

Patch file for the proposed fix for Ticket #5824

7

Changed 5 weeks ago by racheesingh

  • owner racheesingh deleted
  • status changed from assigned to new
  • keywords review added

8

Changed 5 weeks ago by Julian

  • keywords review removed
  • owner set to racheesingh

Hey!

Thanks for working on this. The solution you submitted looks like it's headed in the right direction, but all patches submitted to Twisted have to have accompanying tests. Take a gander at http://twistedmatrix.com/trac/wiki/TwistedDevelopment if you haven't already. You'll need to test the new behavior that this ticket is proposing.

Thanks again for looking at this!

9

Changed 5 weeks ago by racheesingh

Thanks for the pointers! I followed the links about how to add tests and I added a test in what seemed like the place where tests for trial located. After adding the test case I ran

 trial --testmodule twisted/scripts/trial.py

to check if my test case was running at all. But I found that it was not being run. Is there something I am missing here? I am attaching the patch file which has the test case I was trying to add.

Changed 5 weeks ago by racheesingh

Proposed fix along with test case.

10

Changed 5 weeks ago by thijs

Thanks for your patch.

  1. you should run trial twisted.trial.test.test_script since you placed your test there
  2. the docstring should also mention it can raise a NotImplementedError
  3. or perhaps it should simply return 1 for platforms like win32 and print a warning instead?

11

Changed 5 weeks ago by itamar

Thanks for that patch!

I'm not sure what thijs is referring to in items 2 and 3. Here are my review comments:

  1. "trial --help" should indicate auto is a possible option for --jobs, otherwise no one will know about the cool new feature you added!
  2. You should provide a test for the error case where NotImplementedError is raised.
  3. "-j AUTO option not supported for your system." would better read as "'-j auto option not supported for your system."`
  4. You should provide a news file ( https://twistedmatrix.com/trac/wiki/ReviewProcess#Newsfiles) - "svn add" it and then "svn diff" will include it.

Please resubmit after addressing these issues.

12

Changed 5 weeks ago by racheesingh

Thanks for the review comments. I have incorporated the comments from thijs and itamar and am attaching the diff. Please do tell me if I have missed something out (or misunderstood your feedback).

Changed 5 weeks ago by racheesingh

Proposed fix along with test case, incorporating review comments.

13

Changed 4 weeks ago by racheesingh

  • owner racheesingh deleted
  • keywords review added
Note: See TracTickets for help on using tickets.