memcached

Jbuilder Rails caching is slower

你。 提交于 2020-01-01 05:16:12
问题 I've tried to use caching with collections (with multiple solutions) the problem is that when ever I try caching the response become slower consider the following example of a collection that renders 2 partials for every item in it (around 25 item) json.data do json.array! @organizations do |organization| json.partial! 'api/v1/organizations/organization', organization: organization json.partial! 'api/v1/organizations/links', organization: organization end end without caching the average

Redis与Memcached的区别

ぃ、小莉子 提交于 2020-01-01 05:11:48
观点一: 1、Redis和Memcache都是将数据存放在内存中,都是内存数据库。不过memcache还可用于缓存其他东西,例如图片、视频等等; 2、Redis不仅仅支持简单的k/v类型的数据,同时还提供list,set,hash等数据结构的存储; 3、 虚拟内存 --Redis当物理内存用完时,可以将一些很久没用到的value 交换到磁盘; 4、过期策略--memcache在set时就指定,例如set key1 0 0 8,即永不过期。Redis可以通过例如expire 设定,例如expire name 10; 5、分布式--设定memcache集群,利用magent做一主多从;redis可以做一主多从。都可以一主一从; 6、存储数据安全--memcache挂掉后,数据没了;redis可以定期保存到磁盘(持久化); 7、 灾难恢复 --memcache挂掉后,数据不可恢复; redis数据丢失后可以通过aof恢复; 8、Redis支持数据的备份,即master-slave模式的数据备份; 9、mongodb和memcached不是一个范畴内的东西。mongodb是文档型的非关系型数据库,其优势在于查询功能比较强大,能存储海量数据。mongodb和memcached不存在谁替换谁的问题。 观点二: Redis与Memcached的区别

面试题:缓存Redis与Memcached的比较 有用

寵の児 提交于 2020-01-01 05:11:37
Memcached是一个高性能的分布式内存对象缓存系统,用于动态Web应用以减轻数据库负载. 它通过在内存中缓存数据和对象来减少读取数据库的次数, 从而提供动态、数据库驱动网站的速度. Memcached基于一个 存储键/值对的hashmap 。 Redis是一 个key-value存储系统 ,和Memcached类似。但是它支持存储的value类型相对更多, 包括string(字符串)、 list(链表)、set(集合)、zset(sorted set --有序集合)和hashs(哈希类型) 。 这些数据类型都支持push/pop、add/remove及取交集并集和差集及更丰富的操作,而且这些操作都 是原子性的 。在此基础上 ,redis支持各种不同方式的排序 。与memcached一样, 为了保证效率,数据都是缓存在内存中。区别的是 redis会周期 性的把更新的数据写入磁盘或者 把修改操作写入追加的记录文件 ,并且在此基础上实现了master-slave(主从)同步。 Redis是一个高性能的key-value数据库。redis的出现,很大程度补偿了memcached这类key/value存储的不足,在部 分场合可以对关系数据库起到很好的补充作用。它提供了Python,Ruby,Erlang,PHP客户端,使用很方便. 下面主要介绍一下Redis与Memcached的不同。

Memcached和Redis比较

时光怂恿深爱的人放手 提交于 2020-01-01 05:11:28
一、存储 Memcached基本只支持简单的key-value存储方式。 Redis除key-value之外,还支持list,set,sorted set,hash等数据结构; Redis支持数据的备份,即master-slave模式的数据备份; Redis支持数据的持久化(快照、AOF),可以将内存中的数据保持在磁盘中,重启的时候可以再次加载进行使用; Redis可以实现主从复制,实现故障恢复; Redis的Sharding技术,很容易将数据分布到多个Redis实例中。 二、数据一致性 Memcached的cas命令在并发场景下,保证数据的一致性。 Redis事务支持比较弱,只能保证事务中的每个操作连续执行。 三、内存管理   Memcached使用预分配的内存池的方式。使用slab和大小不同的chunk来管理内存,Item根据大小选择合适的chunk存储,内存池的方式可以省去申请/释放内存的开销,并且能减小内存碎片产生,但这种方式也会带来一定程度上的空间浪费,并且在内存仍然有很大空间时,新的数据也可能会被剔除。   Redis使用现场申请内存的方式来存储数据。并且很少使用free-list等方式来优化内存分配,会在一定程度上存在内存碎片,Redis跟据存储命令参数,会把带过期时间的数据单独存放在一起,并把它们称为临时数据,非临时数据是永远不会被剔除的,即便物理内存不够

Centos 下安装使⽤ Memcache

冷暖自知 提交于 2020-01-01 04:45:24
1.美图 2.安装 在 Centos 下安装使⽤用 yum 命令安装 Memcache ⾮非常简单: yum install -y memcached 启动: /usr/bin/memcached -b -p 11211 -m 150 -u root >> /tmp/memcached.log & 启动参数可以配置,常⽤用的命令选项如下: m 内存 c 最⼤大链接数 p 端⼝口 u ⽤用户 t 线程数 查看 memcached 是否在运⾏行行: ( base ) lcc@lcc memadmin$ ps -ef | grep memcached 501 55194 1 0 11:29上午 ?? 0:00.52 /usr/local/bin/memcached -d 501 56702 1 0 11:37上午 ?? 来源: CSDN 作者: 九师兄 链接: https://blog.csdn.net/qq_21383435/article/details/103743458

Why Use Redis instead of MongoDb for Caching? [closed]

孤人 提交于 2019-12-31 10:48:54
问题 As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 7 years ago . I've seen many people using Redis as a cache lately, why not Mongo? As far as I could tell Redis can set an expire date on an index,

Memcached best practices - small objects and lots of keys or big objects and few keys?

。_饼干妹妹 提交于 2019-12-31 10:31:50
问题 I use memcached to store the integer result of a complex calculation. I've got hundreds of integer objects that I could cache! Should I cache them under a single key in a more complex object or should I use hundreds of different keys for the objects? (the objects I'm caching do not need to be invalidated more than once a day) 回答1: I would say lots of little keys. This way you can get the exact result you want in 1 call with minimal serialization effort. If you store it in another object (an

What are some useful tips/tools for monitoring/tuning memcached health?

雨燕双飞 提交于 2019-12-31 09:04:10
问题 Yesterday, I found this cool script 'memcache-top' which nicely prints out stats of memcached live. It looks like, memcache-top v0.6 (default port: 11211, color: on, refresh: 3 seconds) INSTANCE USAGE HIT % CONN TIME EVICT/s READ/s WRITE/s 127.0.0.1:11211 88.8% 94.8% 20 0.8ms 9.0 311.3K 162.8K AVERAGE: 88.8% 94.8% 20 0.8ms 9.0 311.3K 162.8K TOTAL: 1.8GB/ 2.0GB 20 0.8ms 9.0 311.3K 162.8K (ctrl-c to quit.) it even makes certain text red when you should pay attention to something! Q. Broadly,

Best way to combine fragment and object caching for memcached and Rails

纵饮孤独 提交于 2019-12-31 08:39:32
问题 Lets say you have a fragment of the page which displays the most recent posts, and you expire it in 30 minutes. I'm using Rails here. <% cache("recent_posts", :expires_in => 30.minutes) do %> ... <% end %> Obviously you don't need to do the database lookup to get the most recent posts if the fragment exists, so you should be able to avoid that overhead too. What I'm doing now is something like this in the controller which seems to work: unless Rails.cache.exist? "views/recent_posts" @posts =

Rails Caching DB Queries and Best Practices

 ̄綄美尐妖づ 提交于 2019-12-31 08:29:33
问题 The DB load on my site is getting really high so it is time for me to cache common queries that are being called 1000s of times an hour where the results are not changing. So for instance on my city model I do the following: def self.fetch(id) Rails.cache.fetch("city_#{id}") { City.find(id) } end def after_save Rails.cache.delete("city_#{self.id}") end def after_destroy Rails.cache.delete("city_#{self.id}") end So now when I can City.find(1) the first time I hit the DB but the next 1000 times