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
ecfaf6da
Commit
ecfaf6da
authored
May 11, 2009
by
antirez
Browse files
benchmark utility now supports random keys
parent
391b4a60
Changes
1
Hide whitespace changes
Inline
Side-by-side
benchmark.c
View file @
ecfaf6da
...
@@ -63,6 +63,7 @@ static struct config {
...
@@ -63,6 +63,7 @@ static struct config {
int
keysize
;
int
keysize
;
int
datasize
;
int
datasize
;
int
randomkeys
;
int
randomkeys
;
int
randomkeys_keyspacelen
;
aeEventLoop
*
el
;
aeEventLoop
*
el
;
char
*
hostip
;
char
*
hostip
;
int
hostport
;
int
hostport
;
...
@@ -138,6 +139,19 @@ static void resetClient(client c) {
...
@@ -138,6 +139,19 @@ static void resetClient(client c) {
c
->
start
=
mstime
();
c
->
start
=
mstime
();
}
}
static
void
randomizeClientKey
(
client
c
)
{
char
*
p
;
char
buf
[
32
];
long
r
;
p
=
strstr
(
c
->
obuf
,
"_rand"
);
if
(
!
p
)
return
;
p
+=
5
;
r
=
random
()
%
config
.
randomkeys_keyspacelen
;
sprintf
(
buf
,
"%ld"
,
r
);
memcpy
(
p
,
buf
,
strlen
(
buf
));
}
static
void
clientDone
(
client
c
)
{
static
void
clientDone
(
client
c
)
{
long
long
latency
;
long
long
latency
;
config
.
donerequests
++
;
config
.
donerequests
++
;
...
@@ -152,6 +166,7 @@ static void clientDone(client c) {
...
@@ -152,6 +166,7 @@ static void clientDone(client c) {
}
}
if
(
config
.
keepalive
)
{
if
(
config
.
keepalive
)
{
resetClient
(
c
);
resetClient
(
c
);
if
(
config
.
randomkeys
)
randomizeClientKey
(
c
);
}
else
{
}
else
{
config
.
liveclients
--
;
config
.
liveclients
--
;
createMissingClients
(
c
);
createMissingClients
(
c
);
...
@@ -192,7 +207,7 @@ static void readHandler(aeEventLoop *el, int fd, void *privdata, int mask)
...
@@ -192,7 +207,7 @@ static void readHandler(aeEventLoop *el, int fd, void *privdata, int mask)
*
p
=
'\0'
;
*
p
=
'\0'
;
*
(
p
-
1
)
=
'\0'
;
*
(
p
-
1
)
=
'\0'
;
c
->
readlen
=
atoi
(
c
->
ibuf
+
1
)
+
2
;
c
->
readlen
=
atoi
(
c
->
ibuf
+
1
)
+
2
;
if
(
c
->
readlen
==
-
1
)
{
if
(
c
->
readlen
-
2
==
-
1
)
{
clientDone
(
c
);
clientDone
(
c
);
return
;
return
;
}
}
...
@@ -266,6 +281,7 @@ static void createMissingClients(client c) {
...
@@ -266,6 +281,7 @@ static void createMissingClients(client c) {
if
(
!
new
)
continue
;
if
(
!
new
)
continue
;
sdsfree
(
new
->
obuf
);
sdsfree
(
new
->
obuf
);
new
->
obuf
=
sdsdup
(
c
->
obuf
);
new
->
obuf
=
sdsdup
(
c
->
obuf
);
if
(
config
.
randomkeys
)
randomizeClientKey
(
c
);
new
->
replytype
=
c
->
replytype
;
new
->
replytype
=
c
->
replytype
;
if
(
c
->
replytype
==
REPLY_BULK
)
if
(
c
->
replytype
==
REPLY_BULK
)
new
->
readlen
=
-
1
;
new
->
readlen
=
-
1
;
...
@@ -342,8 +358,12 @@ void parseOptions(int argc, char **argv) {
...
@@ -342,8 +358,12 @@ void parseOptions(int argc, char **argv) {
i
++
;
i
++
;
if
(
config
.
datasize
<
1
)
config
.
datasize
=
1
;
if
(
config
.
datasize
<
1
)
config
.
datasize
=
1
;
if
(
config
.
datasize
>
1024
*
1024
)
config
.
datasize
=
1024
*
1024
;
if
(
config
.
datasize
>
1024
*
1024
)
config
.
datasize
=
1024
*
1024
;
}
else
if
(
!
strcmp
(
argv
[
i
],
"-r"
))
{
}
else
if
(
!
strcmp
(
argv
[
i
],
"-r"
)
&&
!
lastarg
)
{
config
.
randomkeys
=
1
;
config
.
randomkeys
=
1
;
config
.
randomkeys_keyspacelen
=
atoi
(
argv
[
i
+
1
]);
if
(
config
.
randomkeys_keyspacelen
<
0
)
config
.
randomkeys_keyspacelen
=
0
;
i
++
;
}
else
if
(
!
strcmp
(
argv
[
i
],
"-q"
))
{
}
else
if
(
!
strcmp
(
argv
[
i
],
"-q"
))
{
config
.
quiet
=
1
;
config
.
quiet
=
1
;
}
else
if
(
!
strcmp
(
argv
[
i
],
"-l"
))
{
}
else
if
(
!
strcmp
(
argv
[
i
],
"-l"
))
{
...
@@ -357,7 +377,13 @@ void parseOptions(int argc, char **argv) {
...
@@ -357,7 +377,13 @@ void parseOptions(int argc, char **argv) {
printf
(
" -n <requests> Total number of requests (default 10000)
\n
"
);
printf
(
" -n <requests> Total number of requests (default 10000)
\n
"
);
printf
(
" -d <size> Data size of SET/GET value in bytes (default 2)
\n
"
);
printf
(
" -d <size> Data size of SET/GET value in bytes (default 2)
\n
"
);
printf
(
" -k <boolean> 1=keep alive 0=reconnect (default 1)
\n
"
);
printf
(
" -k <boolean> 1=keep alive 0=reconnect (default 1)
\n
"
);
printf
(
" -r Use random keys for SET/GET/INCR
\n
"
);
printf
(
" -r <keyspacelen> Use random keys for SET/GET/INCR
\n
"
);
printf
(
" Using this option the benchmark will get/set keys
\n
"
);
printf
(
" in the form mykey_rand000000012456 instead of constant
\n
"
);
printf
(
" keys, the <keyspacelen> argument determines the max
\n
"
);
printf
(
" number of values for the random number. For instance
\n
"
);
printf
(
" if set to 10 only rand000000000000 - rand000000000009
\n
"
);
printf
(
" range will be allowed.
\n
"
);
printf
(
" -q Quiet. Just show query/sec values
\n
"
);
printf
(
" -q Quiet. Just show query/sec values
\n
"
);
printf
(
" -l Loop. Run the tests forever
\n
"
);
printf
(
" -l Loop. Run the tests forever
\n
"
);
exit
(
1
);
exit
(
1
);
...
@@ -379,6 +405,7 @@ int main(int argc, char **argv) {
...
@@ -379,6 +405,7 @@ int main(int argc, char **argv) {
config
.
donerequests
=
0
;
config
.
donerequests
=
0
;
config
.
datasize
=
3
;
config
.
datasize
=
3
;
config
.
randomkeys
=
0
;
config
.
randomkeys
=
0
;
config
.
randomkeys_keyspacelen
=
0
;
config
.
quiet
=
0
;
config
.
quiet
=
0
;
config
.
loop
=
0
;
config
.
loop
=
0
;
config
.
latency
=
NULL
;
config
.
latency
=
NULL
;
...
...
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