kiddouk / redisco

A Python Library for Simple Models and Containers Persisted in Redis

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Natural keys

dmk23 opened this issue · comments

I've done some tracing of Redis calls and was very unpleasantly surprised with the number of queries generated by Redisco and the resulting latency increase.

One of the root causes is the fact that Redisco does not support natural keys (e.g. IP address, etc). Instead every model requires an integer primary key and a natural key field, both with unique indices. Every index relies on clunky/slow lists/sets and expensive operations to keep them running.

Overall what should be a simple HMGET call turns into ~10 various commands that cannot even be pipelined. Obviously this completely kills any latency-sensitive applications.

The question is whether there are any plans / code snippets to implement natural keys. I may have to hack it myself quick, but wanted to see if anyone tried it before and/or may have any input.

I am curious, how would you see such implementation ? Can you give some precise examples of objects with indexing ? For now, we try to follow Ohm project as close as we can.

As I said, objects intended to represent things like URLs or user agent strings make great examples here. They all have long strings as natural keys. If they were to be indexed attributes, these strings would get replicated in at least 3 times increasing memory bloat and slowing down the computation.

They keys would be something like this "objname:<obj_natural_key_str>" instead of "objname:<obj_int_key>"