-
Notifications
You must be signed in to change notification settings - Fork 7
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
Slow queries when events of a type are rare. #52
Comments
Have done some digging (many thanks to @gstib for his help) and found that we are pretty well as optimised as we are going to get with the database indexes. We tried a bunch of different indexes, combinations etc but it always decided to use the primary key index and filter the results. I think a possible fix is for Event Sourcery to maintain an index to the 'top' of the event store (since it last checked for that particular event type) and only check for subsequent events of that type from when it last checked (rather than for all time). |
Looks like that first query is coming from latest_event_id and the second from get_next_from in But I can't find any calls of |
Same thing with this query, it uses the primary key index to get results and then filters:
|
We have identified this issue again where there were no recent events that a certain projector cares about, the tracker was stuck in a past event while the event store keeps growing. The challenge here is keeping a good compromise in performance, only loading specific event types but also finding a way to advance the tracker when there are no event types for the processor. We could consider loading all types of events and only forwarding the ones that the processor cares about. This would allow for advancing the tracker but would have additional burden on all projectors. Also considered having an additional query to get the latest event (of any type) after an empty result, but this could cause skipping events. In the meantime, our workaround was to register a dummy handler for another event type that is known to be frequent: project FrequentEvent do
# no-op
end |
RSS, an Event Sourcery project, was having problems with the database CPU usage increasing over time:
We turned on Postgres logging to look for slow queries and found these two:
and
RSS stopped emitting events of type
revenue_period_ended
andrevenue_period_voided
some time ago but we had not turned off their projector.The dip in the CPU graph is when we disabled the relevant projector.
The implication here is that any projector that deals with RARE events will run slow.
@envatopoho is investigating indexes that may resolve the issue.
The text was updated successfully, but these errors were encountered: