Redis: Reducing Memory Usage
High Level Tips for Redis
Most of Stream-Framework's users start out with Redis and eventually move to Cassandra because Redis becomes too expensive to host. Stream, our hosted API for building scalable newsfeeds & activity streams is also based on Cassandra.
There are quite a few things you can do to reduce Redis' memory usage though. Here are my favourite 6 high level tips for reducing Redis memory usage. For lower level tips, see the Redis docs on memory optimization.
Tip 1 - Serialization
It is often possible to reduce your Redis memory usage by using the right serialization. Serialize objects using built-in serialization mechanism is very tempting (eg. Python's pickle, PHP's serialize...) but it will likely waste lot of memory for nothing. You should stay away from it and make sure you only serialize what you need. Using something like JSON or Protobuf is often a good idea.
Tip 2 - Compression
If the data you're storing is large enough and contains a lot of text you can often reduce memory usage by adding compression. LZO or Snappy are good options for this use case.
Tip 3 - Fallback to disk based storage (aka your rdbms)
Many times you don't need to store all the data in Redis. If your model allows it, try to store only hot or recent data and hit the database when a request for missing data is performed.
If you go for this approach be sure to include an endmarker in your data. Assuming there are 3 items in your database, Redis would store the 3 items and the end marker. This way you know you don't have to run a database query after item number 3. The end marker approach vastly reduces how frequently you fall back to the database.
Tip 4 - Normalize your storage
Memory is expensive and Redis only uses memory. Take this into account when designing your data structure. A normalized approach is often the better choice compared to a denormalized option.
Tip 5 - Expire and trim the data
If possible, set expirations on everything. This presents data which is rarely used from sticking around in your cluster. It can be a few days, a few weeks, but definitely set some sort of expiration on your data. If you're inserting into lists or sets be sure to trim them occasionally.
Tip 6 - Use the right eviction policy
If the amount of data that you store in Redis grows over time and you can't afford to keep it all in memory, you probably want to configure Redis as a LRU cache storage. Redis allows for 6 different eviction policies, make sure you pick the right one!
Most of these tips are obvious, but before you switch away from Redis, be sure to give them a try.
Redis: Reducing Memory Usage的更多相关文章
- Reducing and Profiling GPU Memory Usage in Keras with TensorFlow Backend
keras 自适应分配显存 & 清理不用的变量释放 GPU 显存 Intro Are you running out of GPU memory when using keras or ten ...
- Shell script for logging cpu and memory usage of a Linux process
Shell script for logging cpu and memory usage of a Linux process http://www.unix.com/shell-programmi ...
- 5 commands to check memory usage on Linux
Memory Usage On linux, there are commands for almost everything, because the gui might not be always ...
- SHELL:Find Memory Usage In Linux (统计每个程序内存使用情况)
转载一个shell统计linux系统中每个程序的内存使用情况,因为内存结构非常复杂,不一定100%精确,此shell可以在Ghub上下载. [root@db231 ~]# ./memstat.sh P ...
- Why does the memory usage increase when I redeploy a web application?
That is because your web application has a memory leak. A common issue are "PermGen" memor ...
- GPU Memory Usage占满而GPU-Util却为0的调试
最近使用github上的一个开源项目训练基于CNN的翻译模型,使用THEANO_FLAGS='floatX=float32,device=gpu2,lib.cnmem=1' python run_nn ...
- 【转】C++ Incorrect Memory Usage and Corrupted Memory(模拟C++程序内存使用崩溃问题)
http://www.bogotobogo.com/cplusplus/CppCrashDebuggingMemoryLeak.php Incorrect Memory Usage and Corru ...
- Memory usage of a Java process java Xms Xmx Xmn
http://www.oracle.com/technetwork/java/javase/memleaks-137499.html 3.1 Meaning of OutOfMemoryError O ...
- detect data races The cost of race detection varies by program, but for a typical program, memory usage may increase by 5-10x and execution time by 2-20x.
小结: 1. conflicting access 2.性能危害 优化 The cost of race detection varies by program, but for a typical ...
随机推荐
- Java的SpringMVC执行流程
SpringMVC找Controller流程 1.扫描整个项目(Spring已经做了)定义一个Map集合. 2.拿到所有加了@Controller注解的类. 3.遍历类里面的所有方法对象. 4.判断方 ...
- 管理和安装 chart【转】
安装 chart 当我们觉得准备就绪,就可以安装 chart,Helm 支持四种安装方法: 安装仓库中的 chart,例如:helm install stable/nginx 通过 tar 包安装,例 ...
- 009.Oracle数据库 , between关键字判断日期在两者之间
/*Oracle数据库查询日期在两者之间*/ SELECT PKID, OCCUR_DATE, ATA FROM LM_FAULT WHERE ( OCCUR_DATE BETWEEN to_date ...
- 013-PHP输出表格
<?php // 数据表格化 print("<TABLE bgcolor='ffccoo' BORDER=\"1\">\n"); // 表格开 ...
- Notepad2&Notepad++
写在前面 几个礼拜前电脑自带的记事本抽风,打开文本后台有进程但就是不显示界面,网上搜的教程无非是重装.杀毒.换包;这些操作要不就是太繁琐要不就是没效果,于是乎我物色了两款十分强大且轻量的开源记事本No ...
- SpringBoot-数据库连接信息配置
SpringBoot-数据库连接信息配置 SpringBoot-数据库连接信息配置 在SpringBoot中提供了默认的数据库连接器-追光者HikariCP,我们只需要添加jdbc的启动器就会自动 ...
- 安卓fragment transaction add方法报错
这个问题百度了很多能用的很少! 原来看的B站的视频教程比较老了参数不匹配!我记一下安卓studio3.1的方法 切换fragment 前都先要 FragmentManager manager=getS ...
- 官网英文版学习——RabbitMQ学习笔记(六)Routing
有选择的接收消息. 上一节我们使用的是fanout exchange来实现消息的发布/订阅模式,这并没有给我们带来多大的灵活性——它只能够让人盲目地进行广播.而本节我们采用direct类型的交换器来实 ...
- 【pwnable.kr】blackjack
又一道pwnable nc pwnable.kr 9009 读题找到源代码在:http://cboard.cprogramming.com/c-programming/114023-simple-bl ...
- ActiveMQ持久化机制和JMS可靠消息
1.ActiveMQ持久化机制 1.1 JDBC将数据持久化到数据库 1.2 AMQ生成日志文件 1.3 KahaDB:本次磁盘生成数据文件(默认) 1.4 LevelDB:谷歌K/V数据库 1.5 ...