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 replay from SQL Server #4

Open
kblooie opened this issue May 23, 2015 · 5 comments
Open

Speed up replay from SQL Server #4

kblooie opened this issue May 23, 2015 · 5 comments

Comments

@kblooie
Copy link
Contributor

kblooie commented May 23, 2015

From @danbarua on February 13, 2015 10:21

I'm not sure how relevant this is to V5/6 but this massively speeds up replays on MSSQL:

CREATE NONCLUSTERED INDEX [IX_Commits_Ordered] ON [dbo].[Commits]
(
    [CommitSequence] ASC,
    [StreamId] ASC,
    [StreamRevision] ASC
)

Copied from original issue: NEventStore/NEventStore#391

@kblooie
Copy link
Contributor Author

kblooie commented May 23, 2015

From @damianh on February 13, 2015 11:31

nice!
On 13 Feb 2015 11:21, "Dan Barua" [email protected] wrote:

I'm not sure how relevant this is to V5/6 but this massively speeds up
replays on MSSQL:

CREATE NONCLUSTERED INDEX [IX_Commits_Ordered] ON [dbo].[Commits]([CommitSequence] ASC,
[StreamId] ASC,
[StreamRevision] ASC)


Reply to this email directly or view it on GitHub
NEventStore/NEventStore#391.

@kblooie
Copy link
Contributor Author

kblooie commented May 23, 2015

From @OyvindAndersen on March 12, 2015 10:48

Hi,

On what version did you add this index? We're using both 2.x and 5.x and for 2.x the PK_Commits has StreamId and CommitSequence. This seems for me like a good index but I have not investigated the actual sql statement for replay.

Why wouldn't you want StreamId first and then CommitSequence. Does including StreamRevision increase performance?

Have you tried snapshots if your performance regarding replays are slow?

@kblooie
Copy link
Contributor Author

kblooie commented May 23, 2015

From @danbarua on March 12, 2015 11:50

This was on V3/4. Snapshots are no use when rebuilding my read model as it needs all the events regardless.
My read model rebuild code is essentially this:

foreach(var commit in store.Advanced.GetFrom(DateTime.MinValue)
foreach(var @event in commit.Events)
{
  DispatchToEventHandlers(@event);
}

I just found this by playing around with SQL Profiler during replays and looking at the query plans.

@kblooie
Copy link
Contributor Author

kblooie commented May 23, 2015

From @OyvindAndersen on March 12, 2015 12:34

Ahh. Ok. In your case u're using DateTime and the actual sql statement is ordered by CommitStamp, StreamId and StreamRevision, at least for V2. So that should be a good index also. There is already one for CommitStamp (IX_Commits_Stamp) that maybe could include StreamId and StreamRevision so you don't need two indexes.

@AGiorgetti
Copy link
Member

Instead of adding the suggested index,
Consider adding the 'CommitSequence' to this index:

CREATE UNIQUE NONCLUSTERED INDEX [IX_Commits_Revisions] ON [dbo].[Commits] ([BucketId], [StreamId], [StreamRevision], [Items]);

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

No branches or pull requests

2 participants