The performance of SINTER or SINTERSTORE depends on the
cardinality of your smallest set. For these operations,
redis sorts the sets per cardinality, and then scans the
first set trying to match each item in the other sets
(in the optimal order).
The problem is when you do not have a set significantly
smaller than the other ones.
I have tried an example with 350000 users:
cardinality gender = 175000 (2 genders)
cardinality city = 58000 (6 cities)
cardinality interest = 127000 (5 interest domains,
each user has up to 2 of them)
doing:
sinterstore tmp city:NCE gender:F interest:NATURE
sort tmp by nosort limit 0 100 get *
My oldish PC (a 2 GHz Athlon X2) cannot sustain more than 18 TPS
of these commands. Do not expect more than 3 or 4 times this
figure on recent server hardware. If you multiply the volume
of the smallest set by 10, you can divide the throughput by the
same value.
You may want to isolate this kind of queries on a slave in order to
keep your master responsive.
Now, if you denormalize the criteria, you can expect the cardinalities
to be much smaller and the performance much higher, but you actually
loose some flexibility.
For instance, if you keep only one kind of sets aggregating
gender,city,interest, the same query is covered by the following
command:
sort idx:F:NCE:NATURE by nosort limit 0 100 get *
(no intersection needed anymore)
This query is much faster (my hardware now supports 250 TPS
rather than 18 TPS). However you loose the possibility to
query on a subset of the criteria (you need the three of
them systematically). Also, it only works if the cardinality
of the cartesian product of the criteria is not too high
(here it would be 2*6*5 -> no problem).
An intermediate solution is to denormalize only a subset of
the criteria, the purpose being to decrease only the
cardinality of the smallest set. For instance, if I build
a set with gender,city keeping the interest sets unchanged,
I will instantly double my 18 TPS throughput, trading
performance against some flexibility.
Hope this helps ...
Regards,
Didier.