Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
hanoi2005
redis
提交
ed0dd554
R
redis
项目概览
hanoi2005
/
redis
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
redis
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
ed0dd554
编写于
8月 30, 2010
作者:
P
Pieter Noordhuis
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Show the current throughput while benchmarking
上级
36babc1e
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
50 addition
and
36 deletion
+50
-36
src/redis-benchmark.c
src/redis-benchmark.c
+50
-36
未找到文件。
src/redis-benchmark.c
浏览文件 @
ed0dd554
...
...
@@ -75,6 +75,7 @@ static struct config {
long
long
start
;
long
long
totlatency
;
int
*
latency
;
char
*
title
;
list
*
clients
;
int
quiet
;
int
loop
;
...
...
@@ -389,13 +390,13 @@ static void createMissingClients(client c) {
}
}
static
void
showLatencyReport
(
char
*
title
)
{
static
void
showLatencyReport
(
void
)
{
int
j
,
seen
=
0
;
float
perc
,
reqpersec
;
reqpersec
=
(
float
)
config
.
donerequests
/
((
float
)
config
.
totlatency
/
1000
);
if
(
!
config
.
quiet
)
{
printf
(
"====== %s ======
\n
"
,
title
);
printf
(
"====== %s ======
\n
"
,
config
.
title
);
printf
(
" %d requests completed in %.2f seconds
\n
"
,
config
.
donerequests
,
(
float
)
config
.
totlatency
/
1000
);
printf
(
" %d parallel clients
\n
"
,
config
.
numclients
);
...
...
@@ -411,20 +412,20 @@ static void showLatencyReport(char *title) {
}
printf
(
"%.2f requests per second
\n\n
"
,
reqpersec
);
}
else
{
printf
(
"%s: %.2f requests per second
\n
"
,
title
,
reqpersec
);
printf
(
"%s: %.2f requests per second
\n
"
,
config
.
title
,
reqpersec
);
}
}
static
void
prepareForBenchmark
(
void
)
{
static
void
prepareForBenchmark
(
char
*
title
)
{
memset
(
config
.
latency
,
0
,
sizeof
(
int
)
*
(
MAX_LATENCY
+
1
));
config
.
title
=
title
;
config
.
start
=
mstime
();
config
.
donerequests
=
0
;
}
static
void
endBenchmark
(
char
*
title
)
{
static
void
endBenchmark
(
void
)
{
config
.
totlatency
=
mstime
()
-
config
.
start
;
showLatencyReport
(
title
);
showLatencyReport
();
freeAllClients
();
}
...
...
@@ -498,6 +499,18 @@ void parseOptions(int argc, char **argv) {
}
}
int
showThroughput
(
struct
aeEventLoop
*
eventLoop
,
long
long
id
,
void
*
clientData
)
{
REDIS_NOTUSED
(
eventLoop
);
REDIS_NOTUSED
(
id
);
REDIS_NOTUSED
(
clientData
);
float
dt
=
(
float
)(
mstime
()
-
config
.
start
)
/
1000
.
0
;
float
rps
=
(
float
)
config
.
donerequests
/
dt
;
printf
(
"%s: %.2f
\r
"
,
config
.
title
,
rps
);
fflush
(
stdout
);
return
250
;
/* every 250ms */
}
int
main
(
int
argc
,
char
**
argv
)
{
client
c
;
...
...
@@ -509,6 +522,7 @@ int main(int argc, char **argv) {
config
.
requests
=
10000
;
config
.
liveclients
=
0
;
config
.
el
=
aeCreateEventLoop
();
aeCreateTimeEvent
(
config
.
el
,
1
,
showThroughput
,
NULL
,
NULL
);
config
.
keepalive
=
1
;
config
.
donerequests
=
0
;
config
.
datasize
=
3
;
...
...
@@ -532,7 +546,7 @@ int main(int argc, char **argv) {
if
(
config
.
idlemode
)
{
printf
(
"Creating %d idle connections and waiting forever (Ctrl+C when done)
\n
"
,
config
.
numclients
);
prepareForBenchmark
();
prepareForBenchmark
(
"IDLE"
);
c
=
createClient
();
if
(
!
c
)
exit
(
1
);
c
->
obuf
=
sdsempty
();
...
...
@@ -543,25 +557,25 @@ int main(int argc, char **argv) {
}
do
{
prepareForBenchmark
();
prepareForBenchmark
(
"PING"
);
c
=
createClient
();
if
(
!
c
)
exit
(
1
);
c
->
obuf
=
sdscat
(
c
->
obuf
,
"PING
\r\n
"
);
prepareClientForReply
(
c
,
REPLY_RETCODE
);
createMissingClients
(
c
);
aeMain
(
config
.
el
);
endBenchmark
(
"PING"
);
endBenchmark
();
prepareForBenchmark
();
prepareForBenchmark
(
"PING (multi bulk)"
);
c
=
createClient
();
if
(
!
c
)
exit
(
1
);
c
->
obuf
=
sdscat
(
c
->
obuf
,
"*1
\r\n
$4
\r\n
PING
\r\n
"
);
prepareClientForReply
(
c
,
REPLY_RETCODE
);
createMissingClients
(
c
);
aeMain
(
config
.
el
);
endBenchmark
(
"PING (multi bulk)"
);
endBenchmark
();
prepareForBenchmark
();
prepareForBenchmark
(
"SET"
);
c
=
createClient
();
if
(
!
c
)
exit
(
1
);
c
->
obuf
=
sdscatprintf
(
c
->
obuf
,
"SET foo_rand000000000000 %d
\r\n
"
,
config
.
datasize
);
...
...
@@ -575,106 +589,106 @@ int main(int argc, char **argv) {
prepareClientForReply
(
c
,
REPLY_RETCODE
);
createMissingClients
(
c
);
aeMain
(
config
.
el
);
endBenchmark
(
"SET"
);
endBenchmark
();
prepareForBenchmark
();
prepareForBenchmark
(
"GET"
);
c
=
createClient
();
if
(
!
c
)
exit
(
1
);
c
->
obuf
=
sdscat
(
c
->
obuf
,
"GET foo_rand000000000000
\r\n
"
);
prepareClientForReply
(
c
,
REPLY_BULK
);
createMissingClients
(
c
);
aeMain
(
config
.
el
);
endBenchmark
(
"GET"
);
endBenchmark
();
prepareForBenchmark
();
prepareForBenchmark
(
"INCR"
);
c
=
createClient
();
if
(
!
c
)
exit
(
1
);
c
->
obuf
=
sdscat
(
c
->
obuf
,
"INCR counter_rand000000000000
\r\n
"
);
prepareClientForReply
(
c
,
REPLY_INT
);
createMissingClients
(
c
);
aeMain
(
config
.
el
);
endBenchmark
(
"INCR"
);
endBenchmark
();
prepareForBenchmark
();
prepareForBenchmark
(
"LPUSH"
);
c
=
createClient
();
if
(
!
c
)
exit
(
1
);
c
->
obuf
=
sdscat
(
c
->
obuf
,
"LPUSH mylist 3
\r\n
bar
\r\n
"
);
prepareClientForReply
(
c
,
REPLY_INT
);
createMissingClients
(
c
);
aeMain
(
config
.
el
);
endBenchmark
(
"LPUSH"
);
endBenchmark
();
prepareForBenchmark
();
prepareForBenchmark
(
"LPOP"
);
c
=
createClient
();
if
(
!
c
)
exit
(
1
);
c
->
obuf
=
sdscat
(
c
->
obuf
,
"LPOP mylist
\r\n
"
);
prepareClientForReply
(
c
,
REPLY_BULK
);
createMissingClients
(
c
);
aeMain
(
config
.
el
);
endBenchmark
(
"LPOP"
);
endBenchmark
();
prepareForBenchmark
();
prepareForBenchmark
(
"SADD"
);
c
=
createClient
();
if
(
!
c
)
exit
(
1
);
c
->
obuf
=
sdscat
(
c
->
obuf
,
"SADD myset 24
\r\n
counter_rand000000000000
\r\n
"
);
prepareClientForReply
(
c
,
REPLY_RETCODE
);
createMissingClients
(
c
);
aeMain
(
config
.
el
);
endBenchmark
(
"SADD"
);
endBenchmark
();
prepareForBenchmark
();
prepareForBenchmark
(
"SPOP"
);
c
=
createClient
();
if
(
!
c
)
exit
(
1
);
c
->
obuf
=
sdscat
(
c
->
obuf
,
"SPOP myset
\r\n
"
);
prepareClientForReply
(
c
,
REPLY_BULK
);
createMissingClients
(
c
);
aeMain
(
config
.
el
);
endBenchmark
(
"SPOP"
);
endBenchmark
();
prepareForBenchmark
();
prepareForBenchmark
(
"LPUSH (again, in order to bench LRANGE)"
);
c
=
createClient
();
if
(
!
c
)
exit
(
1
);
c
->
obuf
=
sdscat
(
c
->
obuf
,
"LPUSH mylist 3
\r\n
bar
\r\n
"
);
prepareClientForReply
(
c
,
REPLY_RETCODE
);
createMissingClients
(
c
);
aeMain
(
config
.
el
);
endBenchmark
(
"LPUSH (again, in order to bench LRANGE)"
);
endBenchmark
();
prepareForBenchmark
();
prepareForBenchmark
(
"LRANGE (first 100 elements)"
);
c
=
createClient
();
if
(
!
c
)
exit
(
1
);
c
->
obuf
=
sdscat
(
c
->
obuf
,
"LRANGE mylist 0 99
\r\n
"
);
prepareClientForReply
(
c
,
REPLY_MBULK
);
createMissingClients
(
c
);
aeMain
(
config
.
el
);
endBenchmark
(
"LRANGE (first 100 elements)"
);
endBenchmark
();
prepareForBenchmark
();
prepareForBenchmark
(
"LRANGE (first 300 elements)"
);
c
=
createClient
();
if
(
!
c
)
exit
(
1
);
c
->
obuf
=
sdscat
(
c
->
obuf
,
"LRANGE mylist 0 299
\r\n
"
);
prepareClientForReply
(
c
,
REPLY_MBULK
);
createMissingClients
(
c
);
aeMain
(
config
.
el
);
endBenchmark
(
"LRANGE (first 300 elements)"
);
endBenchmark
();
prepareForBenchmark
();
prepareForBenchmark
(
"LRANGE (first 450 elements)"
);
c
=
createClient
();
if
(
!
c
)
exit
(
1
);
c
->
obuf
=
sdscat
(
c
->
obuf
,
"LRANGE mylist 0 449
\r\n
"
);
prepareClientForReply
(
c
,
REPLY_MBULK
);
createMissingClients
(
c
);
aeMain
(
config
.
el
);
endBenchmark
(
"LRANGE (first 450 elements)"
);
endBenchmark
();
prepareForBenchmark
();
prepareForBenchmark
(
"LRANGE (first 600 elements)"
);
c
=
createClient
();
if
(
!
c
)
exit
(
1
);
c
->
obuf
=
sdscat
(
c
->
obuf
,
"LRANGE mylist 0 599
\r\n
"
);
prepareClientForReply
(
c
,
REPLY_MBULK
);
createMissingClients
(
c
);
aeMain
(
config
.
el
);
endBenchmark
(
"LRANGE (first 600 elements)"
);
endBenchmark
();
printf
(
"
\n
"
);
}
while
(
config
.
loop
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录