设为首页 加入收藏

TOP

redis翻译_redis管道(二)
2015-11-21 01:41:44 来源: 作者: 【 】 浏览:4
Tags:redis 翻译 _redis 管道
ur very first example will be the following:
显然,pipelining 的操作过程是这样的:
Client: INCR X
Client: INCR X
Client: INCR X
Client: INCR X
Server: 1
Server: 2
Server: 3
Server: 4 IMPORTANT NOTE:While the client sends commands using pipelining, the server will be forced to queue the replies, using memory. So if you need to send a lot of commands with pipelining, it is better to send them as batches having a reasonable number, for instance 10k commands, read the replies, and then send another 10k commands again, and so forth. The speed will be nearly the same, but the additional memory used will be at max the amount needed to queue the replies for this 10k commands.
当client使用pipelining发生一些命令时,redis server将使用内存为应答创建一个队列。因此你使用pipelining发生很多命令,一个好的做法是,合理地批量发送,比如,10k一个批次,得到返回后在发生10k。速度大概是一样的,但是redis server为了这个10k的命令要花费内存去创建应答队列。

Some benchmark

In the following benchmark we'll use the Redis Ruby client, supporting pipelining, to test the speed improvement due to pipelining:
下面是使用ruby支持pipelining客户端的例子:
require 'rubygems'
require 'redis'

def bench(descr)
    start = Time.now
    yield
    puts "#{descr} #{Time.now-start} seconds"
end

def without_pipelining
    r = Redis.new
    10000.times {
        r.ping
    }
end

def with_pipelining
    r = Redis.new
    r.pipelined {
        10000.times {
            r.ping
        }
    }
end

bench("without pipelining") {
    without_pipelining
}
bench("with pipelining") {
    with_pipelining
}
Running the above simple script will provide the following figures in my Mac OS X system, running over the loopback interface, where pipelining will provide the smallest improvement as the RTT is already pretty low:
在mac os x上运行上面的脚步,和没有使用pipelining 运行的比较如下:
without pipelining 1.185238 seconds
with pipelining 0.250783 seconds
As you can see, using pipelining, we improved the transfer by a factor of five.
可以发现,使用pipelining传输速度提升了5倍

?

Pipelining VS Scripting

Using Redis scripting (available in Redis version 2.6 or greater) a number of use cases for pipelining can be addressed more efficiently using scripts that perform a lot of the work needed at the server side. A big advantage of scripting is that it is able to both read and write data with minimal latency, making operations like read, compute, write very fast (pipelining can't help in this scenario since the client needs the reply of the read command before it can call the write command).
大量的实验证明,为pipelining 使用脚步可以在服务端处理更多的工作。一个大优点是,使用脚步可以让读和写延迟小,使得读、写、计算变得很快(在客户端需要收到返回才发送命令的情况时,pipelining 是不能满足的) Sometimes the application may also want to send eva l or eva lSHA commands in a pipeline. This is entirely possible and Redis explicitly supports it with the SCRIPT LOAD command (it guarantees that eva lSHA can be called without the risk of failing).
一些应用可能想在pipeline里发生eva l 或者eva lSHA命令。使用SCRIOT LOAD命令是完全支持的(它保证执行没有失败的风险)

首页 上一页 1 2 下一页 尾页 2/2/2
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇关于数据库篇 下一篇rhel5.8ISOyum源配置

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: