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_atomic.h"
33 #include "ms_sigsegv.h"
34 #include "ms_setting.h"
35 #include "ms_thread.h"
37 /* global structure */
38 ms_global_t ms_global
;
40 /* global stats information structure */
43 /* global statistic structure */
44 ms_statistic_t ms_statistic
;
46 #define PROGRAM_NAME "memaslap"
47 #define PROGRAM_DESCRIPTION "Generates workload against memcached servers."
50 /* For some odd reason the option struct on solaris defines the argument
51 * as char* and not const char*
53 # define OPTIONSTRING char *
55 # define OPTIONSTRING const char *
59 static struct option long_options
[] = {
60 {(OPTIONSTRING
) "servers", required_argument
, NULL
, OPT_SERVERS
},
61 {(OPTIONSTRING
) "threads", required_argument
, NULL
, OPT_THREAD_NUMBER
},
62 {(OPTIONSTRING
) "concurrency", required_argument
, NULL
, OPT_CONCURRENCY
},
63 {(OPTIONSTRING
) "conn_sock", required_argument
, NULL
, OPT_SOCK_PER_CONN
},
64 {(OPTIONSTRING
) "execute_number", required_argument
, NULL
, OPT_EXECUTE_NUMBER
},
65 {(OPTIONSTRING
) "time", required_argument
, NULL
, OPT_TIME
},
66 {(OPTIONSTRING
) "cfg_cmd", required_argument
, NULL
, OPT_CONFIG_CMD
},
67 {(OPTIONSTRING
) "win_size", required_argument
, NULL
, OPT_WINDOW_SIZE
},
68 {(OPTIONSTRING
) "fixed_size", required_argument
, NULL
, OPT_FIXED_LTH
},
69 {(OPTIONSTRING
) "verify", required_argument
, NULL
, OPT_VERIFY
},
70 {(OPTIONSTRING
) "division", required_argument
, NULL
, OPT_GETS_DIVISION
},
71 {(OPTIONSTRING
) "stat_freq", required_argument
, NULL
, OPT_STAT_FREQ
},
72 {(OPTIONSTRING
) "exp_verify", required_argument
, NULL
, OPT_EXPIRE
},
73 {(OPTIONSTRING
) "overwrite", required_argument
, NULL
, OPT_OVERWRITE
},
74 {(OPTIONSTRING
) "reconnect", no_argument
, NULL
, OPT_RECONNECT
},
75 {(OPTIONSTRING
) "udp", no_argument
, NULL
, OPT_UDP
},
76 {(OPTIONSTRING
) "facebook", no_argument
, NULL
, OPT_FACEBOOK_TEST
},
77 {(OPTIONSTRING
) "binary", no_argument
, NULL
, OPT_BINARY_PROTOCOL
},
78 {(OPTIONSTRING
) "tps", required_argument
, NULL
, OPT_TPS
},
79 {(OPTIONSTRING
) "rep_write", required_argument
, NULL
, OPT_REP_WRITE_SRV
},
80 {(OPTIONSTRING
) "verbose", no_argument
, NULL
, OPT_VERBOSE
},
81 {(OPTIONSTRING
) "help", no_argument
, NULL
, OPT_HELP
},
82 {(OPTIONSTRING
) "version", no_argument
, NULL
, OPT_VERSION
},
87 static void ms_sync_lock_init(void);
88 static void ms_sync_lock_destroy(void);
89 static void ms_global_struct_init(void);
90 static void ms_global_struct_destroy(void);
91 static void ms_version_command(const char *command_name
);
92 static const char *ms_lookup_help(ms_options_t option
);
93 static int64_t ms_parse_time(void);
94 static int64_t ms_parse_size(void);
95 static void ms_options_parse(int argc
, char *argv
[]);
96 static int ms_check_para(void);
97 static void ms_statistic_init(void);
98 static void ms_stats_init(void);
99 static void ms_print_statistics(int in_time
);
100 static void ms_print_memaslap_stats(struct timeval
*start_time
, struct timeval
*end_time
);
101 static void ms_monitor_slap_mode(void);
104 * output the help information
106 * @param command_name, the string of this process
107 * @param description, description of this process
108 * @param long_options, global options array
110 static void ms_help_command(const char *command_name
, const char *description
) {
111 char *help_message
= NULL
;
113 printf("%s v%u.%u\n", command_name
, 1U, 0U);
114 printf(" %s\n\n", description
);
116 " memaslap -hV | -s servers [-F config_file] [-t time | -x exe_num] [...]\n\n"
119 for (int x
= 0; long_options
[x
].name
; x
++) {
120 printf(" -%c, --%s%c\n", long_options
[x
].val
, long_options
[x
].name
,
121 long_options
[x
].has_arg
? '=' : ' ');
123 if ((help_message
= (char *) ms_lookup_help(long_options
[x
].val
))) {
124 printf(" %s\n", help_message
);
128 printf("\nExamples:\n"
129 " memaslap -s 127.0.0.1:11211 -S 5s\n"
130 " memaslap -s 127.0.0.1:11211 -t 2m -v 0.2 -e 0.05 -b\n"
131 " memaslap -s 127.0.0.1:11211 -F config -t 2m -w 40k -S 20s -o 0.2\n"
132 " memaslap -s 127.0.0.1:11211 -F config -t 2m -T 4 -c 128 -d 20 -P 40k\n"
133 " memaslap -s 127.0.0.1:11211 -F config -t 2m -d 50 -a -n 40\n"
134 " memaslap -s 127.0.0.1:11211,127.0.0.1:11212 -F config -t 2m\n"
135 " memaslap -s 127.0.0.1:11211,127.0.0.1:11212 -F config -t 2m -p 2\n\n");
136 } /* ms_help_command */
138 /* initialize the global locks */
139 static void ms_sync_lock_init() {
140 ms_global
.init_lock
.count
= 0;
141 pthread_mutex_init(&ms_global
.init_lock
.lock
, NULL
);
142 pthread_cond_init(&ms_global
.init_lock
.cond
, NULL
);
144 ms_global
.warmup_lock
.count
= 0;
145 pthread_mutex_init(&ms_global
.warmup_lock
.lock
, NULL
);
146 pthread_cond_init(&ms_global
.warmup_lock
.cond
, NULL
);
148 ms_global
.run_lock
.count
= 0;
149 pthread_mutex_init(&ms_global
.run_lock
.lock
, NULL
);
150 pthread_cond_init(&ms_global
.run_lock
.cond
, NULL
);
152 pthread_mutex_init(&ms_global
.quit_mutex
, NULL
);
153 pthread_mutex_init(&ms_global
.seq_mutex
, NULL
);
154 } /* ms_sync_lock_init */
156 /* destroy the global locks */
157 static void ms_sync_lock_destroy() {
158 pthread_mutex_destroy(&ms_global
.init_lock
.lock
);
159 pthread_cond_destroy(&ms_global
.init_lock
.cond
);
161 pthread_mutex_destroy(&ms_global
.warmup_lock
.lock
);
162 pthread_cond_destroy(&ms_global
.warmup_lock
.cond
);
164 pthread_mutex_destroy(&ms_global
.run_lock
.lock
);
165 pthread_cond_destroy(&ms_global
.run_lock
.cond
);
167 pthread_mutex_destroy(&ms_global
.quit_mutex
);
168 pthread_mutex_destroy(&ms_global
.seq_mutex
);
170 if (ms_setting
.stat_freq
> 0) {
171 pthread_mutex_destroy(&ms_statistic
.stat_mutex
);
173 } /* ms_sync_lock_destroy */
175 /* initialize the global structure */
176 static void ms_global_struct_init() {
178 ms_global
.finish_warmup
= false;
179 ms_global
.time_out
= false;
182 /* destroy the global structure */
183 static void ms_global_struct_destroy() {
184 ms_sync_lock_destroy();
188 * output the version information
190 * @param command_name, the string of this process
192 static void ms_version_command(const char *command_name
) {
193 printf("%s v%u.%u\n", command_name
, 1U, 0U);
198 * get the description of the option
200 * @param option, option of command line
202 * @return char*, description of the command option
204 static const char *ms_lookup_help(ms_options_t option
) {
207 return "List one or more servers to connect. Servers count must be less than\n"
208 " threads count. e.g.: --servers=localhost:1234,localhost:11211";
211 return "Display the version of the application and then exit.";
214 return "Display this message and then exit.";
216 case OPT_EXECUTE_NUMBER
:
217 return "Number of operations(get and set) to execute for the\n"
218 " given test. Default 1000000.";
220 case OPT_THREAD_NUMBER
:
221 return "Number of threads to startup, better equal to CPU numbers. Default 8.";
223 case OPT_CONCURRENCY
:
224 return "Number of concurrency to simulate with load. Default 128.";
227 return "Fixed length of value.";
230 return "The proportion of date verification, e.g.: --verify=0.01";
232 case OPT_GETS_DIVISION
:
233 return "Number of keys to multi-get once. Default 1, means single get.";
236 return "How long the test to run, suffix: s-seconds, m-minutes, h-hours,\n"
237 " d-days e.g.: --time=2h.";
240 return "Load the configure file to get command,key and value distribution list.";
242 case OPT_WINDOW_SIZE
:
243 return "Task window size of each concurrency, suffix: K, M e.g.: --win_size=10k.\n"
247 return "UDP support, by default memaslap uses TCP; TCP port and UDP port of\n"
248 " server must be same.";
251 return "The proportion of objects with expire time, e.g.: --exp_verify=0.01.\n"
252 " Default no object with expire time";
255 return "The proportion of objects need overwrite, e.g.: --overwrite=0.01.\n"
256 " Default never overwrite object.";
259 return "Frequency of dumping statistic information. suffix: s-seconds,\n"
260 " m-minutes, e.g.: --resp_freq=10s.";
262 case OPT_SOCK_PER_CONN
:
263 return "Number of TCP socks per concurrency. Default 1.";
266 return "Reconnect support, when connection is closed it will be reconnected.";
269 return "Whether it outputs detailed information when verification fails.";
271 case OPT_FACEBOOK_TEST
:
272 return "Whether it enables facebook test feature, set with TCP and multi-get with UDP.";
274 case OPT_BINARY_PROTOCOL
:
275 return "Whether it enables binary protocol. Default with ASCII protocol.";
278 return "Expected throughput, suffix: K, e.g.: --tps=10k.";
280 case OPT_REP_WRITE_SRV
:
281 return "The first nth servers can write data, e.g.: --rep_write=2.";
284 return "Forgot to document this option :)";
286 } /* ms_lookup_help */
288 /* used to parse the time string */
289 static int64_t ms_parse_time() {
291 char unit
= optarg
[strlen(optarg
) - 1];
293 optarg
[strlen(optarg
) - 1] = '\0';
319 } /* ms_parse_time */
321 /* used to parse the size string */
322 static int64_t ms_parse_size() {
324 char unit
= optarg
[strlen(optarg
) - 1];
326 optarg
[strlen(optarg
) - 1] = '\0';
328 ret
= strtoll(optarg
, (char **) NULL
, 10);
330 fprintf(stderr
, "strtoll(optarg,..): %s\n", strerror(errno
));
347 ret
*= 1024 * 1024 * 1024;
356 } /* ms_parse_size */
358 /* used to parse the options of command line */
359 static void ms_options_parse(int argc
, char *argv
[]) {
360 int option_index
= 0;
363 while ((option_rv
= getopt_long(argc
, argv
,
364 "VhURbaBs:x:T:c:X:v:d:"
365 "t:S:F:w:e:o:n:P:p:",
366 long_options
, &option_index
))
373 case OPT_VERSION
: /* --version or -V */
374 ms_version_command(PROGRAM_NAME
);
377 case OPT_HELP
: /* --help or -h */
378 ms_help_command(PROGRAM_NAME
, PROGRAM_DESCRIPTION
);
382 case OPT_SERVERS
: /* --servers or -s */
383 ms_setting
.srv_str
= strdup(optarg
);
386 case OPT_CONCURRENCY
: /* --concurrency or -c */
388 ms_setting
.nconns
= (uint32_t) strtoul(optarg
, (char **) NULL
, 10);
389 if (ms_setting
.nconns
<= 0 || errno
) {
390 fprintf(stderr
, "Concurrency must be greater than 0.:-)\n");
395 case OPT_EXECUTE_NUMBER
: /* --execute_number or -x */
397 ms_setting
.exec_num
= (int) strtol(optarg
, (char **) NULL
, 10);
398 if (ms_setting
.exec_num
<= 0 || errno
) {
399 fprintf(stderr
, "Execute number must be greater than 0.:-)\n");
404 case OPT_THREAD_NUMBER
: /* --threads or -T */
406 ms_setting
.nthreads
= (uint32_t) strtoul(optarg
, (char **) NULL
, 10);
407 if (ms_setting
.nthreads
<= 0 || errno
) {
408 fprintf(stderr
, "Threads number must be greater than 0.:-)\n");
413 case OPT_FIXED_LTH
: /* --fixed_size or -X */
415 ms_setting
.fixed_value_size
= (size_t) strtoull(optarg
, (char **) NULL
, 10);
416 if ((ms_setting
.fixed_value_size
<= 0 || errno
)
417 || (ms_setting
.fixed_value_size
> MAX_VALUE_SIZE
))
419 fprintf(stderr
, "Value size must be between 0 and 1M.:-)\n");
424 case OPT_VERIFY
: /* --verify or -v */
425 ms_setting
.verify_percent
= atof(optarg
);
426 if ((ms_setting
.verify_percent
<= 0) || (ms_setting
.verify_percent
> 1.0)) {
428 "Data verification rate must be "
429 "greater than 0 and less than 1.0. :-)\n");
434 case OPT_GETS_DIVISION
: /* --division or -d */
436 ms_setting
.mult_key_num
= (int) strtol(optarg
, (char **) NULL
, 10);
437 if (ms_setting
.mult_key_num
<= 0 || errno
) {
438 fprintf(stderr
, "Multi-get key number must be greater than 0.:-)\n");
443 case OPT_TIME
: /* --time or -t */
444 ms_setting
.run_time
= (int) ms_parse_time();
445 if (ms_setting
.run_time
== -1) {
447 "Please specify the run time. :-)\n"
448 "'s' for second, 'm' for minute, 'h' for hour, "
449 "'d' for day. e.g.: --time=24h (means 24 hours).\n");
453 if (ms_setting
.run_time
== 0) {
454 fprintf(stderr
, "Running time can not be 0. :-)\n");
459 case OPT_CONFIG_CMD
: /* --cfg_cmd or -F */
460 ms_setting
.cfg_file
= strdup(optarg
);
463 case OPT_WINDOW_SIZE
: /* --win_size or -w */
464 ms_setting
.win_size
= (size_t) ms_parse_size();
465 if (ms_setting
.win_size
== (size_t) -1) {
467 "Please specify the item window size. :-)\n"
468 "e.g.: --win_size=10k (means 10k task window size).\n");
473 case OPT_UDP
: /* --udp or -U*/
474 ms_setting
.udp
= true;
477 case OPT_EXPIRE
: /* --exp_verify or -e */
478 ms_setting
.exp_ver_per
= atof(optarg
);
479 if ((ms_setting
.exp_ver_per
<= 0) || (ms_setting
.exp_ver_per
> 1.0)) {
481 "Expire time verification rate must be "
482 "greater than 0 and less than 1.0. :-)\n");
487 case OPT_OVERWRITE
: /* --overwrite or -o */
488 ms_setting
.overwrite_percent
= atof(optarg
);
489 if ((ms_setting
.overwrite_percent
<= 0) || (ms_setting
.overwrite_percent
> 1.0)) {
491 "Objects overwrite rate must be "
492 "greater than 0 and less than 1.0. :-)\n");
497 case OPT_STAT_FREQ
: /* --stat_freq or -S */
498 ms_setting
.stat_freq
= (int) ms_parse_time();
499 if (ms_setting
.stat_freq
== -1) {
501 "Please specify the frequency of dumping "
502 "statistic information. :-)\n"
503 "'s' for second, 'm' for minute, 'h' for hour, "
504 "'d' for day. e.g.: --time=24h (means 24 hours).\n");
508 if (ms_setting
.stat_freq
== 0) {
510 "The frequency of dumping statistic information "
511 "can not be 0. :-)\n");
516 case OPT_SOCK_PER_CONN
: /* --conn_sock or -n */
518 ms_setting
.sock_per_conn
= (uint32_t) strtoul(optarg
, (char **) NULL
, 10);
519 if (ms_setting
.sock_per_conn
<= 0 || errno
) {
521 "Number of socks of each concurrency "
522 "must be greater than 0.:-)\n");
527 case OPT_RECONNECT
: /* --reconnect or -R */
528 ms_setting
.reconnect
= true;
531 case OPT_VERBOSE
: /* --verbose or -b */
532 ms_setting
.verbose
= true;
535 case OPT_FACEBOOK_TEST
: /* --facebook or -a */
536 ms_setting
.facebook_test
= true;
539 case OPT_BINARY_PROTOCOL
: /* --binary or -B */
540 ms_setting
.binary_prot_
= true;
543 case OPT_TPS
: /* --tps or -P */
544 ms_setting
.expected_tps
= (int) ms_parse_size();
545 if (ms_setting
.expected_tps
== -1) {
547 "Please specify the item expected throughput. :-)\n"
548 "e.g.: --tps=10k (means 10k throughput).\n");
553 case OPT_REP_WRITE_SRV
: /* --rep_write or -p */
555 ms_setting
.rep_write_srv
= (uint32_t) strtoul(optarg
, (char **) NULL
, 10);
556 if (ms_setting
.rep_write_srv
<= 0 || errno
) {
558 "Number of replication writing server must be greater "
565 /* getopt_long already printed an error message. */
572 } /* ms_options_parse */
574 static int ms_check_para() {
575 if (ms_setting
.srv_str
== NULL
) {
578 if ((temp
= getenv("MEMCACHED_SERVERS"))) {
579 ms_setting
.srv_str
= strdup(temp
);
581 fprintf(stderr
, "No servers provided\n\n");
586 if (ms_setting
.nconns
% (uint32_t) ms_setting
.nthreads
) {
587 fprintf(stderr
, "Concurrency must be the multiples of threads count.\n");
591 if (ms_setting
.win_size
% UNIT_ITEMS_COUNT
) {
592 fprintf(stderr
, "Window size must be the multiples of 1024.\n\n");
597 } /* ms_check_para */
599 /* initialize the statistic structure */
600 static void ms_statistic_init() {
601 pthread_mutex_init(&ms_statistic
.stat_mutex
, NULL
);
602 ms_init_stats(&ms_statistic
.get_stat
, "Get");
603 ms_init_stats(&ms_statistic
.set_stat
, "Set");
604 ms_init_stats(&ms_statistic
.total_stat
, "Total");
605 } /* ms_statistic_init */
607 /* initialize the global state structure */
608 static void ms_stats_init() {
609 memset(&ms_stats
, 0, sizeof(ms_stats_t
));
610 if (ms_setting
.stat_freq
> 0) {
613 } /* ms_stats_init */
615 /* use to output the statistic */
616 static void ms_print_statistics(int in_time
) {
617 int obj_size
= (int) (ms_setting
.avg_key_size
+ ms_setting
.avg_val_size
);
619 printf("\033[1;1H\033[2J\n");
620 ms_dump_format_stats(&ms_statistic
.get_stat
, in_time
, ms_setting
.stat_freq
, obj_size
);
621 ms_dump_format_stats(&ms_statistic
.set_stat
, in_time
, ms_setting
.stat_freq
, obj_size
);
622 ms_dump_format_stats(&ms_statistic
.total_stat
, in_time
, ms_setting
.stat_freq
, obj_size
);
623 } /* ms_print_statistics */
625 /* used to print the states of memaslap */
626 static void ms_print_memaslap_stats(struct timeval
*start_time
, struct timeval
*end_time
) {
630 pos
+= snprintf(pos
, sizeof(buf
), "cmd_get: %lu\n", (unsigned long) ms_stats
.cmd_get
);
631 pos
+= snprintf(pos
, sizeof(buf
) - (size_t)(pos
- buf
), "cmd_set: %lu\n",
632 (unsigned long) ms_stats
.cmd_set
);
633 pos
+= snprintf(pos
, sizeof(buf
) - (size_t)(pos
- buf
), "get_misses: %lu\n",
634 (unsigned long) ms_stats
.get_misses
);
636 if (ms_setting
.verify_percent
> 0) {
637 pos
+= snprintf(pos
, sizeof(buf
) - (size_t)(pos
- buf
), "verify_misses: %lu\n",
638 (unsigned long) ms_stats
.vef_miss
);
639 pos
+= snprintf(pos
, sizeof(buf
) - (size_t)(pos
- buf
), "verify_failed: %lu\n",
640 (unsigned long) ms_stats
.vef_failed
);
643 if (ms_setting
.exp_ver_per
> 0) {
644 pos
+= snprintf(pos
, sizeof(buf
) - (size_t)(pos
- buf
), "expired_get: %lu\n",
645 (unsigned long) ms_stats
.exp_get
);
646 pos
+= snprintf(pos
, sizeof(buf
) - (size_t)(pos
- buf
), "unexpired_unget: %lu\n",
647 (unsigned long) ms_stats
.unexp_unget
);
650 pos
+= snprintf(pos
, sizeof(buf
) - (size_t)(pos
- buf
), "written_bytes: %lu\n",
651 (unsigned long) ms_stats
.bytes_written
);
652 pos
+= snprintf(pos
, sizeof(buf
) - (size_t)(pos
- buf
), "read_bytes: %lu\n",
653 (unsigned long) ms_stats
.bytes_read
);
654 pos
+= snprintf(pos
, sizeof(buf
) - (size_t)(pos
- buf
), "object_bytes: %lu\n",
655 (unsigned long) ms_stats
.obj_bytes
);
657 if (ms_setting
.udp
|| ms_setting
.facebook_test
) {
658 pos
+= snprintf(pos
, sizeof(buf
) - (size_t)(pos
- buf
), "packet_disorder: %lu\n",
659 (unsigned long) ms_stats
.pkt_disorder
);
660 pos
+= snprintf(pos
, sizeof(buf
) - (size_t)(pos
- buf
), "packet_drop: %lu\n",
661 (unsigned long) ms_stats
.pkt_drop
);
662 pos
+= snprintf(pos
, sizeof(buf
) - (size_t)(pos
- buf
), "udp_timeout: %lu\n",
663 (unsigned long) ms_stats
.udp_timeout
);
666 if (ms_setting
.stat_freq
> 0) {
667 ms_dump_stats(&ms_statistic
.get_stat
);
668 ms_dump_stats(&ms_statistic
.set_stat
);
669 ms_dump_stats(&ms_statistic
.total_stat
);
672 int64_t time_diff
= ms_time_diff(start_time
, end_time
);
673 pos
+= snprintf(pos
, sizeof(buf
) - (size_t)(pos
- buf
),
674 "\nRun time: %.1fs Ops: %llu TPS: %.0Lf Net_rate: %.1fM/s\n",
675 (double) time_diff
/ 1000000,
676 (unsigned long long) (ms_stats
.cmd_get
+ ms_stats
.cmd_set
),
677 (ms_stats
.cmd_get
+ ms_stats
.cmd_set
) / ((long double) time_diff
/ 1000000),
678 (double) (ms_stats
.bytes_written
+ ms_stats
.bytes_read
) / 1024 / 1024
679 / ((double) time_diff
/ 1000000));
680 assert(pos
<= (buf
+ sizeof(buf
)));
682 fwrite(buf
, 1, pos
- buf
, stdout
);
684 } /* ms_print_memaslap_stats */
686 /* the loop of the main thread, wait the work threads to complete */
687 static void ms_monitor_slap_mode() {
688 struct timeval start_time
, end_time
;
690 /* Wait all the threads complete initialization. */
691 pthread_mutex_lock(&ms_global
.init_lock
.lock
);
692 while (ms_global
.init_lock
.count
< ms_setting
.nthreads
) {
693 pthread_cond_wait(&ms_global
.init_lock
.cond
, &ms_global
.init_lock
.lock
);
695 pthread_mutex_unlock(&ms_global
.init_lock
.lock
);
697 /* only when there is no set operation it need warm up */
698 if (ms_setting
.cmd_distr
[CMD_SET
].cmd_prop
< PROP_ERROR
) {
699 /* Wait all the connects complete warm up. */
700 pthread_mutex_lock(&ms_global
.warmup_lock
.lock
);
701 while (ms_global
.warmup_lock
.count
< ms_setting
.nconns
) {
702 pthread_cond_wait(&ms_global
.warmup_lock
.cond
, &ms_global
.warmup_lock
.lock
);
704 pthread_mutex_unlock(&ms_global
.warmup_lock
.lock
);
706 ms_global
.finish_warmup
= true;
708 /* running in "run time" mode, user specify run time */
709 if (ms_setting
.run_time
> 0) {
711 gettimeofday(&start_time
, NULL
);
716 if ((ms_setting
.stat_freq
> 0) && (second
% ms_setting
.stat_freq
== 0)
717 && (ms_stats
.active_conns
>= ms_setting
.nconns
) && (ms_stats
.active_conns
<= INT_MAX
))
719 ms_print_statistics(second
);
722 if (ms_setting
.run_time
<= second
) {
723 ms_global
.time_out
= true;
727 /* all connections disconnect */
728 if ((second
> 5) && (ms_stats
.active_conns
== 0)) {
732 gettimeofday(&end_time
, NULL
);
733 sleep(1); /* wait all threads clean up */
735 /* running in "execute number" mode, user specify execute number */
736 gettimeofday(&start_time
, NULL
);
739 * We loop until we know that all connects have cleaned up.
741 pthread_mutex_lock(&ms_global
.run_lock
.lock
);
742 while (ms_global
.run_lock
.count
< ms_setting
.nconns
) {
743 pthread_cond_wait(&ms_global
.run_lock
.cond
, &ms_global
.run_lock
.lock
);
745 pthread_mutex_unlock(&ms_global
.run_lock
.lock
);
747 gettimeofday(&end_time
, NULL
);
750 ms_print_memaslap_stats(&start_time
, &end_time
);
751 } /* ms_monitor_slap_mode */
753 /* the main function */
754 int main(int argc
, char *argv
[]) {
755 srandom((unsigned int) time(NULL
));
756 ms_global_struct_init();
759 ms_setting_init_pre();
760 ms_options_parse(argc
, argv
);
761 if (ms_check_para()) {
762 ms_help_command(PROGRAM_NAME
, PROGRAM_DESCRIPTION
);
765 ms_setting_init_post();
769 /* waiting work thread complete its task */
770 ms_monitor_slap_mode();
774 ms_global_struct_destroy();
775 ms_setting_cleanup();