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

Optimize redis writes for production #37

Closed
odedfos opened this issue Jan 5, 2015 · 1 comment
Closed

Optimize redis writes for production #37

odedfos opened this issue Jan 5, 2015 · 1 comment

Comments

@odedfos
Copy link

odedfos commented Jan 5, 2015

Hi,
In my system I had a latency issue between my the web-server and the redis redis. This led me to discover some inefficiency in the metrics logic when updating metrics.

checkout
def metric(self, slug, num=1, category=None, expire=None)

in https://github.com/bradmontgomery/django-redis-metrics/blob/master/redis_metrics/models.py [331]

For each key a separate incrementation is performed which leads to multiple redis calls.
Better to use a pipe here and update all keys in a single api call.

for example:

...
pipe = self.r.pipeline()

pipe.incr(hour_key, num)
pipe.incr(day_key, num)
pipe.incr(week_key, num)
pipe.incr(month_key, num)
pipe.incr(year_key, num)

pipe.execute()

Cheers!

@bradmontgomery
Copy link
Owner

Hi @odedfos, this seems like a great idea. Do you mind making the change, and sending me a pull request, so I can merge? Be sure to add yourself to AUTHORS.rst as well.

Thanks!

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