mirror of
https://github.com/fluencelabs/redis
synced 2025-03-20 09:30:55 +00:00
parent
c33cb4938a
commit
0e963e068d
@ -817,22 +817,37 @@ static void showLatencyReport(void) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void benchmark(char *title, char *cmd, int len) {
|
static void initBenchmarkThreads() {
|
||||||
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) {
|
|||||||
|
|
||||||
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();
|
||||||
@ -1546,9 +1551,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 */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user