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

Provide new operation to count that consume less CPU #71

Open
mscherer opened this issue Mar 31, 2020 · 0 comments
Open

Provide new operation to count that consume less CPU #71

mscherer opened this issue Mar 31, 2020 · 0 comments
Labels

Comments

@mscherer
Copy link
Contributor

While fixing latest crash (see https://pagure.io/fedora-badges/pull-request/728), I found that we are using lots of ressources counting messages due to the snippet we use in rules.

For example:

len([msg for msg in query.all() if msg.msg['new'] is 1])

consume lots of memory, but also lots of CPU.

The replacement use less memory, but we still have to decode thousand of json string to verify if enough of them have the right value.

I think it would be better to provide a new operation like count that take a lambda (for example "msg.msg['new'] is 1"), a limit (let's say "10"), and try to decode message until we found 10 of them.

This would save a lot of CPU IMHO (not as much as doing the verification server side), and make it easier to people to write good rules without doing cut and paste from the original rules, especially cut and paste of less efficient examples.

For interns wanting to implement that, the code would be around https://github.com/fedora-infra/fedbadges/blob/develop/fedbadges/rules.py#L487

Alternatively, if writing a operation is not good, adding a function that could be reused by the lambda would be easier. I prefer the higher level construct of adding a operation, since this can be later verified, but complexity wise, a operation that can be used is fine too.

@jwflory jwflory added the bug label Mar 31, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants