reanahub / reana-client

REANA command-line client
http://reana-client.readthedocs.io/
MIT License
10 stars 46 forks source link

cli: more performance optimisations for `list` command #510

Closed tiborsimko closed 3 years ago

tiborsimko commented 3 years ago

The speed up of the list command was improved as part of https://github.com/reanahub/reana-client/issues/367. However, more improvements are needed.

E.g. for one client having about 101 workflows, the list may take 40-50 seconds, which is too much:

$ python -m cProfile -s cumulative /afs/cern.ch/user/r/reana/public/reana-qa/bin/reana-client list 
...
      128   44.979    0.351   44.979    0.351 {method 'read' of '_ssl._SSLSocket' objects}
        1    0.000    0.000   44.976   44.976 client.py:1302(getresponse)
        1    0.000    0.000   44.976   44.976 client.py:300(begin)
        1    0.000    0.000   44.973   44.973 client.py:267(_read_status)
       18    0.000    0.000   44.973    2.498 {method 'readline' of '_io.BufferedReader' objects}

We should debug what is being done on the server side, what is being sent to the client, and minimise passing of any unnecessary information down to the client so that reana-client list would be very fast.

Ideally one SQL query should be done on the server side, detecting and passing only that information that is being displayed:

$ reana-client list
NAME              RUN_NUMBER   CREATED               STARTED               ENDED                 STATUS
bsm09             2            2021-04-05T18:12:31   2021-04-05T18:12:32   2021-04-05T18:22:59   finished
bsm08             2            2021-04-05T18:12:29   2021-04-05T18:12:30   2021-04-05T18:22:56   finished
bsm07             2            2021-04-05T18:12:27   2021-04-05T18:12:28   2021-04-05T18:44:58   finished
bsm06             2            2021-04-05T18:12:25   2021-04-05T18:12:26   2021-04-05T18:22:11   finished
bsm05             2            2021-04-05T18:12:22   2021-04-05T18:12:23   2021-04-05T18:23:08   finished
...

i.e. only information about times and statuses, which should be very fast and should not take dozens of seconds.

P.S. The command list took 44 secs to get response, the command list -v took 56 seconds.

ParthS007 commented 3 years ago

After investigating more, I ran the profiler in my system:

  1. Without Verbose

    • 1368638 function calls (1296534 primitive calls) in 3.747 seconds
  2. With Verbose

    • 1369600 function calls (1297496 primitive calls) in 19.312 seconds
ParthS007 commented 3 years ago

After removing the progress from the response, there's a significant change in the response time.

  1. Without verbose
    • 1367216 function calls (1295112 primitive calls) in 1.329 seconds
  2. With Verbose
    • 1368123 function calls (1296019 primitive calls) in 1.515 seconds

The reana-client list and reana-client list -v output is same as expected.

tiborsimko commented 3 years ago

We shall need new CLI options to include/exclude progress, to include/exclude disk space... Currently we only have -v for "verbose" which masks them all.

This could be addressed together with the filtering issue so that users would be able to write:

$ reana-client list --filter name=bsm --include-progress --include-workspace-size

in the future.

... or, --filter name=bsm --format NAME,RUN_NUMBER,STARTED,PROGRESS,SIZE to use the filtering options to choose which columns to fetch from the server and to print. For example, if there is no PROGRESS asked for, then this won't be passed over to REST API endpoint, and the server-side work won't have to fetch big logs from the DB and calculate progress.

For the issue at hand, we can not be sending progress (unless asked), and we can add new parameters to the REST API endpoint that will fetch only what is necessary. So the work should be done for master.