问题
LR上线前内存使用量在2G左右
上线后飙升至6G(临时扩容)
线上 info memory
used_memory:6383569136
used_memory_human:5.95G
used_memory_rss:6614622208
used_memory_rss_human:6.16G
used_memory_peak:6383749464
used_memory_peak_human:5.95G
used_memory_peak_perc:100.00%
used_memory_overhead:2651540994
used_memory_startup:3833152
used_memory_dataset:3732028142
used_memory_dataset_perc:58.50%
total_system_memory:134568148992
total_system_memory_human:125.33G
used_memory_lua:37888
used_memory_lua_human:37.00K
maxmemory:10737418240
maxmemory_human:10.00G
maxmemory_policy:allkeys-lru
mem_fragmentation_ratio:1.04
mem_allocator:jemalloc-4.0.3
active_defrag_running:0
lazyfree_pending_objects:0
redis 线上内存使用情况
used_memory_dataset:3732028142 实际数据使用量 3559.1387M 3.5G
used_memory_overhead:2651540994 2528.706M 2.5G
mem_fragmentation_ratio= used_memory_rss/used_memory
used_memory= used_memory_dataset+ used_memory_overhead
按 6500万数据计算 每个KEY 60字节计算(实际计算可能会有出入)
String key=String.format("mc:0:lrcsfs:%s:%s",Integer.MAX_VALUE,Integer.MAX_VALUE);
long length= key.getBytes().length+"0.02886395".length()+8;
set a 0.02838383
"OK"
localhost:0>OBJECT ENCODING
a
"embstr"
Embstr 字符串约占"0.02886395".length()+8(length +free)
实际上用量 3210.0674 3.2G 与预估使用量相当
非官方解释:used_memory_overhead: All the memory overhead used by Redis internally to maintain the dataset, including all the client output buffer, query buffer, AOF rewrite buffer, and replication backlog」
官方解释:used_memory_overhead: The sum in bytes of all overheads that the server allocated for managing its internal data structure
可知2G内存由系统开销
结论
6500万记录的存储空间大约在10个G左右(三台总量),工程优化空间有限
数据算法优化
目前LR特征结果数据为N*M维矩阵 N为用户量,M为ITEM量
- 理论上并非所有用户都存在LR特征数据,可以将一部门用户不存储(适合LR的用户mysql 表t_recommend_index_lr_improve_user)用2.1万,交叉特征里面用户百万,可以将交叉特征里面的用户降到2.1万,
- 并非所有ITEM都会推荐给用户,可以将部分长尾item移除
具体数据分析给出结论
其次算法层面优化,是否可以进一步降维,类似于ALS 高维矩阵降为低维矩阵,用时间换空间
网友评论