Skip to content

Slow queries when events of a type are rare. #52

Open
@macosgrove

Description

@macosgrove

RSS, an Event Sourcery project, was having problems with the database CPU usage increasing over time:

screen shot 2018-04-12 at 10 47 22 am

We turned on Postgres logging to look for slow queries and found these two:

SELECT * FROM "events" 
WHERE ("type" IN ('revenue_period_voided', 'revenue_period_ended')) 
ORDER BY "id" DESC 
LIMIT 1

and

SELECT * FROM "events" 
WHERE ((id >= 3616762) AND ("type" IN ('revenue_period_voided', 'revenue_period_ended'))) 
ORDER BY "id" 
LIMIT 1000

RSS stopped emitting events of type revenue_period_ended and revenue_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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions