Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ruanhaishen
redis
Commits
1cd3c1e0
Commit
1cd3c1e0
authored
Dec 17, 2010
by
Pieter Noordhuis
Browse files
Use multi-bulk protocol by default in redis-benchmark
parent
174df6fe
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/redis-benchmark.c
View file @
1cd3c1e0
...
...
@@ -80,6 +80,7 @@ typedef struct _client {
redisContext
*
context
;
int
state
;
sds
obuf
;
char
*
randptr
;
unsigned
int
written
;
/* bytes of 'obuf' already written */
int
replytype
;
long
long
start
;
/* start time of a request */
...
...
@@ -145,16 +146,29 @@ static void resetClient(client c) {
}
static
void
randomizeClientKey
(
client
c
)
{
char
*
p
;
char
*
p
,
*
newline
;
char
buf
[
32
];
long
r
;
p
=
strstr
(
c
->
obuf
,
"_rand"
);
if
(
!
p
)
return
;
p
+=
5
;
if
(
c
->
randptr
==
NULL
)
return
;
/* Check if we have to randomize (only once per connection) */
if
(
c
->
randptr
==
(
void
*
)
-
1
)
{
p
=
strstr
(
c
->
obuf
,
":rand:"
);
if
(
!
p
)
{
c
->
randptr
=
NULL
;
return
;
}
else
{
newline
=
strstr
(
p
,
"
\r\n
"
);
assert
(
newline
-
(
p
+
6
)
==
12
);
/* 12 chars for randomness */
c
->
randptr
=
p
+
6
;
}
}
/* Set random number in output buffer */
r
=
random
()
%
config
.
randomkeys_keyspacelen
;
sprintf
(
buf
,
"%
ld"
,
r
);
memcpy
(
p
,
buf
,
strlen
(
buf
)
);
s
n
printf
(
buf
,
sizeof
(
buf
),
"%012
ld"
,
r
);
memcpy
(
c
->
randptr
,
buf
,
12
);
}
static
void
clientDone
(
client
c
)
{
...
...
@@ -253,7 +267,8 @@ static client createClient(int replytype) {
}
c
->
replytype
=
replytype
;
c
->
state
=
CLIENT_CONNECTING
;
c
->
obuf
=
sdsempty
();
c
->
obuf
=
NULL
;
c
->
randptr
=
(
void
*
)
-
1
;
c
->
written
=
0
;
redisSetReplyObjectFunctions
(
c
->
context
,
NULL
);
aeCreateFileEvent
(
config
.
el
,
c
->
context
->
fd
,
AE_WRITABLE
,
writeHandler
,
c
);
...
...
@@ -265,7 +280,6 @@ static client createClient(int replytype) {
static
void
createMissingClients
(
client
c
)
{
while
(
config
.
liveclients
<
config
.
numclients
)
{
client
new
=
createClient
(
c
->
replytype
);
sdsfree
(
new
->
obuf
);
new
->
obuf
=
sdsdup
(
c
->
obuf
);
if
(
config
.
randomkeys
)
randomizeClientKey
(
c
);
}
...
...
@@ -441,114 +455,148 @@ int main(int argc, char **argv) {
}
do
{
char
*
data
=
zmalloc
(
config
.
datasize
+
1
);
char
*
data
,
*
cmd
;
int
len
;
data
=
zmalloc
(
config
.
datasize
+
1
);
memset
(
data
,
'x'
,
config
.
datasize
);
data
[
config
.
datasize
]
=
'\0'
;
prepareForBenchmark
(
"PING"
);
prepareForBenchmark
(
"PING
(inline)
"
);
c
=
createClient
(
REDIS_REPLY_STATUS
);
c
->
obuf
=
sdscat
(
c
->
obuf
,
"PING
\r\n
"
);
c
->
obuf
=
sdscat
(
sdsempty
()
,
"PING
\r\n
"
);
createMissingClients
(
c
);
aeMain
(
config
.
el
);
endBenchmark
();
prepareForBenchmark
(
"PING
(multi bulk)
"
);
prepareForBenchmark
(
"PING"
);
c
=
createClient
(
REDIS_REPLY_STATUS
);
c
->
obuf
=
sdscat
(
c
->
obuf
,
"*1
\r\n
$4
\r\n
PING
\r\n
"
);
len
=
redisFormatCommand
(
&
cmd
,
"PING"
);
c
->
obuf
=
sdsnewlen
(
cmd
,
len
);
free
(
cmd
);
createMissingClients
(
c
);
aeMain
(
config
.
el
);
endBenchmark
();
prepareForBenchmark
(
"MSET (10 keys
, multi bulk
)"
);
prepareForBenchmark
(
"MSET (10 keys)"
);
c
=
createClient
(
REDIS_REPLY_ARRAY
);
c
->
obuf
=
sdscatprintf
(
c
->
obuf
,
"*%d
\r\n
$4
\r\n
MSET
\r\n
"
,
11
);
for
(
i
=
0
;
i
<
10
;
i
++
)
{
c
->
obuf
=
sdscatprintf
(
c
->
obuf
,
"$%d
\r\n
%s
\r\n
"
,
config
.
datasize
,
data
);
{
const
char
*
argv
[
11
];
argv
[
0
]
=
"MSET"
;
for
(
i
=
1
;
i
<
11
;
i
++
)
argv
[
i
]
=
data
;
len
=
redisFormatCommandArgv
(
&
cmd
,
11
,
argv
,
NULL
);
c
->
obuf
=
sdsnewlen
(
cmd
,
len
);
free
(
cmd
);
}
createMissingClients
(
c
);
aeMain
(
config
.
el
);
endBenchmark
();
prepareForBenchmark
(
"SET"
);
c
=
createClient
(
REDIS_REPLY_STATUS
);
c
->
obuf
=
sdscat
(
c
->
obuf
,
"*3
\r\n
$3
\r\n
SET
\r\n
$20
\r\n
foo_rand000000000000
\r\n
"
);
c
->
obuf
=
sdscatprintf
(
c
->
obuf
,
"$%d
\r\n
%s
\r\n
"
,
config
.
datasize
,
data
);
len
=
redisFormatCommand
(
&
cmd
,
"SET foo:rand:000000000000 %s"
,
data
);
c
->
obuf
=
sdsnewlen
(
cmd
,
len
);
free
(
cmd
);
createMissingClients
(
c
);
aeMain
(
config
.
el
);
endBenchmark
();
prepareForBenchmark
(
"GET"
);
c
=
createClient
(
REDIS_REPLY_STRING
);
c
->
obuf
=
sdscat
(
c
->
obuf
,
"GET foo_rand000000000000
\r\n
"
);
len
=
redisFormatCommand
(
&
cmd
,
"GET foo:rand:000000000000"
);
c
->
obuf
=
sdsnewlen
(
cmd
,
len
);
free
(
cmd
);
createMissingClients
(
c
);
aeMain
(
config
.
el
);
endBenchmark
();
prepareForBenchmark
(
"INCR"
);
c
=
createClient
(
REDIS_REPLY_INTEGER
);
c
->
obuf
=
sdscat
(
c
->
obuf
,
"INCR counter_rand000000000000
\r\n
"
);
len
=
redisFormatCommand
(
&
cmd
,
"INCR counter:rand:000000000000"
);
c
->
obuf
=
sdsnewlen
(
cmd
,
len
);
free
(
cmd
);
createMissingClients
(
c
);
aeMain
(
config
.
el
);
endBenchmark
();
prepareForBenchmark
(
"LPUSH"
);
c
=
createClient
(
REDIS_REPLY_INTEGER
);
c
->
obuf
=
sdscat
(
c
->
obuf
,
"LPUSH mylist bar
\r\n
"
);
len
=
redisFormatCommand
(
&
cmd
,
"LPUSH mylist %s"
,
data
);
c
->
obuf
=
sdsnewlen
(
cmd
,
len
);
free
(
cmd
);
createMissingClients
(
c
);
aeMain
(
config
.
el
);
endBenchmark
();
prepareForBenchmark
(
"LPOP"
);
c
=
createClient
(
REDIS_REPLY_STRING
);
c
->
obuf
=
sdscat
(
c
->
obuf
,
"LPOP mylist
\r\n
"
);
len
=
redisFormatCommand
(
&
cmd
,
"LPOP mylist"
);
c
->
obuf
=
sdsnewlen
(
cmd
,
len
);
free
(
cmd
);
createMissingClients
(
c
);
aeMain
(
config
.
el
);
endBenchmark
();
prepareForBenchmark
(
"SADD"
);
c
=
createClient
(
REDIS_REPLY_STATUS
);
c
->
obuf
=
sdscat
(
c
->
obuf
,
"SADD myset counter_rand000000000000
\r\n
"
);
len
=
redisFormatCommand
(
&
cmd
,
"SADD myset counter:rand:000000000000"
);
c
->
obuf
=
sdsnewlen
(
cmd
,
len
);
free
(
cmd
);
createMissingClients
(
c
);
aeMain
(
config
.
el
);
endBenchmark
();
prepareForBenchmark
(
"SPOP"
);
c
=
createClient
(
REDIS_REPLY_STRING
);
c
->
obuf
=
sdscat
(
c
->
obuf
,
"SPOP myset
\r\n
"
);
len
=
redisFormatCommand
(
&
cmd
,
"SPOP myset"
);
c
->
obuf
=
sdsnewlen
(
cmd
,
len
);
free
(
cmd
);
createMissingClients
(
c
);
aeMain
(
config
.
el
);
endBenchmark
();
prepareForBenchmark
(
"LPUSH (again, in order to bench LRANGE)"
);
c
=
createClient
(
REDIS_REPLY_STATUS
);
c
->
obuf
=
sdscat
(
c
->
obuf
,
"LPUSH mylist bar
\r\n
"
);
len
=
redisFormatCommand
(
&
cmd
,
"LPUSH mylist %s"
,
data
);
c
->
obuf
=
sdsnewlen
(
cmd
,
len
);
free
(
cmd
);
createMissingClients
(
c
);
aeMain
(
config
.
el
);
endBenchmark
();
prepareForBenchmark
(
"LRANGE (first 100 elements)"
);
c
=
createClient
(
REDIS_REPLY_ARRAY
);
c
->
obuf
=
sdscat
(
c
->
obuf
,
"LRANGE mylist 0 99
\r\n
"
);
len
=
redisFormatCommand
(
&
cmd
,
"LRANGE mylist 0 99"
);
c
->
obuf
=
sdsnewlen
(
cmd
,
len
);
free
(
cmd
);
createMissingClients
(
c
);
aeMain
(
config
.
el
);
endBenchmark
();
prepareForBenchmark
(
"LRANGE (first 300 elements)"
);
c
=
createClient
(
REDIS_REPLY_ARRAY
);
c
->
obuf
=
sdscat
(
c
->
obuf
,
"LRANGE mylist 0 299
\r\n
"
);
len
=
redisFormatCommand
(
&
cmd
,
"LRANGE mylist 0 299"
);
c
->
obuf
=
sdsnewlen
(
cmd
,
len
);
free
(
cmd
);
createMissingClients
(
c
);
aeMain
(
config
.
el
);
endBenchmark
();
prepareForBenchmark
(
"LRANGE (first 450 elements)"
);
c
=
createClient
(
REDIS_REPLY_ARRAY
);
c
->
obuf
=
sdscat
(
c
->
obuf
,
"LRANGE mylist 0 449
\r\n
"
);
len
=
redisFormatCommand
(
&
cmd
,
"LRANGE mylist 0 449"
);
c
->
obuf
=
sdsnewlen
(
cmd
,
len
);
free
(
cmd
);
createMissingClients
(
c
);
aeMain
(
config
.
el
);
endBenchmark
();
prepareForBenchmark
(
"LRANGE (first 600 elements)"
);
c
=
createClient
(
REDIS_REPLY_ARRAY
);
c
->
obuf
=
sdscat
(
c
->
obuf
,
"LRANGE mylist 0 599
\r\n
"
);
len
=
redisFormatCommand
(
&
cmd
,
"LRANGE mylist 0 599"
);
c
->
obuf
=
sdsnewlen
(
cmd
,
len
);
free
(
cmd
);
createMissingClients
(
c
);
aeMain
(
config
.
el
);
endBenchmark
();
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment