2 +--------------------------------------------------------------------+
3 | libmemcached - C/C++ Client Library for memcached |
4 +--------------------------------------------------------------------+
5 | Redistribution and use in source and binary forms, with or without |
6 | modification, are permitted under the terms of the BSD license. |
7 | You should have received a copy of the license in a bundled file |
8 | named LICENSE; in case you did not receive a copy you can review |
9 | the terms online at: https://opensource.org/licenses/BSD-3-Clause |
10 +--------------------------------------------------------------------+
11 | Copyright (c) 2006-2014 Brian Aker https://datadifferential.com/ |
12 | Copyright (c) 2020 Michael Wallner <mike@php.net> |
13 +--------------------------------------------------------------------+
16 #include "mem_config.h"
22 #if defined(HAVE_SYS_TIME_H)
23 # include <sys/time.h>
26 #if defined(HAVE_TIME_H)
30 #include "ms_sigsegv.h"
31 #include "ms_setting.h"
32 #include "ms_thread.h"
34 /* global structure */
35 ms_global_t ms_global
;
37 /* global stats information structure */
40 /* global statistic structure */
41 ms_statistic_t ms_statistic
;
43 #define PROGRAM_NAME "memaslap"
44 #define PROGRAM_DESCRIPTION "Generates workload against memcached servers."
47 /* For some odd reason the option struct on solaris defines the argument
48 * as char* and not const char*
50 # define OPTIONSTRING char *
52 # define OPTIONSTRING const char *
56 static struct option long_options
[] = {
57 {(OPTIONSTRING
) "servers", required_argument
, NULL
, OPT_SERVERS
},
58 {(OPTIONSTRING
) "threads", required_argument
, NULL
, OPT_THREAD_NUMBER
},
59 {(OPTIONSTRING
) "concurrency", required_argument
, NULL
, OPT_CONCURRENCY
},
60 {(OPTIONSTRING
) "conn_sock", required_argument
, NULL
, OPT_SOCK_PER_CONN
},
61 {(OPTIONSTRING
) "execute_number", required_argument
, NULL
, OPT_EXECUTE_NUMBER
},
62 {(OPTIONSTRING
) "time", required_argument
, NULL
, OPT_TIME
},
63 {(OPTIONSTRING
) "cfg_cmd", required_argument
, NULL
, OPT_CONFIG_CMD
},
64 {(OPTIONSTRING
) "win_size", required_argument
, NULL
, OPT_WINDOW_SIZE
},
65 {(OPTIONSTRING
) "fixed_size", required_argument
, NULL
, OPT_FIXED_LTH
},
66 {(OPTIONSTRING
) "verify", required_argument
, NULL
, OPT_VERIFY
},
67 {(OPTIONSTRING
) "division", required_argument
, NULL
, OPT_GETS_DIVISION
},
68 {(OPTIONSTRING
) "stat_freq", required_argument
, NULL
, OPT_STAT_FREQ
},
69 {(OPTIONSTRING
) "exp_verify", required_argument
, NULL
, OPT_EXPIRE
},
70 {(OPTIONSTRING
) "overwrite", required_argument
, NULL
, OPT_OVERWRITE
},
71 {(OPTIONSTRING
) "reconnect", no_argument
, NULL
, OPT_RECONNECT
},
72 {(OPTIONSTRING
) "udp", no_argument
, NULL
, OPT_UDP
},
73 {(OPTIONSTRING
) "facebook", no_argument
, NULL
, OPT_FACEBOOK_TEST
},
74 {(OPTIONSTRING
) "binary", no_argument
, NULL
, OPT_BINARY_PROTOCOL
},
75 {(OPTIONSTRING
) "tps", required_argument
, NULL
, OPT_TPS
},
76 {(OPTIONSTRING
) "rep_write", required_argument
, NULL
, OPT_REP_WRITE_SRV
},
77 {(OPTIONSTRING
) "verbose", no_argument
, NULL
, OPT_VERBOSE
},
78 {(OPTIONSTRING
) "help", no_argument
, NULL
, OPT_HELP
},
79 {(OPTIONSTRING
) "version", no_argument
, NULL
, OPT_VERSION
},
84 static void ms_sync_lock_init(void);
85 static void ms_sync_lock_destroy(void);
86 static void ms_global_struct_init(void);
87 static void ms_global_struct_destroy(void);
88 static void ms_version_command(const char *command_name
);
89 static const char *ms_lookup_help(ms_options_t option
);
90 static int64_t ms_parse_time(void);
91 static int64_t ms_parse_size(void);
92 static void ms_options_parse(int argc
, char *argv
[]);
93 static int ms_check_para(void);
94 static void ms_statistic_init(void);
95 static void ms_stats_init(void);
96 static void ms_print_statistics(int in_time
);
97 static void ms_print_memaslap_stats(struct timeval
*start_time
, struct timeval
*end_time
);
98 static void ms_monitor_slap_mode(void);
101 * output the help information
103 * @param command_name, the string of this process
104 * @param description, description of this process
105 * @param long_options, global options array
107 static void ms_help_command(const char *command_name
, const char *description
) {
108 char *help_message
= NULL
;
110 printf("%s v%u.%u\n", command_name
, 1U, 0U);
111 printf(" %s\n\n", description
);
113 " memaslap -hV | -s servers [-F config_file] [-t time | -x exe_num] [...]\n\n"
116 for (int x
= 0; long_options
[x
].name
; x
++) {
117 printf(" -%c, --%s%c\n", long_options
[x
].val
, long_options
[x
].name
,
118 long_options
[x
].has_arg
? '=' : ' ');
120 if ((help_message
= (char *) ms_lookup_help(long_options
[x
].val
))) {
121 printf(" %s\n", help_message
);
125 printf("\nExamples:\n"
126 " memaslap -s 127.0.0.1:11211 -S 5s\n"
127 " memaslap -s 127.0.0.1:11211 -t 2m -v 0.2 -e 0.05 -b\n"
128 " memaslap -s 127.0.0.1:11211 -F config -t 2m -w 40k -S 20s -o 0.2\n"
129 " memaslap -s 127.0.0.1:11211 -F config -t 2m -T 4 -c 128 -d 20 -P 40k\n"
130 " memaslap -s 127.0.0.1:11211 -F config -t 2m -d 50 -a -n 40\n"
131 " memaslap -s 127.0.0.1:11211,127.0.0.1:11212 -F config -t 2m\n"
132 " memaslap -s 127.0.0.1:11211,127.0.0.1:11212 -F config -t 2m -p 2\n\n");
133 } /* ms_help_command */
135 /* initialize the global locks */
136 static void ms_sync_lock_init() {
137 ms_global
.init_lock
.count
= 0;
138 pthread_mutex_init(&ms_global
.init_lock
.lock
, NULL
);
139 pthread_cond_init(&ms_global
.init_lock
.cond
, NULL
);
141 ms_global
.warmup_lock
.count
= 0;
142 pthread_mutex_init(&ms_global
.warmup_lock
.lock
, NULL
);
143 pthread_cond_init(&ms_global
.warmup_lock
.cond
, NULL
);
145 ms_global
.run_lock
.count
= 0;
146 pthread_mutex_init(&ms_global
.run_lock
.lock
, NULL
);
147 pthread_cond_init(&ms_global
.run_lock
.cond
, NULL
);
149 pthread_mutex_init(&ms_global
.quit_mutex
, NULL
);
150 pthread_mutex_init(&ms_global
.seq_mutex
, NULL
);
151 } /* ms_sync_lock_init */
153 /* destroy the global locks */
154 static void ms_sync_lock_destroy() {
155 pthread_mutex_destroy(&ms_global
.init_lock
.lock
);
156 pthread_cond_destroy(&ms_global
.init_lock
.cond
);
158 pthread_mutex_destroy(&ms_global
.warmup_lock
.lock
);
159 pthread_cond_destroy(&ms_global
.warmup_lock
.cond
);
161 pthread_mutex_destroy(&ms_global
.run_lock
.lock
);
162 pthread_cond_destroy(&ms_global
.run_lock
.cond
);
164 pthread_mutex_destroy(&ms_global
.quit_mutex
);
165 pthread_mutex_destroy(&ms_global
.seq_mutex
);
167 if (ms_setting
.stat_freq
> 0) {
168 pthread_mutex_destroy(&ms_statistic
.stat_mutex
);
170 } /* ms_sync_lock_destroy */
172 /* initialize the global structure */
173 static void ms_global_struct_init() {
175 ms_global
.finish_warmup
= false;
176 ms_global
.time_out
= false;
179 /* destroy the global structure */
180 static void ms_global_struct_destroy() {
181 ms_sync_lock_destroy();
185 * output the version information
187 * @param command_name, the string of this process
189 static void ms_version_command(const char *command_name
) {
190 printf("%s v%u.%u\n", command_name
, 1U, 0U);
195 * get the description of the option
197 * @param option, option of command line
199 * @return char*, description of the command option
201 static const char *ms_lookup_help(ms_options_t option
) {
204 return "List one or more servers to connect. Servers count must be less than\n"
205 " threads count. e.g.: --servers=localhost:1234,localhost:11211";
208 return "Display the version of the application and then exit.";
211 return "Display this message and then exit.";
213 case OPT_EXECUTE_NUMBER
:
214 return "Number of operations(get and set) to execute for the\n"
215 " given test. Default 1000000.";
217 case OPT_THREAD_NUMBER
:
218 return "Number of threads to startup, better equal to CPU numbers. Default 8.";
220 case OPT_CONCURRENCY
:
221 return "Number of concurrency to simulate with load. Default 128.";
224 return "Fixed length of value.";
227 return "The proportion of date verification, e.g.: --verify=0.01";
229 case OPT_GETS_DIVISION
:
230 return "Number of keys to multi-get once. Default 1, means single get.";
233 return "How long the test to run, suffix: s-seconds, m-minutes, h-hours,\n"
234 " d-days e.g.: --time=2h.";
237 return "Load the configure file to get command,key and value distribution list.";
239 case OPT_WINDOW_SIZE
:
240 return "Task window size of each concurrency, suffix: K, M e.g.: --win_size=10k.\n"
244 return "UDP support, by default memaslap uses TCP; TCP port and UDP port of\n"
245 " server must be same.";
248 return "The proportion of objects with expire time, e.g.: --exp_verify=0.01.\n"
249 " Default no object with expire time";
252 return "The proportion of objects need overwrite, e.g.: --overwrite=0.01.\n"
253 " Default never overwrite object.";
256 return "Frequency of dumping statistic information. suffix: s-seconds,\n"
257 " m-minutes, e.g.: --resp_freq=10s.";
259 case OPT_SOCK_PER_CONN
:
260 return "Number of TCP socks per concurrency. Default 1.";
263 return "Reconnect support, when connection is closed it will be reconnected.";
266 return "Whether it outputs detailed information when verification fails.";
268 case OPT_FACEBOOK_TEST
:
269 return "Whether it enables facebook test feature, set with TCP and multi-get with UDP.";
271 case OPT_BINARY_PROTOCOL
:
272 return "Whether it enables binary protocol. Default with ASCII protocol.";
275 return "Expected throughput, suffix: K, e.g.: --tps=10k.";
277 case OPT_REP_WRITE_SRV
:
278 return "The first nth servers can write data, e.g.: --rep_write=2.";
281 return "Forgot to document this option :)";
283 } /* ms_lookup_help */
285 /* used to parse the time string */
286 static int64_t ms_parse_time() {
288 char unit
= optarg
[strlen(optarg
) - 1];
290 optarg
[strlen(optarg
) - 1] = '\0';
316 } /* ms_parse_time */
318 /* used to parse the size string */
319 static int64_t ms_parse_size() {
321 char unit
= optarg
[strlen(optarg
) - 1];
323 optarg
[strlen(optarg
) - 1] = '\0';
325 ret
= strtoll(optarg
, (char **) NULL
, 10);
327 fprintf(stderr
, "strtoll(optarg,..): %s\n", strerror(errno
));
344 ret
*= 1024 * 1024 * 1024;
353 } /* ms_parse_size */
355 /* used to parse the options of command line */
356 static void ms_options_parse(int argc
, char *argv
[]) {
357 int option_index
= 0;
360 while ((option_rv
= getopt_long(argc
, argv
,
361 "VhURbaBs:x:T:c:X:v:d:"
362 "t:S:F:w:e:o:n:P:p:",
363 long_options
, &option_index
))
370 case OPT_VERSION
: /* --version or -V */
371 ms_version_command(PROGRAM_NAME
);
374 case OPT_HELP
: /* --help or -h */
375 ms_help_command(PROGRAM_NAME
, PROGRAM_DESCRIPTION
);
379 case OPT_SERVERS
: /* --servers or -s */
380 ms_setting
.srv_str
= strdup(optarg
);
383 case OPT_CONCURRENCY
: /* --concurrency or -c */
385 ms_setting
.nconns
= (uint32_t) strtoul(optarg
, (char **) NULL
, 10);
386 if (ms_setting
.nconns
<= 0 || errno
) {
387 fprintf(stderr
, "Concurrency must be greater than 0.:-)\n");
392 case OPT_EXECUTE_NUMBER
: /* --execute_number or -x */
394 ms_setting
.exec_num
= (int) strtol(optarg
, (char **) NULL
, 10);
395 if (ms_setting
.exec_num
<= 0 || errno
) {
396 fprintf(stderr
, "Execute number must be greater than 0.:-)\n");
401 case OPT_THREAD_NUMBER
: /* --threads or -T */
403 ms_setting
.nthreads
= (uint32_t) strtoul(optarg
, (char **) NULL
, 10);
404 if (ms_setting
.nthreads
<= 0 || errno
) {
405 fprintf(stderr
, "Threads number must be greater than 0.:-)\n");
410 case OPT_FIXED_LTH
: /* --fixed_size or -X */
412 ms_setting
.fixed_value_size
= (size_t) strtoull(optarg
, (char **) NULL
, 10);
413 if ((ms_setting
.fixed_value_size
<= 0 || errno
)
414 || (ms_setting
.fixed_value_size
> MAX_VALUE_SIZE
))
416 fprintf(stderr
, "Value size must be between 0 and 1M.:-)\n");
421 case OPT_VERIFY
: /* --verify or -v */
422 ms_setting
.verify_percent
= atof(optarg
);
423 if ((ms_setting
.verify_percent
<= 0) || (ms_setting
.verify_percent
> 1.0)) {
425 "Data verification rate must be "
426 "greater than 0 and less than 1.0. :-)\n");
431 case OPT_GETS_DIVISION
: /* --division or -d */
433 ms_setting
.mult_key_num
= (int) strtol(optarg
, (char **) NULL
, 10);
434 if (ms_setting
.mult_key_num
<= 0 || errno
) {
435 fprintf(stderr
, "Multi-get key number must be greater than 0.:-)\n");
440 case OPT_TIME
: /* --time or -t */
441 ms_setting
.run_time
= (int) ms_parse_time();
442 if (ms_setting
.run_time
== -1) {
444 "Please specify the run time. :-)\n"
445 "'s' for second, 'm' for minute, 'h' for hour, "
446 "'d' for day. e.g.: --time=24h (means 24 hours).\n");
450 if (ms_setting
.run_time
== 0) {
451 fprintf(stderr
, "Running time can not be 0. :-)\n");
456 case OPT_CONFIG_CMD
: /* --cfg_cmd or -F */
457 ms_setting
.cfg_file
= strdup(optarg
);
460 case OPT_WINDOW_SIZE
: /* --win_size or -w */
461 ms_setting
.win_size
= (size_t) ms_parse_size();
462 if (ms_setting
.win_size
== (size_t) -1) {
464 "Please specify the item window size. :-)\n"
465 "e.g.: --win_size=10k (means 10k task window size).\n");
470 case OPT_UDP
: /* --udp or -U*/
471 ms_setting
.udp
= true;
474 case OPT_EXPIRE
: /* --exp_verify or -e */
475 ms_setting
.exp_ver_per
= atof(optarg
);
476 if ((ms_setting
.exp_ver_per
<= 0) || (ms_setting
.exp_ver_per
> 1.0)) {
478 "Expire time verification rate must be "
479 "greater than 0 and less than 1.0. :-)\n");
484 case OPT_OVERWRITE
: /* --overwrite or -o */
485 ms_setting
.overwrite_percent
= atof(optarg
);
486 if ((ms_setting
.overwrite_percent
<= 0) || (ms_setting
.overwrite_percent
> 1.0)) {
488 "Objects overwrite rate must be "
489 "greater than 0 and less than 1.0. :-)\n");
494 case OPT_STAT_FREQ
: /* --stat_freq or -S */
495 ms_setting
.stat_freq
= (int) ms_parse_time();
496 if (ms_setting
.stat_freq
== -1) {
498 "Please specify the frequency of dumping "
499 "statistic information. :-)\n"
500 "'s' for second, 'm' for minute, 'h' for hour, "
501 "'d' for day. e.g.: --time=24h (means 24 hours).\n");
505 if (ms_setting
.stat_freq
== 0) {
507 "The frequency of dumping statistic information "
508 "can not be 0. :-)\n");
513 case OPT_SOCK_PER_CONN
: /* --conn_sock or -n */
515 ms_setting
.sock_per_conn
= (uint32_t) strtoul(optarg
, (char **) NULL
, 10);
516 if (ms_setting
.sock_per_conn
<= 0 || errno
) {
518 "Number of socks of each concurrency "
519 "must be greater than 0.:-)\n");
524 case OPT_RECONNECT
: /* --reconnect or -R */
525 ms_setting
.reconnect
= true;
528 case OPT_VERBOSE
: /* --verbose or -b */
529 ms_setting
.verbose
= true;
532 case OPT_FACEBOOK_TEST
: /* --facebook or -a */
533 ms_setting
.facebook_test
= true;
536 case OPT_BINARY_PROTOCOL
: /* --binary or -B */
537 ms_setting
.binary_prot_
= true;
540 case OPT_TPS
: /* --tps or -P */
541 ms_setting
.expected_tps
= (int) ms_parse_size();
542 if (ms_setting
.expected_tps
== -1) {
544 "Please specify the item expected throughput. :-)\n"
545 "e.g.: --tps=10k (means 10k throughput).\n");
550 case OPT_REP_WRITE_SRV
: /* --rep_write or -p */
552 ms_setting
.rep_write_srv
= (uint32_t) strtoul(optarg
, (char **) NULL
, 10);
553 if (ms_setting
.rep_write_srv
<= 0 || errno
) {
555 "Number of replication writing server must be greater "
562 /* getopt_long already printed an error message. */
569 } /* ms_options_parse */
571 static int ms_check_para() {
572 if (ms_setting
.srv_str
== NULL
) {
575 if ((temp
= getenv("MEMCACHED_SERVERS"))) {
576 ms_setting
.srv_str
= strdup(temp
);
578 fprintf(stderr
, "No servers provided\n\n");
583 if (ms_setting
.nconns
% (uint32_t) ms_setting
.nthreads
) {
584 fprintf(stderr
, "Concurrency must be the multiples of threads count.\n");
588 if (ms_setting
.win_size
% UNIT_ITEMS_COUNT
) {
589 fprintf(stderr
, "Window size must be the multiples of 1024.\n\n");
594 } /* ms_check_para */
596 /* initialize the statistic structure */
597 static void ms_statistic_init() {
598 pthread_mutex_init(&ms_statistic
.stat_mutex
, NULL
);
599 ms_init_stats(&ms_statistic
.get_stat
, "Get");
600 ms_init_stats(&ms_statistic
.set_stat
, "Set");
601 ms_init_stats(&ms_statistic
.total_stat
, "Total");
602 } /* ms_statistic_init */
604 /* initialize the global state structure */
605 static void ms_stats_init() {
606 memset(&ms_stats
, 0, sizeof(ms_stats_t
));
607 if (ms_setting
.stat_freq
> 0) {
610 } /* ms_stats_init */
612 /* use to output the statistic */
613 static void ms_print_statistics(int in_time
) {
614 int obj_size
= (int) (ms_setting
.avg_key_size
+ ms_setting
.avg_val_size
);
616 printf("\033[1;1H\033[2J\n");
617 ms_dump_format_stats(&ms_statistic
.get_stat
, in_time
, ms_setting
.stat_freq
, obj_size
);
618 ms_dump_format_stats(&ms_statistic
.set_stat
, in_time
, ms_setting
.stat_freq
, obj_size
);
619 ms_dump_format_stats(&ms_statistic
.total_stat
, in_time
, ms_setting
.stat_freq
, obj_size
);
620 } /* ms_print_statistics */
622 /* used to print the states of memaslap */
623 static void ms_print_memaslap_stats(struct timeval
*start_time
, struct timeval
*end_time
) {
627 pos
+= snprintf(pos
, sizeof(buf
), "cmd_get: %lu\n", (unsigned long) ms_stats
.cmd_get
);
628 pos
+= snprintf(pos
, sizeof(buf
) - (size_t)(pos
- buf
), "cmd_set: %lu\n",
629 (unsigned long) ms_stats
.cmd_set
);
630 pos
+= snprintf(pos
, sizeof(buf
) - (size_t)(pos
- buf
), "get_misses: %lu\n",
631 (unsigned long) ms_stats
.get_misses
);
633 if (ms_setting
.verify_percent
> 0) {
634 pos
+= snprintf(pos
, sizeof(buf
) - (size_t)(pos
- buf
), "verify_misses: %lu\n",
635 (unsigned long) ms_stats
.vef_miss
);
636 pos
+= snprintf(pos
, sizeof(buf
) - (size_t)(pos
- buf
), "verify_failed: %lu\n",
637 (unsigned long) ms_stats
.vef_failed
);
640 if (ms_setting
.exp_ver_per
> 0) {
641 pos
+= snprintf(pos
, sizeof(buf
) - (size_t)(pos
- buf
), "expired_get: %lu\n",
642 (unsigned long) ms_stats
.exp_get
);
643 pos
+= snprintf(pos
, sizeof(buf
) - (size_t)(pos
- buf
), "unexpired_unget: %lu\n",
644 (unsigned long) ms_stats
.unexp_unget
);
647 pos
+= snprintf(pos
, sizeof(buf
) - (size_t)(pos
- buf
), "written_bytes: %lu\n",
648 (unsigned long) ms_stats
.bytes_written
);
649 pos
+= snprintf(pos
, sizeof(buf
) - (size_t)(pos
- buf
), "read_bytes: %lu\n",
650 (unsigned long) ms_stats
.bytes_read
);
651 pos
+= snprintf(pos
, sizeof(buf
) - (size_t)(pos
- buf
), "object_bytes: %lu\n",
652 (unsigned long) ms_stats
.obj_bytes
);
654 if (ms_setting
.udp
|| ms_setting
.facebook_test
) {
655 pos
+= snprintf(pos
, sizeof(buf
) - (size_t)(pos
- buf
), "packet_disorder: %lu\n",
656 (unsigned long) ms_stats
.pkt_disorder
);
657 pos
+= snprintf(pos
, sizeof(buf
) - (size_t)(pos
- buf
), "packet_drop: %lu\n",
658 (unsigned long) ms_stats
.pkt_drop
);
659 pos
+= snprintf(pos
, sizeof(buf
) - (size_t)(pos
- buf
), "udp_timeout: %lu\n",
660 (unsigned long) ms_stats
.udp_timeout
);
663 if (ms_setting
.stat_freq
> 0) {
664 ms_dump_stats(&ms_statistic
.get_stat
);
665 ms_dump_stats(&ms_statistic
.set_stat
);
666 ms_dump_stats(&ms_statistic
.total_stat
);
669 int64_t time_diff
= ms_time_diff(start_time
, end_time
);
670 pos
+= snprintf(pos
, sizeof(buf
) - (size_t)(pos
- buf
),
671 "\nRun time: %.1fs Ops: %llu TPS: %.0Lf Net_rate: %.1fM/s\n",
672 (double) time_diff
/ 1000000,
673 (unsigned long long) (ms_stats
.cmd_get
+ ms_stats
.cmd_set
),
674 (ms_stats
.cmd_get
+ ms_stats
.cmd_set
) / ((long double) time_diff
/ 1000000),
675 (double) (ms_stats
.bytes_written
+ ms_stats
.bytes_read
) / 1024 / 1024
676 / ((double) time_diff
/ 1000000));
677 assert(pos
<= (buf
+ sizeof(buf
)));
679 fwrite(buf
, 1, pos
- buf
, stdout
);
681 } /* ms_print_memaslap_stats */
683 /* the loop of the main thread, wait the work threads to complete */
684 static void ms_monitor_slap_mode() {
685 struct timeval start_time
, end_time
;
687 /* Wait all the threads complete initialization. */
688 pthread_mutex_lock(&ms_global
.init_lock
.lock
);
689 while (ms_global
.init_lock
.count
< ms_setting
.nthreads
) {
690 pthread_cond_wait(&ms_global
.init_lock
.cond
, &ms_global
.init_lock
.lock
);
692 pthread_mutex_unlock(&ms_global
.init_lock
.lock
);
694 /* only when there is no set operation it need warm up */
695 if (ms_setting
.cmd_distr
[CMD_SET
].cmd_prop
< PROP_ERROR
) {
696 /* Wait all the connects complete warm up. */
697 pthread_mutex_lock(&ms_global
.warmup_lock
.lock
);
698 while (ms_global
.warmup_lock
.count
< ms_setting
.nconns
) {
699 pthread_cond_wait(&ms_global
.warmup_lock
.cond
, &ms_global
.warmup_lock
.lock
);
701 pthread_mutex_unlock(&ms_global
.warmup_lock
.lock
);
703 ms_global
.finish_warmup
= true;
705 /* running in "run time" mode, user specify run time */
706 if (ms_setting
.run_time
> 0) {
708 gettimeofday(&start_time
, NULL
);
713 if ((ms_setting
.stat_freq
> 0) && (second
% ms_setting
.stat_freq
== 0)
714 && (ms_stats
.active_conns
>= ms_setting
.nconns
) && (ms_stats
.active_conns
<= INT_MAX
))
716 ms_print_statistics(second
);
719 if (ms_setting
.run_time
<= second
) {
720 ms_global
.time_out
= true;
724 /* all connections disconnect */
725 if ((second
> 5) && (ms_stats
.active_conns
== 0)) {
729 gettimeofday(&end_time
, NULL
);
730 sleep(1); /* wait all threads clean up */
732 /* running in "execute number" mode, user specify execute number */
733 gettimeofday(&start_time
, NULL
);
736 * We loop until we know that all connects have cleaned up.
738 pthread_mutex_lock(&ms_global
.run_lock
.lock
);
739 while (ms_global
.run_lock
.count
< ms_setting
.nconns
) {
740 pthread_cond_wait(&ms_global
.run_lock
.cond
, &ms_global
.run_lock
.lock
);
742 pthread_mutex_unlock(&ms_global
.run_lock
.lock
);
744 gettimeofday(&end_time
, NULL
);
747 ms_print_memaslap_stats(&start_time
, &end_time
);
748 } /* ms_monitor_slap_mode */
750 /* the main function */
751 int main(int argc
, char *argv
[]) {
752 srandom((unsigned int) time(NULL
));
753 ms_global_struct_init();
756 ms_setting_init_pre();
757 ms_options_parse(argc
, argv
);
758 if (ms_check_para()) {
759 ms_help_command(PROGRAM_NAME
, PROGRAM_DESCRIPTION
);
762 ms_setting_init_post();
766 /* waiting work thread complete its task */
767 ms_monitor_slap_mode();
771 ms_global_struct_destroy();
772 ms_setting_cleanup();