Laravel 7:MariaDB与Redis结合使用,但是Redis在大型对象上的运行速度较慢 [英] Laravel 7: MariaDB in combination with Redis but Redis behaves slower with large objects

查看:20
本文介绍了Laravel 7:MariaDB与Redis结合使用,但是Redis在大型对象上的运行速度较慢的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经成功实现了redis和mysql的组合.在我的应用程序的一部分中,我以为我会减少mysql服务器的负载并使用redis直到数据被更改,但是我观察到从Mysql提取相同的数据比redis仍然更快.

I have successfully implemented a combination of redis and mysql. At one section of my application I thought I would reduce load on mysql server and use redis until the data gets changed, however I observe that it's still faster when the same data is fetched from Mysql than redis.

这是场景.

User1:10,000条记录在一天左右的时间内很少更改.

User1: 10,000 records with seldom one off change in a day or so.

我要做的是将获取这10K记录的整个对象(大小约为20mb的序列化对象)保存到redis.这样做的想法是,由于随后的100到1000个请求仅是页面刷新,所以为什么不避免mysql命中并从redis获取此数据.

What I do is whole object that fetches these 10K records, (serialized object of about 20mb in size) is saved to redis. The idea is that since subsequent 100 to 1000 requests will only be just page refreshes so why not avoid mysql hits and get this data from redis.

但是,我观察到,当从Redis提取此对象时,它比刷新刷新Redis并命中mysql查询要花费更多的时间.我以为redis会更快,或者至少具有相同的mysql-like速度,但这是不同的.

However, I have observed that when this object is fetched from Redis, it takes more time than when I flush redis and the mysql query is hit. I thought redis would have been faster or have the same mysql-like speed at least, but here it's different.

此外,我已经观察到,从Redis获取20mb对象时,我的php出现了允许的内存耗尽"错误(我知道该如何解决),但是当从相同的数据中获取相同的内容时,它并没有给出任何错误MySQL的.

Also, I have observed that while fetching the 20mb object from Redis my php gives the "allowed memory exhausted" error (which I know how to fix) but it doesn't give out any error when the same data is fetched from mysql.

Redis是否不适合缓存大型对象?还是还有其他东西?

Could it be that Redis is not fit for caching huge objects? Or is there something else?

谢谢

推荐答案

Redis不适用于存储/获取大型对象.在网络/带宽中获取/设置这些对象时,您将遭受痛苦.由于它是单线程的,因此在存储/获取这些大对象时,其他请求也会受到影响.

Redis is not designed/fit for storing/fetching large objects. You will suffer while getting/setting these objects in network/bandwidth. Since it is single threaded, other requests also will suffer while storing/fetching these large objects.

基准文档中所述;

RAM的速度和内存带宽对于全局性能似乎不太重要,特别是对于小型对象.对于大对象(> 10 KB),它可能会变得很明显.通常,购买昂贵的快速内存模块来优化Redis并不是很划算.

Speed of RAM and memory bandwidth seem less critical for global performance especially for small objects. For large objects (>10 KB), it may become noticeable though. Usually, it is not really cost-effective to buy expensive fast memory modules to optimize Redis.

您可能要做的是,根据应用程序的查询要求,使用哈希列表重新设计缓存层.您可以在此处中查看其他信息.我也在此处

What you may do is, redesign your cache layer with hashes or lists depending on the query requirements of your application. You may check here for additional information. Also i answered a similar question in here

这篇关于Laravel 7:MariaDB与Redis结合使用,但是Redis在大型对象上的运行速度较慢的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