akka / akka-persistence-cassandra

A replicated Akka Persistence journal backed by Apache Cassandra
https://doc.akka.io/libraries/akka-persistence-cassandra/current/
Other
329 stars 135 forks source link

Improve performance of asyncReadHighestSequenceNr #332

Open patriknw opened 6 years ago

patriknw commented 6 years ago

The select highest journal sequence number cql query orders the journal messages by sequence_nr in descending order to get the highest sequence number. The journal's messages table orders the messages by sequence_nr in ascending order by default. This can cause the query to be much slower and take away much of the performance benefit of using snapshots.

patriknw commented 6 years ago

In the end we need a RecoverySuccess(highSeqNr), but it's unclear to me why we have to first asyncReadHighestSequenceNr and then asyncReplayMessages, instead of using the last sequenceNr from asyncReplayMessages. Perhaps it's because asyncReadHighestSequenceNr is also using asyncHighestDeletedSequenceNumber? Might be possible to use max of asyncReplayMessages and asyncHighestDeletedSequenceNumber instead?

patriknw commented 6 years ago

I'm starting to work on this.

patriknw commented 6 years ago

I have not been able to reproduce any performance problem with asyncReadHighestSequenceNr. Tried with 5 million events and that query is still sub millis response time (not increasing with number of events).