Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix!: lipome compute task optim #613

Merged
merged 9 commits into from
Mar 24, 2023
Merged

Conversation

SdgJlbl
Copy link
Contributor

@SdgJlbl SdgJlbl commented Mar 9, 2023

Companion PR

Breaking changes

  • The endpoint /compute_plans/<pkey>/tasks now returns the ComputeTask without their associated inputs and outputs.
  • The endpoint /tasks now returns the ComputeTask without their associated inputs and outputs.
  • The endpoint /tasks/<pkey> still returns the full view of the ComputeTask (including inputs and outputs).

Description

Fixes slow page display (list view of compute tasks linked to a compute plan).

Two issues have been fixed:

  • add some missing prefetch_related statements
  • duplicate the ComputeTaskSerializer to have one for the list view and one for the detail view.

The serializer for the list view does not contain any information about inputs and outputs, since these information are not used currently and make a lot of queries to get nested objects.
The serializer for the detail view is the same as it was before (optimised queries though).

How has this been tested?

This has been tested manually for the frontend part, comparing the version actually in production with a local cluster built on my branch. Pages that were checked:

  • /compute_plans
  • /compute_plans//task
  • /compute_plans//task/
  • /tasks
  • /task/

For the backend, I have added non-regression tests that check that the number of queries is in O(1). The so-called n+1 queries issue is caused by some missing prefetch_related statement that causes the number of queries to be linear in the number of items. In our case, because of nested items, we actually have a complexity that is higher than linear without the prefetch_related.

Impact

URL nb items main this branch
/compute_plans//tasks 10 / 60 tasks 118/672 14
/tasks 10/60 tasks 38 / 142 14
/task/ 4 / 10 inputs 122 / 182 18

TODO

  • Evaluate impact to delegate the querying of inputs / outputs to the SDK
  • Update changelog

Checklist

  • changelog was updated with notable changes
  • documentation was updated

@github-actions github-actions bot added the api label Mar 9, 2023
@SdgJlbl SdgJlbl force-pushed the fix/lipome-compute-task-optim branch from feb878f to 84e0b0b Compare March 10, 2023 19:19
@github-actions github-actions bot added compute-engine documentation Improvements or additions to documentation labels Mar 10, 2023
@SdgJlbl SdgJlbl changed the base branch from fix/lipome-optimization to main March 10, 2023 19:20
@SdgJlbl SdgJlbl changed the title Fix/lipome compute task optim fix: lipome compute task optim Mar 10, 2023
@github-actions github-actions bot removed documentation Improvements or additions to documentation compute-engine labels Mar 10, 2023
@SdgJlbl SdgJlbl force-pushed the fix/lipome-compute-task-optim branch from 2be79ad to de5250f Compare March 14, 2023 10:02
@SdgJlbl SdgJlbl marked this pull request as ready for review March 14, 2023 10:03
@SdgJlbl SdgJlbl requested a review from a team as a code owner March 14, 2023 10:03
@SdgJlbl
Copy link
Contributor Author

SdgJlbl commented Mar 14, 2023

/e2e --tests sdk,frontend,substrafl --benchmarks mnist,camelyon

@Owlfred
Copy link

Owlfred commented Mar 14, 2023

End to end tests: ❌ FAILURE

Jobs status:

  • Tests Benchmark:
  • Tests Distributed:
  • Tests Standalone:

“Rien ne sert de courir ; il faut partir à point.” ― Jean de La Fontaine (Le Lièvre et la Tortue)

Comment on lines 273 to 277
print("response\n", response.json()[0])
print("expected\n", expected_response[0])
print("----\n")
print(response.json()[0]["key"])
print("----\n")
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it meant to stay in the test suite?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

oops 😬

@SdgJlbl
Copy link
Contributor Author

SdgJlbl commented Mar 14, 2023

/e2e --tests sdk,frontend,substrafl --benchmarks mnist,camelyon

@Owlfred
Copy link

Owlfred commented Mar 14, 2023

End to end tests: ❌ FAILURE

Jobs status:

  • Tests Benchmark:
  • Tests Distributed:
  • Tests Standalone:

I'm sorry.

@SdgJlbl SdgJlbl force-pushed the fix/lipome-compute-task-optim branch from 077a79f to 13ef406 Compare March 14, 2023 17:21
@SdgJlbl
Copy link
Contributor Author

SdgJlbl commented Mar 14, 2023

/e2e --tests sdk,frontend,substrafl --benchmarks mnist,camelyon

@Owlfred
Copy link

Owlfred commented Mar 14, 2023

End to end tests: ❌ FAILURE

Jobs status:

  • Tests Benchmark:
  • Tests Distributed:
  • Tests Standalone:

That's a shame.

@SdgJlbl
Copy link
Contributor Author

SdgJlbl commented Mar 21, 2023

/e2e --benchmarks mnist,camelyon --refs substra=fix/compute-task-performance-issue

@Owlfred
Copy link

Owlfred commented Mar 21, 2023

End to end tests: ❌ FAILURE

Jobs status:

  • Tests Benchmark:
  • Tests Distributed:
  • Tests Standalone:

Oh well.

@SdgJlbl
Copy link
Contributor Author

SdgJlbl commented Mar 21, 2023

/e2e --tests sdk,frontend,substrafl --benchmarks mnist,camelyon --refs substra=fix/compute-task-performance-issue, substra-tests=fix/compute-task-performance-issue

@Owlfred
Copy link

Owlfred commented Mar 21, 2023

Error: Invalid ref

Usage: /e2e [options] [help]

/e2e may appear anywhere as long as it is on its own line

Options:
  --refs <value>                                         Extra refs (branch or tag) with format REPO=GIT_REF,REPO=GIT_REF.
  Supported repositories: hlf-k8s, orchestrator, substra-backend, substra-frontend, substra-tools, substrafl, substra, substra-tests, substra-ci.
  Example: /e2e --refs substra-backend=some_branch,orchestrator=some_tag (default: {})
  --tests-to-run, --tests <tests-to-run>                 Comma-separated list of tests to run. Valid options: sdk,substrafl,frontend or NONE. (default: "sdk")
  --benchmarks-to-run, --benchmarks <benchmarks-to-run>  Comma-separated list of workflows tests to run. Valid options: mnist, camelyon or NONE. (default: "NONE")
  --orchestrator-mode, --mode <orchestrator-mode>        Comma-separated list of orchestrator modes to run tests for. Valid options: standalone,distributed (default: "standalone,distributed")
  -h, --help                                             display help for command

@SdgJlbl
Copy link
Contributor Author

SdgJlbl commented Mar 21, 2023

/e2e --tests sdk,frontend,substrafl --benchmarks mnist,camelyon --refs substra=fix/compute-task-performance-issue,substra-tests=fix/compute-task-performance-issue

@Owlfred
Copy link

Owlfred commented Mar 21, 2023

End to end tests: ❌ FAILURE

It'll stay between us, no one needs to know.

@SdgJlbl
Copy link
Contributor Author

SdgJlbl commented Mar 21, 2023

/e2e --tests sdk,frontend,substrafl --benchmarks mnist,camelyon --refs substra=fix/compute-task-performance-issue,substra-tests=fix/compute-task-performance-issue

@Owlfred
Copy link

Owlfred commented Mar 21, 2023

End to end tests: ❌ FAILURE

Jobs status:

  • Tests Benchmark:
  • Tests Distributed:
  • Tests Standalone:

“You shall not pass!” ― Gandalf, The Lord of the Rings, The Fellowship of the Ring

@SdgJlbl
Copy link
Contributor Author

SdgJlbl commented Mar 22, 2023

/e2e --tests sdk,frontend,substrafl --benchmarks mnist,camelyon --refs substra=fix/compute-task-performance-issue,substra-tests=fix/compute-task-performance-issue

