golang - Redis best drive of the Go language

Redis can cache data, data which enables the operator to achieve a faster rate, in some applications requiring fast data storage, such as Twitter, Redis plays an irreplaceable role. In the official website of redis, golang drive a few, suddenly got into high spirits, that is the best Go redis language driver?

These drivers are in early development, but also not released the official version, and some have not updated for a long time. Updated from the point of view, Gary Burd's radigo and gosexy of redis recent update, but from their point of view the README file, their support for the redis pretty good. Most likely, they both have one win. But in the end who is the best, this is now still can not judge. There is in gosexy of redis source library _benchmarks files, which are some of the various redis Go drive of some simple performance tests. Simply looked at, which is the code calls the function of their respective package to achieve the test function. We may wish to look at. Here you pass this test, simply look at who is the best judge.

First, install the driver of each Go:

go get github.com/alphazero/Go-Redis
go get github.com/simonz05/godis
go get github.com/garyburd/redigo
go get github.com/gosexy/redis
go get cgl.tideland.biz/redis

Note : tcgl originally hosted on google, but now it is now set themselves up as the source library, redis of gosexy of _benchmarks of tcgl_redis_test.go to import a google version, but now changed. That is commented out code.google.com/p/tcgl/redis, add cgl.tideland.biz/redis, so that we can carry out the next move.

Redis open in a terminal:

redis-server

We want to enter _benchmarks this folder, there are steps inside README.md performance testing, performance testing operation to be performed here have Ping, Set, Get, Incr, LPush, LRange10, LRange100, which are LRange10 and LRange100 call LRange operation, but their number is different. Here's what I have done in these folders inside.

Open a new terminal:

go test -test.bench='.*' > redis-go-driver-benchmark.txt
./grep_data.sh

grep_data is a script I wrote:

#!/bin/sh
for i in AlphazeroRedis GaryburdRedigo GosexyRedis Simonz05Godis TcglRedis 
do
    grep $i redis-go-driver-benchmark.txt  | awk '{print $3}' > $i
done

The role of the script is to AlphazeroRedis, GaryburdRedigo, GosexyRedis, Simonz05Godis, TcglRedis and other test data is extracted from the redis-go-driver-benchmark.txt out, that is, the data of their respective operations, then write in their name to a file inside . We can open AlphazeroRedis look,

39001
43967
43459
43350
44249
58078
139603

These data sequence corresponding to Ping, Set, Get, nanosecond time Incr, LPush, LRange10, LRange100 required for each operation. I wrote a small program to the R display the data to a chart above, the R is not very familiar with, want to know Daniel R of correction. On the following codes:

png(filename="redis的最佳go语言驱动--使用格通测试的数据.png",width=1400, height=900)
Sys.setlocale(, "zh_CN.UTF-8")
oldpar <- par(lwd=4)
AlphazeroRedis <- read.table("AlphazeroRedis")
GaryburdRedigo <- read.table("GaryburdRedigo")
GosexyRedis <- read.table("GosexyRedis")
Simonz05Godis <- read.table("Simonz05Godis")
TcglRedis <- read.table("TcglRedis")
plot(AlphazeroRedis$V1, type="o", ylim = c(0, 360000), col = "black", axes=FALSE, ann=FALSE)
text(2, AlphazeroRedis$V1[2], cex=2, pos=3, col="black", "AlphazeroRedis")
axis(1, at=1:8, lab=c("Ping","Set","Get","Incr", "LPush", "LRange10", "LRange100", ""))
axis(2, las=0, at=40000*0: 360000)
box()
title(xlab="操作", col = "black")
title(ylab="每个操作多少纳秒", col = "black")
title(main = "5个Redis的Go语言驱动操作比较--使用格通测试的数据")
lines(GaryburdRedigo, col = "red")
text(6, GaryburdRedigo$V1[6]-10000, cex=2, pos=1, col="red", "GaryburdRedigo")
lines(GosexyRedis, col = "blue")
text(2, GosexyRedis$V1[2], pos=1,col="blue", cex=2, "GosexyRedis")
lines(Simonz05Godis, col = "yellow")
text(4, Simonz05Godis$V1[4]+7000,pos=3, col="yellow",cex=2, "Simonz05Godis")
lines(TcglRedis, col = "gray")
text(3, TcglRedis$V1[3],pos=1,cex=2, col="gray", "TcglRedis")
par(oldpar)
dev.off()

Save as a go-redis-getongs-data.R, with R to call this file:

$R
>source("go-redis-getongs-data.R")

In the following will generate a directory called "redis best go language driver - data grid through the use of test .png" file, I deliberately to enlarge the map so that you can clearly see the trend lines, drawing a little big, may here is displayed incorrectly:

In _benchmarks data gosexy tested README.md, I modified the above go-redis-getongs-data.R file, the finishing gosexy test data on the chart:

2 can be seen, tcgl 5 is undoubtedly the most time-consuming. In the data I tested, GosexyRedis won almost all tests (except LRange100 lost GaryburdRedigo), GaryburdRedigo basically ranked second child. Gosexy use of data, in addition to tcgl, the other four data less, but still won the LRange100 GaryburdRedigo test, explained in terms of the number of relatively large list, GaryburdRedigo is very advantageous.

From the above data can be known, set, get, incr, lpush operation takes in about 40 microseconds, which is able to operate inside 1s about 25,000 times. I figured, startled, as if an order of magnitude higher than the other use cases (the wrong correct me hope).

Redis above test involves only part of the operation, in terms of overall support for redis, or the need to continue to add other functional tests. Go now began to develop after all, need to continue to build. After reading you can test yourself.

Posted please specify from: Advisa

Reproduced in: https: //my.oschina.net/u/191928/blog/618619

Guess you like

Origin blog.csdn.net/weixin_33912246/article/details/91987015