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"
24 #if defined(HAVE_SYS_TIME_H)
25 # include <sys/time.h>
28 #if defined(HAVE_TIME_H)
32 #include "ms_sigsegv.h"
33 #include "ms_setting.h"
34 #include "ms_thread.h"
36 /* global structure */
37 ms_global_t ms_global
;
39 /* global stats information structure */
42 /* global statistic structure */
43 ms_statistic_t ms_statistic
;
45 #define PROGRAM_NAME "memaslap"
46 #define PROGRAM_DESCRIPTION "Generates workload against memcached servers."
49 /* For some odd reason the option struct on solaris defines the argument
50 * as char* and not const char*
52 # define OPTIONSTRING char *
54 # define OPTIONSTRING const char *
58 static struct option long_options
[] = {
59 {(OPTIONSTRING
) "servers", required_argument
, NULL
, OPT_SERVERS
},
60 {(OPTIONSTRING
) "threads", required_argument
, NULL
, OPT_THREAD_NUMBER
},
61 {(OPTIONSTRING
) "concurrency", required_argument
, NULL
, OPT_CONCURRENCY
},
62 {(OPTIONSTRING
) "conn_sock", required_argument
, NULL
, OPT_SOCK_PER_CONN
},
63 {(OPTIONSTRING
) "execute_number", required_argument
, NULL
, OPT_EXECUTE_NUMBER
},
64 {(OPTIONSTRING
) "time", required_argument
, NULL
, OPT_TIME
},
65 {(OPTIONSTRING
) "cfg_cmd", required_argument
, NULL
, OPT_CONFIG_CMD
},
66 {(OPTIONSTRING
) "win_size", required_argument
, NULL
, OPT_WINDOW_SIZE
},
67 {(OPTIONSTRING
) "fixed_size", required_argument
, NULL
, OPT_FIXED_LTH
},
68 {(OPTIONSTRING
) "verify", required_argument
, NULL
, OPT_VERIFY
},
69 {(OPTIONSTRING
) "division", required_argument
, NULL
, OPT_GETS_DIVISION
},
70 {(OPTIONSTRING
) "stat_freq", required_argument
, NULL
, OPT_STAT_FREQ
},
71 {(OPTIONSTRING
) "exp_verify", required_argument
, NULL
, OPT_EXPIRE
},
72 {(OPTIONSTRING
) "overwrite", required_argument
, NULL
, OPT_OVERWRITE
},
73 {(OPTIONSTRING
) "reconnect", no_argument
, NULL
, OPT_RECONNECT
},
74 {(OPTIONSTRING
) "udp", no_argument
, NULL
, OPT_UDP
},
75 {(OPTIONSTRING
) "facebook", no_argument
, NULL
, OPT_FACEBOOK_TEST
},
76 {(OPTIONSTRING
) "binary", no_argument
, NULL
, OPT_BINARY_PROTOCOL
},
77 {(OPTIONSTRING
) "tps", required_argument
, NULL
, OPT_TPS
},
78 {(OPTIONSTRING
) "rep_write", required_argument
, NULL
, OPT_REP_WRITE_SRV
},
79 {(OPTIONSTRING
) "verbose", no_argument
, NULL
, OPT_VERBOSE
},
80 {(OPTIONSTRING
) "help", no_argument
, NULL
, OPT_HELP
},
81 {(OPTIONSTRING
) "version", no_argument
, NULL
, OPT_VERSION
},
86 static void ms_sync_lock_init(void);
87 static void ms_sync_lock_destroy(void);
88 static void ms_global_struct_init(void);
89 static void ms_global_struct_destroy(void);
90 static void ms_version_command(const char *command_name
);
91 static const char *ms_lookup_help(ms_options_t option
);
92 static int64_t ms_parse_time(void);
93 static int64_t ms_parse_size(void);
94 static void ms_options_parse(int argc
, char *argv
[]);
95 static int ms_check_para(void);
96 static void ms_statistic_init(void);
97 static void ms_stats_init(void);
98 static void ms_print_statistics(int in_time
);
99 static void ms_print_memaslap_stats(struct timeval
*start_time
, struct timeval
*end_time
);
100 static void ms_monitor_slap_mode(void);
103 * output the help information
105 * @param command_name, the string of this process
106 * @param description, description of this process
107 * @param long_options, global options array
109 static void ms_help_command(const char *command_name
, const char *description
) {
110 char *help_message
= NULL
;
112 printf("%s v%u.%u\n", command_name
, 1U, 0U);
113 printf(" %s\n\n", description
);
115 " memaslap -hV | -s servers [-F config_file] [-t time | -x exe_num] [...]\n\n"
118 for (int x
= 0; long_options
[x
].name
; x
++) {
119 printf(" -%c, --%s%c\n", long_options
[x
].val
, long_options
[x
].name
,
120 long_options
[x
].has_arg
? '=' : ' ');
122 if ((help_message
= (char *) ms_lookup_help(long_options
[x
].val
))) {
123 printf(" %s\n", help_message
);
127 printf("\nExamples:\n"
128 " memaslap -s 127.0.0.1:11211 -S 5s\n"
129 " memaslap -s 127.0.0.1:11211 -t 2m -v 0.2 -e 0.05 -b\n"
130 " memaslap -s 127.0.0.1:11211 -F config -t 2m -w 40k -S 20s -o 0.2\n"
131 " memaslap -s 127.0.0.1:11211 -F config -t 2m -T 4 -c 128 -d 20 -P 40k\n"
132 " memaslap -s 127.0.0.1:11211 -F config -t 2m -d 50 -a -n 40\n"
133 " memaslap -s 127.0.0.1:11211,127.0.0.1:11212 -F config -t 2m\n"
134 " memaslap -s 127.0.0.1:11211,127.0.0.1:11212 -F config -t 2m -p 2\n\n");
135 } /* ms_help_command */
137 /* initialize the global locks */
138 static void ms_sync_lock_init() {
139 ms_global
.init_lock
.count
= 0;
140 pthread_mutex_init(&ms_global
.init_lock
.lock
, NULL
);
141 pthread_cond_init(&ms_global
.init_lock
.cond
, NULL
);
143 ms_global
.warmup_lock
.count
= 0;
144 pthread_mutex_init(&ms_global
.warmup_lock
.lock
, NULL
);
145 pthread_cond_init(&ms_global
.warmup_lock
.cond
, NULL
);
147 ms_global
.run_lock
.count
= 0;
148 pthread_mutex_init(&ms_global
.run_lock
.lock
, NULL
);
149 pthread_cond_init(&ms_global
.run_lock
.cond
, NULL
);
151 pthread_mutex_init(&ms_global
.quit_mutex
, NULL
);
152 pthread_mutex_init(&ms_global
.seq_mutex
, NULL
);
153 } /* ms_sync_lock_init */
155 /* destroy the global locks */
156 static void ms_sync_lock_destroy() {
157 pthread_mutex_destroy(&ms_global
.init_lock
.lock
);
158 pthread_cond_destroy(&ms_global
.init_lock
.cond
);
160 pthread_mutex_destroy(&ms_global
.warmup_lock
.lock
);
161 pthread_cond_destroy(&ms_global
.warmup_lock
.cond
);
163 pthread_mutex_destroy(&ms_global
.run_lock
.lock
);
164 pthread_cond_destroy(&ms_global
.run_lock
.cond
);
166 pthread_mutex_destroy(&ms_global
.quit_mutex
);
167 pthread_mutex_destroy(&ms_global
.seq_mutex
);
169 if (ms_setting
.stat_freq
> 0) {
170 pthread_mutex_destroy(&ms_statistic
.stat_mutex
);
172 } /* ms_sync_lock_destroy */
174 /* initialize the global structure */
175 static void ms_global_struct_init() {
177 ms_global
.finish_warmup
= false;
178 ms_global
.time_out
= false;
181 /* destroy the global structure */
182 static void ms_global_struct_destroy() {
183 ms_sync_lock_destroy();
187 * output the version information
189 * @param command_name, the string of this process
191 static void ms_version_command(const char *command_name
) {
192 printf("%s v%u.%u\n", command_name
, 1U, 0U);
197 * get the description of the option
199 * @param option, option of command line
201 * @return char*, description of the command option
203 static const char *ms_lookup_help(ms_options_t option
) {
206 return "List one or more servers to connect. Servers count must be less than\n"
207 " threads count. e.g.: --servers=localhost:1234,localhost:11211";
210 return "Display the version of the application and then exit.";
213 return "Display this message and then exit.";
215 case OPT_EXECUTE_NUMBER
:
216 return "Number of operations(get and set) to execute for the\n"
217 " given test. Default 1000000.";
219 case OPT_THREAD_NUMBER
:
220 return "Number of threads to startup, better equal to CPU numbers. Default 8.";
222 case OPT_CONCURRENCY
:
223 return "Number of concurrency to simulate with load. Default 128.";
226 return "Fixed length of value.";
229 return "The proportion of date verification, e.g.: --verify=0.01";
231 case OPT_GETS_DIVISION
:
232 return "Number of keys to multi-get once. Default 1, means single get.";
235 return "How long the test to run, suffix: s-seconds, m-minutes, h-hours,\n"
236 " d-days e.g.: --time=2h.";
239 return "Load the configure file to get command,key and value distribution list.";
241 case OPT_WINDOW_SIZE
:
242 return "Task window size of each concurrency, suffix: K, M e.g.: --win_size=10k.\n"
246 return "UDP support, by default memaslap uses TCP; TCP port and UDP port of\n"
247 " server must be same.";
250 return "The proportion of objects with expire time, e.g.: --exp_verify=0.01.\n"
251 " Default no object with expire time";
254 return "The proportion of objects need overwrite, e.g.: --overwrite=0.01.\n"
255 " Default never overwrite object.";
258 return "Frequency of dumping statistic information. suffix: s-seconds,\n"
259 " m-minutes, e.g.: --resp_freq=10s.";
261 case OPT_SOCK_PER_CONN
:
262 return "Number of TCP socks per concurrency. Default 1.";
265 return "Reconnect support, when connection is closed it will be reconnected.";
268 return "Whether it outputs detailed information when verification fails.";
270 case OPT_FACEBOOK_TEST
:
271 return "Whether it enables facebook test feature, set with TCP and multi-get with UDP.";
273 case OPT_BINARY_PROTOCOL
:
274 return "Whether it enables binary protocol. Default with ASCII protocol.";
277 return "Expected throughput, suffix: K, e.g.: --tps=10k.";
279 case OPT_REP_WRITE_SRV
:
280 return "The first nth servers can write data, e.g.: --rep_write=2.";
283 return "Forgot to document this option :)";
285 } /* ms_lookup_help */
287 /* used to parse the time string */
288 static int64_t ms_parse_time() {
290 char unit
= optarg
[strlen(optarg
) - 1];
292 optarg
[strlen(optarg
) - 1] = '\0';
318 } /* ms_parse_time */
320 /* used to parse the size string */
321 static int64_t ms_parse_size() {
323 char unit
= optarg
[strlen(optarg
) - 1];
325 optarg
[strlen(optarg
) - 1] = '\0';
327 ret
= strtoll(optarg
, (char **) NULL
, 10);
329 fprintf(stderr
, "strtoll(optarg,..): %s\n", strerror(errno
));
346 ret
*= 1024 * 1024 * 1024;
355 } /* ms_parse_size */
357 /* used to parse the options of command line */
358 static void ms_options_parse(int argc
, char *argv
[]) {
359 int option_index
= 0;
362 while ((option_rv
= getopt_long(argc
, argv
,
363 "VhURbaBs:x:T:c:X:v:d:"
364 "t:S:F:w:e:o:n:P:p:",
365 long_options
, &option_index
))
372 case OPT_VERSION
: /* --version or -V */
373 ms_version_command(PROGRAM_NAME
);
376 case OPT_HELP
: /* --help or -h */
377 ms_help_command(PROGRAM_NAME
, PROGRAM_DESCRIPTION
);
381 case OPT_SERVERS
: /* --servers or -s */
382 ms_setting
.srv_str
= strdup(optarg
);
385 case OPT_CONCURRENCY
: /* --concurrency or -c */
387 ms_setting
.nconns
= (uint32_t) strtoul(optarg
, (char **) NULL
, 10);
388 if (ms_setting
.nconns
<= 0 || errno
) {
389 fprintf(stderr
, "Concurrency must be greater than 0.:-)\n");
394 case OPT_EXECUTE_NUMBER
: /* --execute_number or -x */
396 ms_setting
.exec_num
= (int) strtol(optarg
, (char **) NULL
, 10);
397 if (ms_setting
.exec_num
<= 0 || errno
) {
398 fprintf(stderr
, "Execute number must be greater than 0.:-)\n");
403 case OPT_THREAD_NUMBER
: /* --threads or -T */
405 ms_setting
.nthreads
= (uint32_t) strtoul(optarg
, (char **) NULL
, 10);
406 if (ms_setting
.nthreads
<= 0 || errno
) {
407 fprintf(stderr
, "Threads number must be greater than 0.:-)\n");
412 case OPT_FIXED_LTH
: /* --fixed_size or -X */
414 ms_setting
.fixed_value_size
= (size_t) strtoull(optarg
, (char **) NULL
, 10);
415 if ((ms_setting
.fixed_value_size
<= 0 || errno
)
416 || (ms_setting
.fixed_value_size
> MAX_VALUE_SIZE
))
418 fprintf(stderr
, "Value size must be between 0 and 1M.:-)\n");
423 case OPT_VERIFY
: /* --verify or -v */
424 ms_setting
.verify_percent
= atof(optarg
);
425 if ((ms_setting
.verify_percent
<= 0) || (ms_setting
.verify_percent
> 1.0)) {
427 "Data verification rate must be "
428 "greater than 0 and less than 1.0. :-)\n");
433 case OPT_GETS_DIVISION
: /* --division or -d */
435 ms_setting
.mult_key_num
= (int) strtol(optarg
, (char **) NULL
, 10);
436 if (ms_setting
.mult_key_num
<= 0 || errno
) {
437 fprintf(stderr
, "Multi-get key number must be greater than 0.:-)\n");
442 case OPT_TIME
: /* --time or -t */
443 ms_setting
.run_time
= (int) ms_parse_time();
444 if (ms_setting
.run_time
== -1) {
446 "Please specify the run time. :-)\n"
447 "'s' for second, 'm' for minute, 'h' for hour, "
448 "'d' for day. e.g.: --time=24h (means 24 hours).\n");
452 if (ms_setting
.run_time
== 0) {
453 fprintf(stderr
, "Running time can not be 0. :-)\n");
458 case OPT_CONFIG_CMD
: /* --cfg_cmd or -F */
459 ms_setting
.cfg_file
= strdup(optarg
);
462 case OPT_WINDOW_SIZE
: /* --win_size or -w */
463 ms_setting
.win_size
= (size_t) ms_parse_size();
464 if (ms_setting
.win_size
== (size_t) -1) {
466 "Please specify the item window size. :-)\n"
467 "e.g.: --win_size=10k (means 10k task window size).\n");
472 case OPT_UDP
: /* --udp or -U*/
473 ms_setting
.udp
= true;
476 case OPT_EXPIRE
: /* --exp_verify or -e */
477 ms_setting
.exp_ver_per
= atof(optarg
);
478 if ((ms_setting
.exp_ver_per
<= 0) || (ms_setting
.exp_ver_per
> 1.0)) {
480 "Expire time verification rate must be "
481 "greater than 0 and less than 1.0. :-)\n");
486 case OPT_OVERWRITE
: /* --overwrite or -o */
487 ms_setting
.overwrite_percent
= atof(optarg
);
488 if ((ms_setting
.overwrite_percent
<= 0) || (ms_setting
.overwrite_percent
> 1.0)) {
490 "Objects overwrite rate must be "
491 "greater than 0 and less than 1.0. :-)\n");
496 case OPT_STAT_FREQ
: /* --stat_freq or -S */
497 ms_setting
.stat_freq
= (int) ms_parse_time();
498 if (ms_setting
.stat_freq
== -1) {
500 "Please specify the frequency of dumping "
501 "statistic information. :-)\n"
502 "'s' for second, 'm' for minute, 'h' for hour, "
503 "'d' for day. e.g.: --time=24h (means 24 hours).\n");
507 if (ms_setting
.stat_freq
== 0) {
509 "The frequency of dumping statistic information "
510 "can not be 0. :-)\n");
515 case OPT_SOCK_PER_CONN
: /* --conn_sock or -n */
517 ms_setting
.sock_per_conn
= (uint32_t) strtoul(optarg
, (char **) NULL
, 10);
518 if (ms_setting
.sock_per_conn
<= 0 || errno
) {
520 "Number of socks of each concurrency "
521 "must be greater than 0.:-)\n");
526 case OPT_RECONNECT
: /* --reconnect or -R */
527 ms_setting
.reconnect
= true;
530 case OPT_VERBOSE
: /* --verbose or -b */
531 ms_setting
.verbose
= true;
534 case OPT_FACEBOOK_TEST
: /* --facebook or -a */
535 ms_setting
.facebook_test
= true;
538 case OPT_BINARY_PROTOCOL
: /* --binary or -B */
539 ms_setting
.binary_prot_
= true;
542 case OPT_TPS
: /* --tps or -P */
543 ms_setting
.expected_tps
= (int) ms_parse_size();
544 if (ms_setting
.expected_tps
== -1) {
546 "Please specify the item expected throughput. :-)\n"
547 "e.g.: --tps=10k (means 10k throughput).\n");
552 case OPT_REP_WRITE_SRV
: /* --rep_write or -p */
554 ms_setting
.rep_write_srv
= (uint32_t) strtoul(optarg
, (char **) NULL
, 10);
555 if (ms_setting
.rep_write_srv
<= 0 || errno
) {
557 "Number of replication writing server must be greater "
564 /* getopt_long already printed an error message. */
571 } /* ms_options_parse */
573 static int ms_check_para() {
574 if (ms_setting
.srv_str
== NULL
) {
577 if ((temp
= getenv("MEMCACHED_SERVERS"))) {
578 ms_setting
.srv_str
= strdup(temp
);
580 fprintf(stderr
, "No servers provided\n\n");
585 if (ms_setting
.nconns
% (uint32_t) ms_setting
.nthreads
) {
586 fprintf(stderr
, "Concurrency must be the multiples of threads count.\n");
590 if (ms_setting
.win_size
% UNIT_ITEMS_COUNT
) {
591 fprintf(stderr
, "Window size must be the multiples of 1024.\n\n");
596 } /* ms_check_para */
598 /* initialize the statistic structure */
599 static void ms_statistic_init() {
600 pthread_mutex_init(&ms_statistic
.stat_mutex
, NULL
);
601 ms_init_stats(&ms_statistic
.get_stat
, "Get");
602 ms_init_stats(&ms_statistic
.set_stat
, "Set");
603 ms_init_stats(&ms_statistic
.total_stat
, "Total");
604 } /* ms_statistic_init */
606 /* initialize the global state structure */
607 static void ms_stats_init() {
608 memset(&ms_stats
, 0, sizeof(ms_stats_t
));
609 if (ms_setting
.stat_freq
> 0) {
612 } /* ms_stats_init */
614 /* use to output the statistic */
615 static void ms_print_statistics(int in_time
) {
616 int obj_size
= (int) (ms_setting
.avg_key_size
+ ms_setting
.avg_val_size
);
618 printf("\033[1;1H\033[2J\n");
619 ms_dump_format_stats(&ms_statistic
.get_stat
, in_time
, ms_setting
.stat_freq
, obj_size
);
620 ms_dump_format_stats(&ms_statistic
.set_stat
, in_time
, ms_setting
.stat_freq
, obj_size
);
621 ms_dump_format_stats(&ms_statistic
.total_stat
, in_time
, ms_setting
.stat_freq
, obj_size
);
622 } /* ms_print_statistics */
624 /* used to print the states of memaslap */
625 static void ms_print_memaslap_stats(struct timeval
*start_time
, struct timeval
*end_time
) {
629 pos
+= snprintf(pos
, sizeof(buf
), "cmd_get: %lu\n", (unsigned long) ms_stats
.cmd_get
);
630 pos
+= snprintf(pos
, sizeof(buf
) - (size_t)(pos
- buf
), "cmd_set: %lu\n",
631 (unsigned long) ms_stats
.cmd_set
);
632 pos
+= snprintf(pos
, sizeof(buf
) - (size_t)(pos
- buf
), "get_misses: %lu\n",
633 (unsigned long) ms_stats
.get_misses
);
635 if (ms_setting
.verify_percent
> 0) {
636 pos
+= snprintf(pos
, sizeof(buf
) - (size_t)(pos
- buf
), "verify_misses: %lu\n",
637 (unsigned long) ms_stats
.vef_miss
);
638 pos
+= snprintf(pos
, sizeof(buf
) - (size_t)(pos
- buf
), "verify_failed: %lu\n",
639 (unsigned long) ms_stats
.vef_failed
);
642 if (ms_setting
.exp_ver_per
> 0) {
643 pos
+= snprintf(pos
, sizeof(buf
) - (size_t)(pos
- buf
), "expired_get: %lu\n",
644 (unsigned long) ms_stats
.exp_get
);
645 pos
+= snprintf(pos
, sizeof(buf
) - (size_t)(pos
- buf
), "unexpired_unget: %lu\n",
646 (unsigned long) ms_stats
.unexp_unget
);
649 pos
+= snprintf(pos
, sizeof(buf
) - (size_t)(pos
- buf
), "written_bytes: %lu\n",
650 (unsigned long) ms_stats
.bytes_written
);
651 pos
+= snprintf(pos
, sizeof(buf
) - (size_t)(pos
- buf
), "read_bytes: %lu\n",
652 (unsigned long) ms_stats
.bytes_read
);
653 pos
+= snprintf(pos
, sizeof(buf
) - (size_t)(pos
- buf
), "object_bytes: %lu\n",
654 (unsigned long) ms_stats
.obj_bytes
);
656 if (ms_setting
.udp
|| ms_setting
.facebook_test
) {
657 pos
+= snprintf(pos
, sizeof(buf
) - (size_t)(pos
- buf
), "packet_disorder: %lu\n",
658 (unsigned long) ms_stats
.pkt_disorder
);
659 pos
+= snprintf(pos
, sizeof(buf
) - (size_t)(pos
- buf
), "packet_drop: %lu\n",
660 (unsigned long) ms_stats
.pkt_drop
);
661 pos
+= snprintf(pos
, sizeof(buf
) - (size_t)(pos
- buf
), "udp_timeout: %lu\n",
662 (unsigned long) ms_stats
.udp_timeout
);
665 if (ms_setting
.stat_freq
> 0) {
666 ms_dump_stats(&ms_statistic
.get_stat
);
667 ms_dump_stats(&ms_statistic
.set_stat
);
668 ms_dump_stats(&ms_statistic
.total_stat
);
671 int64_t time_diff
= ms_time_diff(start_time
, end_time
);
672 pos
+= snprintf(pos
, sizeof(buf
) - (size_t)(pos
- buf
),
673 "\nRun time: %.1fs Ops: %llu TPS: %.0Lf Net_rate: %.1fM/s\n",
674 (double) time_diff
/ 1000000,
675 (unsigned long long) (ms_stats
.cmd_get
+ ms_stats
.cmd_set
),
676 (ms_stats
.cmd_get
+ ms_stats
.cmd_set
) / ((long double) time_diff
/ 1000000),
677 (double) (ms_stats
.bytes_written
+ ms_stats
.bytes_read
) / 1024 / 1024
678 / ((double) time_diff
/ 1000000));
679 assert(pos
<= (buf
+ sizeof(buf
)));
681 fwrite(buf
, 1, pos
- buf
, stdout
);
683 } /* ms_print_memaslap_stats */
685 /* the loop of the main thread, wait the work threads to complete */
686 static void ms_monitor_slap_mode() {
687 struct timeval start_time
, end_time
;
689 /* Wait all the threads complete initialization. */
690 pthread_mutex_lock(&ms_global
.init_lock
.lock
);
691 while (ms_global
.init_lock
.count
< ms_setting
.nthreads
) {
692 pthread_cond_wait(&ms_global
.init_lock
.cond
, &ms_global
.init_lock
.lock
);
694 pthread_mutex_unlock(&ms_global
.init_lock
.lock
);
696 /* only when there is no set operation it need warm up */
697 if (ms_setting
.cmd_distr
[CMD_SET
].cmd_prop
< PROP_ERROR
) {
698 /* Wait all the connects complete warm up. */
699 pthread_mutex_lock(&ms_global
.warmup_lock
.lock
);
700 while (ms_global
.warmup_lock
.count
< ms_setting
.nconns
) {
701 pthread_cond_wait(&ms_global
.warmup_lock
.cond
, &ms_global
.warmup_lock
.lock
);
703 pthread_mutex_unlock(&ms_global
.warmup_lock
.lock
);
705 ms_global
.finish_warmup
= true;
707 /* running in "run time" mode, user specify run time */
708 if (ms_setting
.run_time
> 0) {
710 gettimeofday(&start_time
, NULL
);
715 if ((ms_setting
.stat_freq
> 0) && (second
% ms_setting
.stat_freq
== 0)
716 && (ms_stats
.active_conns
>= ms_setting
.nconns
) && (ms_stats
.active_conns
<= INT_MAX
))
718 ms_print_statistics(second
);
721 if (ms_setting
.run_time
<= second
) {
722 ms_global
.time_out
= true;
726 /* all connections disconnect */
727 if ((second
> 5) && (ms_stats
.active_conns
== 0)) {
731 gettimeofday(&end_time
, NULL
);
732 sleep(1); /* wait all threads clean up */
734 /* running in "execute number" mode, user specify execute number */
735 gettimeofday(&start_time
, NULL
);
738 * We loop until we know that all connects have cleaned up.
740 pthread_mutex_lock(&ms_global
.run_lock
.lock
);
741 while (ms_global
.run_lock
.count
< ms_setting
.nconns
) {
742 pthread_cond_wait(&ms_global
.run_lock
.cond
, &ms_global
.run_lock
.lock
);
744 pthread_mutex_unlock(&ms_global
.run_lock
.lock
);
746 gettimeofday(&end_time
, NULL
);
749 ms_print_memaslap_stats(&start_time
, &end_time
);
750 } /* ms_monitor_slap_mode */
752 /* the main function */
753 int main(int argc
, char *argv
[]) {
754 srandom((unsigned int) time(NULL
));
755 ms_global_struct_init();
758 ms_setting_init_pre();
759 ms_options_parse(argc
, argv
);
760 if (ms_check_para()) {
761 ms_help_command(PROGRAM_NAME
, PROGRAM_DESCRIPTION
);
764 ms_setting_init_post();
768 /* waiting work thread complete its task */
769 ms_monitor_slap_mode();
773 ms_global_struct_destroy();
774 ms_setting_cleanup();