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
84d6ce4f
Unverified
Commit
84d6ce4f
authored
Mar 13, 2019
by
Salvatore Sanfilippo
Committed by
GitHub
Mar 13, 2019
Browse files
Merge pull request #5901 from artix75/bm_threads_cluster_dev
Redis Benchmark: add multithread idle mode
parents
53d1dc17
5284d67e
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/redis-benchmark.c
View file @
84d6ce4f
...
@@ -247,11 +247,11 @@ static redisConfig *getRedisConfig(const char *ip, int port,
...
@@ -247,11 +247,11 @@ static redisConfig *getRedisConfig(const char *ip, int port,
c
=
redisConnect
(
ip
,
port
);
c
=
redisConnect
(
ip
,
port
);
else
else
c
=
redisConnectUnix
(
hostsocket
);
c
=
redisConnectUnix
(
hostsocket
);
if
(
c
->
err
)
{
if
(
c
==
NULL
||
c
->
err
)
{
fprintf
(
stderr
,
"Could not connect to Redis at "
);
fprintf
(
stderr
,
"Could not connect to Redis at "
);
if
(
hostsocket
==
NULL
)
char
*
err
=
(
c
!=
NULL
?
c
->
errstr
:
""
);
fprintf
(
stderr
,
"%s:%d: %s
\n
"
,
ip
,
port
,
c
->
errst
r
);
if
(
hostsocket
==
NULL
)
fprintf
(
stderr
,
"%s:%d: %s
\n
"
,
ip
,
port
,
er
r
);
else
fprintf
(
stderr
,
"%s: %s
\n
"
,
hostsocket
,
c
->
errst
r
);
else
fprintf
(
stderr
,
"%s: %s
\n
"
,
hostsocket
,
er
r
);
goto
fail
;
goto
fail
;
}
}
redisAppendCommand
(
c
,
"CONFIG GET %s"
,
"save"
);
redisAppendCommand
(
c
,
"CONFIG GET %s"
,
"save"
);
...
@@ -276,18 +276,16 @@ static redisConfig *getRedisConfig(const char *ip, int port,
...
@@ -276,18 +276,16 @@ static redisConfig *getRedisConfig(const char *ip, int port,
case
1
:
cfg
->
appendonly
=
sdsnew
(
value
);
break
;
case
1
:
cfg
->
appendonly
=
sdsnew
(
value
);
break
;
}
}
}
}
if
(
reply
)
freeReplyObject
(
reply
);
freeReplyObject
(
reply
);
if
(
c
)
redisFree
(
c
);
redisFree
(
c
);
return
cfg
;
return
cfg
;
fail:
fail:
if
(
reply
)
freeReplyObject
(
reply
);
if
(
c
)
redisFree
(
c
);
zfree
(
cfg
);
fprintf
(
stderr
,
"ERROR: failed to fetch CONFIG from "
);
fprintf
(
stderr
,
"ERROR: failed to fetch CONFIG from "
);
if
(
c
->
connection_type
==
REDIS_CONN_TCP
)
if
(
hostsocket
==
NULL
)
fprintf
(
stderr
,
"%s:%d
\n
"
,
ip
,
port
);
fprintf
(
stderr
,
"%s:%d
\n
"
,
c
->
tcp
.
host
,
c
->
tcp
.
port
);
else
fprintf
(
stderr
,
"%s
\n
"
,
hostsocket
);
else
if
(
c
->
connection_type
==
REDIS_CONN_UNIX
)
freeReplyObject
(
reply
);
fprintf
(
stderr
,
"%s
\n
"
,
c
->
unix_sock
.
path
);
redisFree
(
c
);
zfree
(
cfg
);
return
NULL
;
return
NULL
;
}
}
static
void
freeRedisConfig
(
redisConfig
*
cfg
)
{
static
void
freeRedisConfig
(
redisConfig
*
cfg
)
{
...
@@ -345,7 +343,9 @@ static void randomizeClientKey(client c) {
...
@@ -345,7 +343,9 @@ static void randomizeClientKey(client c) {
for
(
i
=
0
;
i
<
c
->
randlen
;
i
++
)
{
for
(
i
=
0
;
i
<
c
->
randlen
;
i
++
)
{
char
*
p
=
c
->
randptr
[
i
]
+
11
;
char
*
p
=
c
->
randptr
[
i
]
+
11
;
size_t
r
=
random
()
%
config
.
randomkeys_keyspacelen
;
size_t
r
=
0
;
if
(
config
.
randomkeys_keyspacelen
!=
0
)
r
=
random
()
%
config
.
randomkeys_keyspacelen
;
size_t
j
;
size_t
j
;
for
(
j
=
0
;
j
<
12
;
j
++
)
{
for
(
j
=
0
;
j
<
12
;
j
++
)
{
...
@@ -447,27 +447,27 @@ static void readHandler(aeEventLoop *el, int fd, void *privdata, int mask) {
...
@@ -447,27 +447,27 @@ static void readHandler(aeEventLoop *el, int fd, void *privdata, int mask) {
}
}
}
}
if
(
config
.
cluster_mode
&&
is_err
&&
c
->
cluster_node
&&
/* Try to update slots configuration if reply error is
(
!
strncmp
(
r
->
str
,
"MOVED"
,
5
)
||
* MOVED/ASK/CLUSTERDOWN and the key(s) used by the command
!
strcmp
(
r
->
str
,
"ASK"
)))
* contain(s) the slot hash tag. */
{
if
(
is_err
&&
c
->
cluster_node
&&
c
->
staglen
)
{
/* Try to update slots configuration if the key of the
int
fetch_slots
=
0
,
do_wait
=
0
;
* command is using the slot hash tag. */
if
(
!
strncmp
(
r
->
str
,
"MOVED"
,
5
)
||
!
strncmp
(
r
->
str
,
"ASK"
,
3
))
if
(
c
->
staglen
&&
!
fetchClusterSlotsConfiguration
(
c
))
fetch_slots
=
1
;
exit
(
1
);
else
if
(
!
strncmp
(
r
->
str
,
"CLUSTERDOWN"
,
11
))
{
/*
/* Usually the cluster is able to recover itself after
clusterNode *node = c->cluster_node;
* a CLUSTERDOWN error, so try to sleep one second
assert(node);
* before requesting the new configuration. */
if (++node->current_slot_index >= node->slots_count) {
fetch_slots
=
1
;
if (config.showerrors) {
do_wait
=
1
;
fprintf(stderr, "WARN: No more available slots in "
printf
(
"Error from server %s:%d: %s
\n
"
,
"node %s:%d\n", node->ip, node->port);
c
->
cluster_node
->
ip
,
}
c
->
cluster_node
->
port
,
freeReplyObject(reply);
r
->
str
);
freeClient(c);
return;
}
}
*/
if
(
do_wait
)
sleep
(
1
);
if
(
fetch_slots
&&
!
fetchClusterSlotsConfiguration
(
c
))
exit
(
1
);
}
}
freeReplyObject
(
reply
);
freeReplyObject
(
reply
);
...
@@ -817,22 +817,37 @@ static void showLatencyReport(void) {
...
@@ -817,22 +817,37 @@ static void showLatencyReport(void) {
}
}
}
}
static
void
b
enchmark
(
char
*
title
,
char
*
cmd
,
int
len
)
{
static
void
initB
enchmark
Threads
(
)
{
int
i
;
int
i
;
if
(
config
.
threads
)
freeBenchmarkThreads
();
config
.
threads
=
zmalloc
(
config
.
num_threads
*
sizeof
(
benchmarkThread
*
));
for
(
i
=
0
;
i
<
config
.
num_threads
;
i
++
)
{
benchmarkThread
*
thread
=
createBenchmarkThread
(
i
);
config
.
threads
[
i
]
=
thread
;
}
}
static
void
startBenchmarkThreads
()
{
int
i
;
for
(
i
=
0
;
i
<
config
.
num_threads
;
i
++
)
{
benchmarkThread
*
t
=
config
.
threads
[
i
];
if
(
pthread_create
(
&
(
t
->
thread
),
NULL
,
execBenchmarkThread
,
t
)){
fprintf
(
stderr
,
"FATAL: Failed to start thread %d.
\n
"
,
i
);
exit
(
1
);
}
}
for
(
i
=
0
;
i
<
config
.
num_threads
;
i
++
)
pthread_join
(
config
.
threads
[
i
]
->
thread
,
NULL
);
}
static
void
benchmark
(
char
*
title
,
char
*
cmd
,
int
len
)
{
client
c
;
client
c
;
config
.
title
=
title
;
config
.
title
=
title
;
config
.
requests_issued
=
0
;
config
.
requests_issued
=
0
;
config
.
requests_finished
=
0
;
config
.
requests_finished
=
0
;
if
(
config
.
num_threads
)
{
if
(
config
.
num_threads
)
initBenchmarkThreads
();
if
(
config
.
threads
)
freeBenchmarkThreads
();
config
.
threads
=
zmalloc
(
config
.
num_threads
*
sizeof
(
benchmarkThread
*
));
for
(
i
=
0
;
i
<
config
.
num_threads
;
i
++
)
{
benchmarkThread
*
thread
=
createBenchmarkThread
(
i
);
config
.
threads
[
i
]
=
thread
;
}
}
int
thread_id
=
config
.
num_threads
>
0
?
0
:
-
1
;
int
thread_id
=
config
.
num_threads
>
0
?
0
:
-
1
;
c
=
createClient
(
cmd
,
len
,
NULL
,
thread_id
);
c
=
createClient
(
cmd
,
len
,
NULL
,
thread_id
);
...
@@ -840,17 +855,7 @@ static void benchmark(char *title, char *cmd, int len) {
...
@@ -840,17 +855,7 @@ static void benchmark(char *title, char *cmd, int len) {
config
.
start
=
mstime
();
config
.
start
=
mstime
();
if
(
!
config
.
num_threads
)
aeMain
(
config
.
el
);
if
(
!
config
.
num_threads
)
aeMain
(
config
.
el
);
else
{
else
startBenchmarkThreads
();
for
(
i
=
0
;
i
<
config
.
num_threads
;
i
++
)
{
benchmarkThread
*
t
=
config
.
threads
[
i
];
if
(
pthread_create
(
&
(
t
->
thread
),
NULL
,
execBenchmarkThread
,
t
)){
fprintf
(
stderr
,
"FATAL: Failed to start thread %d.
\n
"
,
i
);
exit
(
1
);
}
}
for
(
i
=
0
;
i
<
config
.
num_threads
;
i
++
)
pthread_join
(
config
.
threads
[
i
]
->
thread
,
NULL
);
}
config
.
totlatency
=
mstime
()
-
config
.
start
;
config
.
totlatency
=
mstime
()
-
config
.
start
;
showLatencyReport
();
showLatencyReport
();
...
@@ -1283,6 +1288,11 @@ int parseOptions(int argc, const char **argv) {
...
@@ -1283,6 +1288,11 @@ int parseOptions(int argc, const char **argv) {
if
(
config
.
pipeline
<=
0
)
config
.
pipeline
=
1
;
if
(
config
.
pipeline
<=
0
)
config
.
pipeline
=
1
;
}
else
if
(
!
strcmp
(
argv
[
i
],
"-r"
))
{
}
else
if
(
!
strcmp
(
argv
[
i
],
"-r"
))
{
if
(
lastarg
)
goto
invalid
;
if
(
lastarg
)
goto
invalid
;
const
char
*
next
=
argv
[
++
i
],
*
p
=
next
;
if
(
*
p
==
'-'
)
{
p
++
;
if
(
*
p
<
'0'
||
*
p
>
'9'
)
goto
invalid
;
}
config
.
randomkeys
=
1
;
config
.
randomkeys
=
1
;
config
.
randomkeys_keyspacelen
=
atoi
(
argv
[
++
i
]);
config
.
randomkeys_keyspacelen
=
atoi
(
argv
[
++
i
]);
if
(
config
.
randomkeys_keyspacelen
<
0
)
if
(
config
.
randomkeys_keyspacelen
<
0
)
...
@@ -1546,9 +1556,15 @@ int main(int argc, const char **argv) {
...
@@ -1546,9 +1556,15 @@ int main(int argc, const char **argv) {
if
(
config
.
idlemode
)
{
if
(
config
.
idlemode
)
{
printf
(
"Creating %d idle connections and waiting forever (Ctrl+C when done)
\n
"
,
config
.
numclients
);
printf
(
"Creating %d idle connections and waiting forever (Ctrl+C when done)
\n
"
,
config
.
numclients
);
c
=
createClient
(
""
,
0
,
NULL
,
-
1
);
/* will never receive a reply */
int
thread_id
=
-
1
,
use_threads
=
(
config
.
num_threads
>
0
);
if
(
use_threads
)
{
thread_id
=
0
;
initBenchmarkThreads
();
}
c
=
createClient
(
""
,
0
,
NULL
,
thread_id
);
/* will never receive a reply */
createMissingClients
(
c
);
createMissingClients
(
c
);
aeMain
(
config
.
el
);
if
(
use_threads
)
startBenchmarkThreads
();
else
aeMain
(
config
.
el
);
/* and will wait for every */
/* and will wait for every */
}
}
...
...
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