@Owlfred
Copy link

Owlfred commented Mar 22, 2023

End to end tests: ✔️ SUCCESS

“Shaken, not stirred.” ― James Bond, Goldfinger

@SdgJlbl SdgJlbl force-pushed the fix/lipome-compute-task-optim branch from 7dddb68 to 5bea4da Compare March 22, 2023 13:55
@SdgJlbl SdgJlbl marked this pull request as ready for review March 22, 2023 13:57
models.When(start_date__isnull=True, then=0),
default=Extract(Coalesce("end_date", Now()) - models.F("start_date"), "epoch"),
return (
ComputeTask.objects.filter(channel=get_channel_name(self.request))
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a difference between using ComputeTask.objects and super().get_queryset()?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't think so, I feel like it's slightly more explicit not to use super() given that there is some multiple inheritance with mixins here, but maybe I'm missing some under-the-hood optimization...

Copy link
Contributor

@guilhem-barthes guilhem-barthes left a comment

Choose a reason for hiding this comment

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

LGTM!

@SdgJlbl
Copy link
Contributor Author

SdgJlbl commented Mar 23, 2023

/e2e --tests sdk,frontend,substrafl --benchmarks mnist,camelyon

@Owlfred
Copy link

Owlfred commented Mar 23, 2023

End to end tests: ❌ FAILURE

Jobs status:

  • Tests Benchmark:
  • Tests Distributed:
  • Tests Standalone:

“Just Keep Swimming!” ― Dory, Finding Nemo

@SdgJlbl
Copy link
Contributor Author

SdgJlbl commented Mar 24, 2023

/e2e --tests sdk,frontend,substrafl --benchmarks mnist,camelyon --refs substra=fix/compute-task-performance-issue,substra-tests=fix/compute-task-performance-issue

@Owlfred
Copy link

Owlfred commented Mar 24, 2023

End to end tests: ❌ FAILURE

Jobs status:

  • Tests Benchmark:
  • Tests Distributed:
  • Tests Standalone:

“Just Keep Swimming!” ― Dory, Finding Nemo

@SdgJlbl
Copy link
Contributor Author

SdgJlbl commented Mar 24, 2023

/e2e --tests sdk,frontend,substrafl --benchmarks mnist,camelyon --refs substra=fix/compute-task-performance-issue,substra-tests=fix/compute-task-performance-issue

@Owlfred
Copy link

Owlfred commented Mar 24, 2023

End to end tests: ❌ FAILURE

“Boy, that escalated quickly.” ― Ron Burgundy, Anchorman: The Legend of Ron Burgundy

@SdgJlbl
Copy link
Contributor Author

SdgJlbl commented Mar 24, 2023

/e2e --tests sdk,frontend,substrafl --benchmarks mnist,camelyon --refs substra=fix/compute-task-performance-issue,substra-tests=fix/compute-task-performance-issue

@Owlfred
Copy link

Owlfred commented Mar 24, 2023

End to end tests: ❌ FAILURE

Jobs status:

  • Tests Benchmark:
  • Tests Distributed:
  • Tests Standalone:

“You shall not pass!” ― Gandalf, The Lord of the Rings, The Fellowship of the Ring

@SdgJlbl
Copy link
Contributor Author

SdgJlbl commented Mar 24, 2023

/e2e --tests sdk,frontend,substrafl --benchmarks mnist,camelyon --refs substra=fix/compute-task-performance-issue,substra-tests=fix/compute-task-performance-issue

@Owlfred
Copy link

Owlfred commented Mar 24, 2023

End to end tests: ✔️ SUCCESS

“It’s alive! It’s alive!” ― Henry Frankenstein, Frankenstein

@guilhem-barthes guilhem-barthes merged commit d7beb02 into main Mar 24, 2023
@guilhem-barthes guilhem-barthes deleted the fix/lipome-compute-task-optim branch March 24, 2023 14:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants