3月 282016
 

脚本:

 

阿里云的1G标准的redis,当同时40个这样的PHP进程压测的话,会有8个进程最终出现select时 1s 超时异常; 但是人家给的指标是支持 300并发的

 Posted by at 下午 3:25
9月 102014
 

示例代码:

 输出:

 Posted by at 下午 7:24
7月 212013
 

 

1. redis的lru的使用

其中:

这个赋值是怎么体现lru的工作机制的?

 

2. 按照下面的调用过程来看redis对每个命令的处理过程:

至于redis协议中的每条指定对应server端的那一个函数,不会看到一个if..else.. 或者 switch结构的, 从 redisCommandTable 中来找就足够了(当然,quit命令找不到,似乎也只有quit命令)

 

3. 今天还了解一下细节

1) key和value都是作为redis的object来存储的,相同的value是重复使用的

2) 过期机制是通过将要过期的key写到一个过期table中来做的,这个是和memcache不同的

4. redis是支持认证机制的,当然,这样会多一次请求,而且认证请求不能和其它请求一起打包执行的

 

5. 关于Redis的LRU:

Redis的LRU是不精确的,不是在allkey中LRU的,而是在allkey中随机选取 maxmemory-samples 来LRU的,这一点要考虑一下是否满足需求。

redis_lru

 

(了解一下概率的计算方法吧)

摘录: http://oldblog.antirez.com/post/redis-as-LRU-cache.html

maxmemory-samples number_of_samples

The last config option is used to tune the algorithms precision. In order to save memory Redis just adds a 22 bits field to every object for LRU. When we need to remove a key we sample N keys, and remove the one that was idle for longer time. For default three keys are sampled, that is a reasonable approximation of LRU in the long run, but you can get more precision at the cost of some more CPU time changing the number of keys to sample.

Redis 2.2 的配置文件关于LRU的相关说明:

 

 Posted by at 上午 12:45
5月 052013
 

 

下载window版本redis:

https://github.com/dmajkic/redis

windows上让redis作为服务启动:

https://github.com/kcherenkov/redis-windows-service  可以直接下载里面编译好的二进制文件

下载retwis:

http://redis.googlecode.com/files/retwis-0.3.tar.gz   这个包中的redis协议不是最新的,可在下面地址下载:

http://phpor.net/download/retwis.zip

 

参考文档:

http://blog.csdn.net/archimedes_zht/article/details/6892511

 Posted by at 下午 5:29
11月 182012
 

关于keys命令

为什么使用keys命令遍历所有key不可取?

1. 相对于其他操作来讲,遍历所有key是一个耗时的操作

2. redis是一个单线程的程序,一个操作的阻塞,就会影响其他操作的执行

3. keys操作并不是匹配一个就输出一个的,而是都匹配出来之后才输出的;虽然没有copy每个匹配到的key,也就是说没有占用额外的服务器的内存,但是:

如果client端允许一边接收一边处理的话,则势必阻塞server端的操作;如果client端接收完再操作,则可能会消耗很多client端的内存。如果可以的话,大数据量似乎只能先暂存到磁盘了。

从根本上来讲,这似乎是redis的单线程机制造成的。

 Posted by at 下午 10:59