Skip to content

Improve performance of deletes over many partitions, #384 - #385

Merged
patriknw merged 3 commits into
masterfrom
wip-perf-delete-patriknw
Aug 17, 2018
Merged

patriknw merged 3 commits into
masterfrom
wip-perf-delete-patriknw

Conversation

@patriknw

Copy link
Copy Markdown
Contributor
  • The lowest sequence number is always the stored highestDeletedSequenceNumber,
    instead of 1
  • Use the given toSequenceNumber as highest instead of searching for highest,
    but Long.MaxValue can be used for deleting all events without knowing the
    highest
  • The main problem was that it was searching for highest sequence number in
    all partitions.

Refs #384

@t3hnar

t3hnar commented Aug 16, 2018

Copy link
Copy Markdown
Contributor

You also don't need to query partitionInfo in for non config.cassandra2xCompat, which is a happy path.

val partitionInfos = (lowestPartition to highestPartition).map(partitionInfo(persistenceId, _, toSeqNr))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

should be highestDeletedSequenceNumber + 1

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

right, thanks

@t3hnar t3hnar Aug 16, 2018 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I propose to still flatMap physicalDelete future, for instance we have covered all journal methods with metrics and did not see that deletion takes so much time.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I think the reason was that the physical delete could run in the background without affecting the response time of the PersistentActor.

On the other hand I guess there is no reason for a PersistentActor to "wait" or depend on how long time it takes for the delete to complete, so one could say that the entire delete is running in the background.

One problem with adding that to the response time might be that it could trigger the CircuitBreaker in Akka.

Let's see if there are other opinions when this PR is reviewed.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This makes sense so that if a user actor gets a delete success they are definitely fully deleted.
Also completing the Future earlier only effects when the user actor gets the delete success it doesn't block further writes so it isn't really optimising anything unless the user is doing a side effect on delete success.

Maybe under a diff PR or commit?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Please :)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

sure, I'll change that tomorrow morning

@patriknw

Copy link
Copy Markdown
Contributor Author

You also don't need to query partitionInfo

Fixed, thanks

@chbatey chbatey left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Don't forget :)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This makes sense so that if a user actor gets a delete success they are definitely fully deleted.
Also completing the Future earlier only effects when the user actor gets the delete success it doesn't block further writes so it isn't really optimising anything unless the user is doing a side effect on delete success.

Maybe under a diff PR or commit?

* The lowest sequence number is always the stored highestDeletedSequenceNumber,
  instead of 1
* Use the given toSequenceNumber as highest instead of searching for highest,
  but Long.MaxValue can be used for deleting all events without knowing the
  highest
* The main problem was that it was searching for highest sequence number in
  all partitions.

* no need to query PartitionInfo
@patriknw
patriknw force-pushed the wip-perf-delete-patriknw branch from 2e088aa to 3443a34 Compare August 17, 2018 09:02
@patriknw

Copy link
Copy Markdown
Contributor Author

@chbatey Please review the additional change of running the physical deletes 7a292f0

highestSequenceNr <- asyncFindHighestSequenceNr(persistenceId, lowestSequenceNr, config.targetPartitionSize)
_ <- logicalDeleteWithAsyncPhysicalDelete(lowestSequenceNr, highestSequenceNr)
highestSequenceNr <- {
// MaxValue may be used as magic value to delete all events without specifying actual toSequenceNr

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I have also added a check of valid seqnr in Akka akka/akka-core#25488

@chbatey

chbatey commented Aug 17, 2018

Copy link
Copy Markdown
Contributor

Looks good, one question about when to kick off the next delete if they are queued

* The reason was that the physical delete could run in the background
  without affecting the response time of the PersistentActor.
* However, there is no reason for a PersistentActor to "wait"
  or depend on how long time it takes for the delete to complete,
  so one could say that the entire delete is running in the background.
* This change will make it look like deletes take longer time and
  may in worst case trigger CircuitBreaker in Akka, but it was
  considered better to make that visible than silently running
  parts of it in the background.
@patriknw
patriknw force-pushed the wip-perf-delete-patriknw branch from 3443a34 to 6304fd5 Compare August 17, 2018 12:51
@patriknw

Copy link
Copy Markdown
Contributor Author

pushed small rename

@patriknw
patriknw merged commit 110b5f6 into master Aug 17, 2018
@patriknw
patriknw deleted the wip-perf-delete-patriknw branch August 17, 2018 14:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants