rjdverse / rjdemetra

R interface to JDemetra+ v 2.x
https://rjdverse.github.io/rjdemetra
52 stars 16 forks source link

Does RJDemetra uses Multithreading? #89

Closed AQLT closed 3 years ago

AQLT commented 3 years ago

Every time I submit a new version of RJDemetra (or another package that uses it), I have questions about if the package uses more that 2 cores. The questioning comes from the fact that some notes are produces when checking the package that cannot be explained if there is no multithreading. For example:

Examples with CPU time > 2.5 times elapsed time
    user system elapsed ratio
jSA 4.53  0.167   1.313 3.577

Or

Examples with CPU time > 2.5 times elapsed time
                               user system elapsed ratio
 get_object                   1.956  0.036   0.551 3.615
 get_ts                       1.488  0.024   0.529 2.858
 get_name                     4.500  0.108   1.644 2.803
 regarima                     4.960  0.040   1.874 2.668

For CRAN policies, we shouldn't use more than 2 cores by default. I thought RJDemetra didn't use multi-threading but maybe I'm wrong (for example, it seems to be used in tstoolkit). Using the following option seems to limit the result of Runtime.getRuntime().availableProcessors() to maximum 2 (and so to the solve the CRAN issue):

.jpackage(pkgname, lib.loc = libname,
          parameters = c(getOption("java.parameters"), "-XX:ActiveProcessorCount=2"))

We could add an option to set this parameter when loading the package. What do you think @palatej ?

palatej commented 3 years ago

JDemetra itself uses explicitly several processors only in multi-processing objects. However, Java uses other threads for its own needs, for instance in the garbage collector or in streams. No problem to limit the number of processors as you propose.