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
da86481e
Unverified
Commit
da86481e
authored
Feb 14, 2019
by
Salvatore Sanfilippo
Committed by
GitHub
Feb 14, 2019
Browse files
Merge pull request #5840 from madolson/dev-unstable-benchmark-latency
Updated redis benchmark with us precision support
parents
fd7484cd
f9bababa
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/redis-benchmark.c
View file @
da86481e
...
@@ -39,6 +39,7 @@
...
@@ -39,6 +39,7 @@
#include <sys/time.h>
#include <sys/time.h>
#include <signal.h>
#include <signal.h>
#include <assert.h>
#include <assert.h>
#include <math.h>
#include <sds.h>
/* Use hiredis sds. */
#include <sds.h>
/* Use hiredis sds. */
#include "ae.h"
#include "ae.h"
...
@@ -48,6 +49,7 @@
...
@@ -48,6 +49,7 @@
#define UNUSED(V) ((void) V)
#define UNUSED(V) ((void) V)
#define RANDPTR_INITIAL_SIZE 8
#define RANDPTR_INITIAL_SIZE 8
#define MAX_LATENCY_PRECISION 3
static
struct
config
{
static
struct
config
{
aeEventLoop
*
el
;
aeEventLoop
*
el
;
...
@@ -79,6 +81,7 @@ static struct config {
...
@@ -79,6 +81,7 @@ static struct config {
sds
dbnumstr
;
sds
dbnumstr
;
char
*
tests
;
char
*
tests
;
char
*
auth
;
char
*
auth
;
int
precision
;
}
config
;
}
config
;
typedef
struct
_client
{
typedef
struct
_client
{
...
@@ -428,8 +431,19 @@ static int compareLatency(const void *a, const void *b) {
...
@@ -428,8 +431,19 @@ static int compareLatency(const void *a, const void *b) {
return
(
*
(
long
long
*
)
a
)
-
(
*
(
long
long
*
)
b
);
return
(
*
(
long
long
*
)
a
)
-
(
*
(
long
long
*
)
b
);
}
}
static
int
ipow
(
int
base
,
int
exp
)
{
int
result
=
1
;
while
(
exp
)
{
if
(
exp
&
1
)
result
*=
base
;
exp
/=
2
;
base
*=
base
;
}
return
result
;
}
static
void
showLatencyReport
(
void
)
{
static
void
showLatencyReport
(
void
)
{
int
i
,
curlat
=
0
;
int
i
,
curlat
=
0
;
int
usbetweenlat
=
ipow
(
10
,
MAX_LATENCY_PRECISION
-
config
.
precision
);
float
perc
,
reqpersec
;
float
perc
,
reqpersec
;
reqpersec
=
(
float
)
config
.
requests_finished
/
((
float
)
config
.
totlatency
/
1000
);
reqpersec
=
(
float
)
config
.
requests_finished
/
((
float
)
config
.
totlatency
/
1000
);
...
@@ -444,10 +458,10 @@ static void showLatencyReport(void) {
...
@@ -444,10 +458,10 @@ static void showLatencyReport(void) {
qsort
(
config
.
latency
,
config
.
requests
,
sizeof
(
long
long
),
compareLatency
);
qsort
(
config
.
latency
,
config
.
requests
,
sizeof
(
long
long
),
compareLatency
);
for
(
i
=
0
;
i
<
config
.
requests
;
i
++
)
{
for
(
i
=
0
;
i
<
config
.
requests
;
i
++
)
{
if
(
config
.
latency
[
i
]
/
1000
!=
curlat
||
i
==
(
config
.
requests
-
1
))
{
if
(
config
.
latency
[
i
]
/
usbetweenlat
!=
curlat
||
i
==
(
config
.
requests
-
1
))
{
curlat
=
config
.
latency
[
i
]
/
1000
;
curlat
=
config
.
latency
[
i
]
/
usbetweenlat
;
perc
=
((
float
)(
i
+
1
)
*
100
)
/
config
.
requests
;
perc
=
((
float
)(
i
+
1
)
*
100
)
/
config
.
requests
;
printf
(
"%.2f%% <= %
d
milliseconds
\n
"
,
perc
,
c
urlat
);
printf
(
"%.2f%% <= %
.*f
milliseconds
\n
"
,
perc
,
c
onfig
.
precision
,
curlat
/
pow
(
10
.
0
,
config
.
precision
)
);
}
}
}
}
printf
(
"%.2f requests per second
\n\n
"
,
reqpersec
);
printf
(
"%.2f requests per second
\n\n
"
,
reqpersec
);
...
@@ -546,6 +560,11 @@ int parseOptions(int argc, const char **argv) {
...
@@ -546,6 +560,11 @@ int parseOptions(int argc, const char **argv) {
if
(
lastarg
)
goto
invalid
;
if
(
lastarg
)
goto
invalid
;
config
.
dbnum
=
atoi
(
argv
[
++
i
]);
config
.
dbnum
=
atoi
(
argv
[
++
i
]);
config
.
dbnumstr
=
sdsfromlonglong
(
config
.
dbnum
);
config
.
dbnumstr
=
sdsfromlonglong
(
config
.
dbnum
);
}
else
if
(
!
strcmp
(
argv
[
i
],
"--precision"
))
{
if
(
lastarg
)
goto
invalid
;
config
.
precision
=
atoi
(
argv
[
++
i
]);
if
(
config
.
precision
<
0
)
config
.
precision
=
0
;
if
(
config
.
precision
>
MAX_LATENCY_PRECISION
)
config
.
precision
=
MAX_LATENCY_PRECISION
;
}
else
if
(
!
strcmp
(
argv
[
i
],
"--help"
))
{
}
else
if
(
!
strcmp
(
argv
[
i
],
"--help"
))
{
exit_status
=
0
;
exit_status
=
0
;
goto
usage
;
goto
usage
;
...
@@ -585,6 +604,7 @@ usage:
...
@@ -585,6 +604,7 @@ usage:
" -e If server replies with errors, show them on stdout.
\n
"
" -e If server replies with errors, show them on stdout.
\n
"
" (no more than 1 error per second is displayed)
\n
"
" (no more than 1 error per second is displayed)
\n
"
" -q Quiet. Just show query/sec values
\n
"
" -q Quiet. Just show query/sec values
\n
"
" --precision Number of decimal places to display in latency output (default 0)
\n
"
" --csv Output in CSV format
\n
"
" --csv Output in CSV format
\n
"
" -l Loop. Run the tests forever
\n
"
" -l Loop. Run the tests forever
\n
"
" -t <tests> Only run the comma separated list of tests. The test
\n
"
" -t <tests> Only run the comma separated list of tests. The test
\n
"
...
@@ -679,6 +699,7 @@ int main(int argc, const char **argv) {
...
@@ -679,6 +699,7 @@ int main(int argc, const char **argv) {
config
.
tests
=
NULL
;
config
.
tests
=
NULL
;
config
.
dbnum
=
0
;
config
.
dbnum
=
0
;
config
.
auth
=
NULL
;
config
.
auth
=
NULL
;
config
.
precision
=
0
;
i
=
parseOptions
(
argc
,
argv
);
i
=
parseOptions
(
argc
,
argv
);
argc
-=
i
;
argc
-=
i
;
...
...
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