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

Speed up Datastore deletes by batch deletions with multithreading #2182

Merged
merged 4 commits into from
Jan 5, 2022

Conversation

ptoman-pa
Copy link
Contributor

What this PR does / why we need it:
Speeds up teardown in Datastore by 3-4 orders of magnitude via Datastore's delete_multi plus multithreading with a work queue. (Previous approach was one-request-per-element single-threaded deletions.)

Which issue(s) this PR fixes:
No issue

Does this PR introduce a user-facing change?:

NONE

Signed-off-by: Pamela Toman <ptoman@paloaltonetworks.com>
@ptoman-pa ptoman-pa requested a review from a team as a code owner January 4, 2022 01:32
@ptoman-pa ptoman-pa requested review from mavysavydav and removed request for a team January 4, 2022 01:32
@feast-ci-bot
Copy link
Collaborator

Hi @ptoman-pa. Thanks for your PR.

I'm waiting for a feast-dev member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

Signed-off-by: Pamela Toman <ptoman@paloaltonetworks.com>
@@ -32,6 +35,9 @@
from feast.protos.feast.types.Value_pb2 import Value as ValueProto
from feast.repo_config import FeastConfigBaseModel, RepoConfig
from feast.usage import log_exceptions_and_usage, tracing_span
from feast.utils.generic_utils import AtomicCounter
Copy link
Member

Choose a reason for hiding this comment

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

We've generally tried to avoid adding utils modules since it's a kitchen sink/code smell. If this AtomicCounter is only used in this datastore class, maybe we can just define it here? Or rename feast.utils.generic_utils to feast.atomic or something?

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'm actually glad to hear this :) I wanted to use the patterns of the codebase. I'm going to move it into an innerclass just for the _delete_all_values since it's only used for that logging statement (or we could remove the logging), and it can always be migrated to increasing scope if needed.

while True:
client.delete_multi(deletion_queue.get())
shared_counter.increment()
LOGGER.info(
Copy link
Member

Choose a reason for hiding this comment

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

This should maybe be .debug?

@achals achals self-assigned this Jan 4, 2022
Signed-off-by: Pamela Toman <ptoman@paloaltonetworks.com>
@codecov-commenter
Copy link

codecov-commenter commented Jan 4, 2022

Codecov Report

Merging #2182 (941dc05) into master (068389d) will increase coverage by 0.04%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2182      +/-   ##
==========================================
+ Coverage   84.59%   84.64%   +0.04%     
==========================================
  Files         102      102              
  Lines        8186     8230      +44     
==========================================
+ Hits         6925     6966      +41     
- Misses       1261     1264       +3     
Flag Coverage Δ
integrationtests 74.37% <100.00%> (-0.19%) ⬇️
unittests 58.86% <14.28%> (-0.15%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
sdk/python/feast/infra/online_stores/datastore.py 83.00% <100.00%> (+2.88%) ⬆️
sdk/python/feast/type_map.py 72.65% <0.00%> (-0.52%) ⬇️
.../integration/online_store/test_universal_online.py 97.67% <0.00%> (-0.47%) ⬇️
sdk/python/feast/online_response.py 87.71% <0.00%> (ø)
sdk/python/feast/feature_store.py 91.48% <0.00%> (+0.12%) ⬆️
sdk/python/feast/infra/provider.py 90.09% <0.00%> (+0.18%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 068389d...941dc05. Read the comment docs.

with self.lock:
self.value += 1

BATCH_SIZE = 500 # Dec 2021: delete_multi has a max size of 500
Copy link
Member

Choose a reason for hiding this comment

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

Nit is there a doc we can link to in case this changes in the future?

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 just went looking and couldn't find an obvious place. If we try to query with more than 500, the server responds:

google.api_core.exceptions.InvalidArgument: 400 cannot write more than 500 entities in a single call

Copy link
Member

Choose a reason for hiding this comment

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

Signed-off-by: Pamela Toman <ptoman@paloaltonetworks.com>
@achals
Copy link
Member

achals commented Jan 4, 2022

/ok-to-test

Copy link
Member

@achals achals left a comment

Choose a reason for hiding this comment

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

/lgtm

@feast-ci-bot
Copy link
Collaborator

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: achals, ptoman-pa

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@feast-ci-bot feast-ci-bot merged commit e8e4972 into feast-dev:master Jan 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants