缓存预热的思路
a.提前给redis中嵌入部分数据,再提供服务
b.肯定不可能将所有数据都写入redis,因为数据量太大了,第一耗费的时间太长了,第二redis根本就容纳不下所有的数据
c.需要更具当天的具体访问情况,试试统计出频率较高的热数据
d.然后将访问频率较高的热数据写入到redis,肯定是热数据也比较多,我们也得多个服务并行的读取数据去写,并行的分布式的缓存预热
e.然后将嵌入的热数据的redis对外提供服务,这样就不至于冷启动,直接让数据库奔溃了
(简单讲 不要让所有的请求都去数据库查 提前把一些热点数据存入 至于哪些是热数据 这就得实时分析了呀)
具体的实时方案:
1. nginx+lua将访问量上报到kafka中
要统计出来当前最新的实时的热数据是哪些,我们就得将商品详情页访问的请求对应的流量,日志,实时上报到kafka中,
2. storm从kafka中消费数据,实时统计出每个商品的访问次数,访问次数基于LRU内存数据结构的存储方案 (LRU 看次数)
3. 每个storm task启动的时候,基于zk分布式锁,将自己的id写入zk的一个节点中
4. 每个storm task负责完成自己这里的热数据的统计,比如每次计数过后,维护一个钱1000个商品的list,每次计算完都更新这个list
5. 写一个后台线程,每个一段时间,比如一分钟,将排名钱1000的热数据list,同步到zk中