The most efficient way to insert an already sorted set into REDIS

I already have a sorted set in memory of size (N) and you want to reset it to redis, can this be done in O (N) if you insert the head or tail first? or it does not matter, and the insert will be O (log (N!)) ~ O (N log (N))

For more information, sorted redis sets are implemented using hashmap and skiplist (for ordering).

EDIT: This question remains unanswered from the very beginning, or at least the answer is a bit ambiguous for me: Redis: ZADD is better than O (logN) when the inserted element is at the beginning or end?

+5
source share
2 answers

Here are the results of my β€œempirical” approach , which suggest that there might be little benefit from ordering :)

(.venv) foo@bar :~/so_bounty$ python main.py ascending order 5.57414388657 descending order 5.72963309288 random order 6.75937390327 0 score 5.79048109055 
+3
source

After doubts about the methodology used in the other empirical approach, I conducted my own insert test (all sets are initialized before the synchronization insert, for random testing of the insert, the list of tuples is shuffled before the synchronization starts) with the following results:

for an ordered set with members 2k, 20k and 200k:

  • head one: 196.29s | 1146.43s | 9897.29s
  • tail first: 170.14s | 993.43 s | 9722.14s
  • rand insert: 146.00s | 1014.57 s | 9968.57s

All with sufficient variability (standard developers at 7.8 | 54.5 | 324.5 respectively), so the difference is not significant enough for the conclusions. It doesn't seem to matter ... :(

+1
source

Source: https://habr.com/ru/post/1213315/


All Articles