3 * Author: Mingqiang Zhuang
5 * Created on February 10, 2009
7 * (c) Copyright 2009, Schooner Information Technology, Inc.
8 * http://www.schoonerinfotech.com/
14 #include <libmemcached/memcached.h>
21 #include <sys/types.h>
22 #include <sys/types.h>
27 #include "ms_setting.h"
30 #define MAX_EXEC_NUM 0x4000000000000000 /* 1 << 62 */
31 #define ADDR_ALIGN(addr) ((addr + 15) & ~(16 - 1)) /* 16 bytes aligned */
32 #define RAND_CHAR_SIZE (10 * 1024 * 1024) /* 10M character table */
33 #define RESERVED_RAND_CHAR_SIZE (2 * 1024 * 1024) /* reserved 2M to avoid pointer sloping over */
35 #define DEFAULT_CONFIG_NAME ".memslap.cnf"
37 #define DEFAULT_THREADS_NUM 1 /* default start one thread */
38 #define DEFAULT_CONNS_NUM 16 /* default each thread with 16 connections */
39 #define DEFAULT_EXE_NUM 0 /* default execute number is 0 */
40 #define DEFAULT_VERIFY_RATE 0.0 /* default it doesn't do data verification */
41 #define DEFAULT_OVERWRITE_RATE 0.0 /* default it doesn't do overwrite */
42 #define DEFAULT_DIV 1 /* default it runs single get */
43 #define DEFAULT_RUN_TIME 600 /* default run time 10 minutes */
44 #define DEFAULT_WINDOW_SIZE (10 * UNIT_ITEMS_COUNT) /* default window size is 10k */
45 #define DEFAULT_SOCK_PER_CONN 1 /* default socks per connection is 1 */
47 /* Use this for string generation */
48 #define CHAR_COUNT 64 /* number of characters used to generate character table */
49 const char ALPHANUMBERICS
[]=
50 "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz.-";
52 ms_setting_st ms_setting
; /* store the settings specified by user */
55 /* read setting from configuration file */
56 static void ms_get_serverlist(char *str
);
57 static uint32_t ms_get_cpu_count(void);
58 ms_conf_type_t
ms_get_conf_type(char *line
);
59 static int ms_is_line_data(char *line
);
60 static int ms_read_is_data(char *line
, ssize_t nread
);
61 static void ms_no_config_file(void);
62 static void ms_parse_cfg_file(char *cfg_file
);
65 /* initialize setting structure */
66 static void ms_init_random_block(void);
67 static void ms_calc_avg_size(void);
68 static int ms_shuffle_distr(ms_distr_t
*distr
, int length
);
69 static void ms_build_distr(void);
70 static void ms_print_setting(void);
71 static void ms_setting_slapmode_init_pre(void);
72 static void ms_setting_slapmode_init_post(void);
74 #if !defined(HAVE_GETLINE)
76 static ssize_t
getline (char **line
, size_t *line_size
, FILE *fp
)
82 if (line
== NULL
|| line_size
== NULL
|| fp
== NULL
)
88 if (*line
== NULL
|| *line_size
== 0)
92 new_line
= (char *) realloc (*line
, *line_size
);
110 /* Make enough space for len+1 (for final NUL) bytes. */
111 if (cur_len
+ 1 >= *line_size
)
114 SSIZE_MAX
< SIZE_MAX
? (size_t) SSIZE_MAX
+ 1 : SIZE_MAX
;
115 size_t needed
= (2 * (*line_size
)) + 1;
118 if (needed_max
< needed
)
120 if (cur_len
+ 1 >= needed
)
127 new_line
= (char *)realloc(*line
, needed
);
128 if (new_line
== NULL
)
138 (*line
)[cur_len
]= (char)i
;
144 (*line
)[cur_len
] = '\0';
146 return (ssize_t
)cur_len
;
152 * parse the server list string, and build the servers
153 * information structure array. this function is used to parse
154 * the command line options specified by user.
156 * @param str, the string of server list
158 static void ms_get_serverlist(char *str
)
160 ms_mcd_server_t
*srvs
= NULL
;
163 * Servers list format is like this. For example:
164 * "localhost:11108, localhost:11109"
166 memcached_server_st
*server_pool
;
167 server_pool
= memcached_servers_parse(str
);
169 for (uint32_t loop
= 0; loop
< memcached_server_list_count(server_pool
); loop
++)
171 assert(ms_setting
.srv_cnt
< ms_setting
.total_srv_cnt
);
172 strcpy(ms_setting
.servers
[ms_setting
.srv_cnt
].srv_host_name
, server_pool
[loop
].hostname
);
173 ms_setting
.servers
[ms_setting
.srv_cnt
].srv_port
= server_pool
[loop
].port
;
174 ms_setting
.servers
[ms_setting
.srv_cnt
].disconn_cnt
= 0;
175 ms_setting
.servers
[ms_setting
.srv_cnt
].reconn_cnt
= 0;
176 ms_setting
.srv_cnt
++;
178 if (ms_setting
.srv_cnt
>= ms_setting
.total_srv_cnt
)
180 srvs
= (ms_mcd_server_t
*)realloc( ms_setting
.servers
,
181 (size_t)ms_setting
.total_srv_cnt
* sizeof(ms_mcd_server_t
) * 2);
184 fprintf(stderr
, "Can't reallocate servers structure.\n");
187 ms_setting
.servers
= srvs
;
188 ms_setting
.total_srv_cnt
*= 2;
192 memcached_server_free(server_pool
);
193 } /* ms_get_serverlist */
197 * used to get the CPU count of the current system
199 * @return return the cpu count if get, else return 1
201 static uint32_t ms_get_cpu_count()
203 #ifdef HAVE__SC_NPROCESSORS_ONLN
204 return sysconf(_SC_NPROCESSORS_CONF
);
207 # ifdef HAVE_CPU_SET_T
211 sched_getaffinity(0, sizeof(cpu_set_t
), &cpu_set
);
213 for (int i
= 0; i
< (sizeof(cpu_set_t
) * 8); i
++)
215 if (CPU_ISSET(i
, &cpu_set
))
226 /* the system with one cpu at least */
228 } /* ms_get_cpu_count */
232 * used to get the configure type based on the type string read
233 * from the configuration file.
235 * @param line, string of one line
237 * @return ms_conf_type_t
239 ms_conf_type_t
ms_get_conf_type(char *line
)
241 if (! memcmp(line
, "key", strlen("key")))
245 else if (! memcmp(line
, "value", strlen("value")))
249 else if (! memcmp(line
, "cmd", strlen("cmd")))
257 } /* ms_get_conf_type */
261 * judge whether the line is a line with useful data. used to
262 * parse the configuration file.
264 * @param line, string of one line
266 * @return if success, return 1, else return 0
268 static int ms_is_line_data(char *line
)
270 assert(line
!= NULL
);
272 char *begin_ptr
= line
;
274 while (isspace(*begin_ptr
))
278 if ((begin_ptr
[0] == '\0') || (begin_ptr
[0] == '#'))
282 } /* ms_is_line_data */
286 * function to bypass blank line and comments
288 * @param line, string of one line
289 * @param nread, length of the line
291 * @return if it's EOF or not line data, return 0, else return 1
293 static int ms_read_is_data(char *line
, ssize_t nread
)
295 if ((nread
== EOF
) || ! ms_is_line_data(line
))
299 } /* ms_read_is_data */
303 * if no configuration file, use this function to create the default
304 * configuration file.
306 static void ms_no_config_file()
308 char userpath
[PATH_MAX
];
309 struct passwd
*usr
= NULL
;
312 usr
= getpwuid(getuid());
314 snprintf(userpath
, PATH_MAX
, "%s/%s", usr
->pw_dir
, DEFAULT_CONFIG_NAME
);
316 if (access (userpath
, F_OK
| R_OK
) == 0)
319 fd
= fopen(userpath
, "w+");
323 fprintf(stderr
, "Could not create default configure file %s\n", userpath
);
324 perror(strerror(errno
));
327 fprintf(fd
, "%s", DEFAULT_CONGIF_STR
);
331 ms_setting
.cfg_file
= strdup(userpath
);
332 } /* ms_no_config_file */
336 * parse the configuration file
338 * @param cfg_file, the configuration file name
340 static void ms_parse_cfg_file(char *cfg_file
)
343 size_t start_len
, end_len
;
349 ms_conf_type_t conf_type
;
351 ms_key_distr_t
*key_distr
= NULL
;
352 ms_value_distr_t
*val_distr
= NULL
;
354 if (cfg_file
== NULL
)
357 cfg_file
= ms_setting
.cfg_file
;
360 /*read key value configure file*/
361 if ((f
= fopen(cfg_file
, "r")) == NULL
)
363 fprintf(stderr
, "Can not open file: '%s'.\n", cfg_file
);
369 if ((((nread
= getline(&line
, &read_len
, f
)) == 1)
370 || ! ms_read_is_data(line
, nread
)) && (nread
!= EOF
)) /* bypass blank line */
375 fprintf(stderr
, "Bad configuration file, no configuration find.\n");
378 conf_type
= ms_get_conf_type(line
);
382 while (! end_of_file
)
389 if ((((nread
= getline(&line
, &read_len
, f
)) == 1)
390 || ! ms_read_is_data(line
, nread
)) && (nread
!= EOF
)) /* bypass blank line */
395 if (sscanf(line
, "%zu %zu %lf ", &start_len
,
396 &end_len
, &proportion
) != 3)
398 conf_type
= ms_get_conf_type(line
);
401 ms_setting
.key_distr
[ms_setting
.key_rng_cnt
].start_len
= start_len
;
402 ms_setting
.key_distr
[ms_setting
.key_rng_cnt
].end_len
= end_len
;
403 ms_setting
.key_distr
[ms_setting
.key_rng_cnt
].key_prop
= proportion
;
404 ms_setting
.key_rng_cnt
++;
406 if (ms_setting
.key_rng_cnt
>= ms_setting
.total_key_rng_cnt
)
408 key_distr
= (ms_key_distr_t
*)realloc(
409 ms_setting
.key_distr
,
411 total_key_rng_cnt
* sizeof(ms_key_distr_t
) * 2);
412 if (key_distr
== NULL
)
415 "Can't reallocate key distribution structure.\n");
418 ms_setting
.key_distr
= key_distr
;
419 ms_setting
.total_key_rng_cnt
*= 2;
431 if ((((nread
= getline(&line
, &read_len
, f
)) == 1)
432 || ! ms_read_is_data(line
, nread
)) && (nread
!= EOF
)) /* bypass blank line */
437 if (sscanf(line
, "%zu %zu %lf", &start_len
, &end_len
,
440 conf_type
= ms_get_conf_type(line
);
443 ms_setting
.value_distr
[ms_setting
.val_rng_cnt
].start_len
=
445 ms_setting
.value_distr
[ms_setting
.val_rng_cnt
].end_len
= end_len
;
446 ms_setting
.value_distr
[ms_setting
.val_rng_cnt
].value_prop
=
448 ms_setting
.val_rng_cnt
++;
450 if (ms_setting
.val_rng_cnt
>= ms_setting
.total_val_rng_cnt
)
452 val_distr
= (ms_value_distr_t
*)realloc(
453 ms_setting
.value_distr
,
455 total_val_rng_cnt
* sizeof(ms_value_distr_t
) * 2);
456 if (val_distr
== NULL
)
459 "Can't reallocate key distribution structure.\n");
462 ms_setting
.value_distr
= val_distr
;
463 ms_setting
.total_val_rng_cnt
*= 2;
475 if ((((nread
= getline(&line
, &read_len
, f
)) == 1)
476 || ! ms_read_is_data(line
, nread
)) && (nread
!= EOF
)) /* bypass blank line */
481 if (sscanf(line
, "%d %lf", &cmd_type
, &proportion
) != 2)
483 conf_type
= ms_get_conf_type(line
);
486 if (cmd_type
>= CMD_NULL
)
490 ms_setting
.cmd_distr
[ms_setting
.cmd_used_count
].cmd_type
=
492 ms_setting
.cmd_distr
[ms_setting
.cmd_used_count
].cmd_prop
=
494 ms_setting
.cmd_used_count
++;
504 if ((((nread
= getline(&line
, &read_len
, f
)) == 1)
505 || ! ms_read_is_data(line
, nread
)) && (nread
!= EOF
)) /* bypass blank line */
510 if ((conf_type
= ms_get_conf_type(line
)) != CONF_NULL
)
533 } /* ms_parse_cfg_file */
536 /* calculate the average size of key and value */
537 static void ms_calc_avg_size()
539 double avg_val_size
= 0.0;
540 double avg_key_size
= 0.0;
543 double averge_len
= 0.0;
547 for (int j
= 0; j
< ms_setting
.val_rng_cnt
; j
++)
549 val_pro
= ms_setting
.value_distr
[j
].value_prop
;
550 start_len
= ms_setting
.value_distr
[j
].start_len
;
551 end_len
= ms_setting
.value_distr
[j
].end_len
;
553 averge_len
= val_pro
* ((double)(start_len
+ end_len
)) / 2;
554 avg_val_size
+= averge_len
;
557 for (int j
= 0; j
< ms_setting
.key_rng_cnt
; j
++)
559 key_pro
= ms_setting
.key_distr
[j
].key_prop
;
560 start_len
= ms_setting
.key_distr
[j
].start_len
;
561 end_len
= ms_setting
.key_distr
[j
].end_len
;
563 averge_len
= key_pro
* ((double)(start_len
+ end_len
)) / 2;
564 avg_key_size
+= averge_len
;
567 ms_setting
.avg_val_size
= (size_t)avg_val_size
;
568 ms_setting
.avg_key_size
= (size_t)avg_key_size
;
569 } /* ms_calc_avg_size */
573 * used to shuffle key and value distribution array to ensure
574 * (key, value) pair with different set.
576 * @param distr, pointer of distribution structure array
577 * @param length, length of the array
579 * @return always return 0
581 static int ms_shuffle_distr(ms_distr_t
*distr
, int length
)
588 for (i
= 0; i
< length
; i
++)
591 j
= (int)(rnd
% (length
- i
)) + i
;
596 tmp_size
= distr
[j
].key_size
;
597 distr
[j
].key_size
= distr
[i
].key_size
;
598 distr
[i
].key_size
= tmp_size
;
602 tmp_offset
= distr
[j
].key_offset
;
603 distr
[j
].key_offset
= distr
[i
].key_offset
;
604 distr
[i
].key_offset
= tmp_offset
;
608 tmp_size
= distr
[j
].value_size
;
609 distr
[j
].value_size
= distr
[i
].value_size
;
610 distr
[i
].value_size
= tmp_size
;
619 } /* ms_shuffle_distr */
623 * according to the key and value distribution, to build the
624 * (key, value) pair distribution. the (key, value) pair
625 * distribution array is global, each connection set or get
626 * object keeping this distribution, for the final result, we
627 * can reach the expected key and value distribution.
629 static void ms_build_distr()
635 size_t average_len
= 0;
640 ms_distr_t
*distr
= NULL
;
641 int units
= (int)ms_setting
.win_size
/ UNIT_ITEMS_COUNT
;
643 /* calculate average value size and key size */
646 ms_setting
.char_blk_size
= RAND_CHAR_SIZE
;
648 (int)((ms_setting
.char_blk_size
- RESERVED_RAND_CHAR_SIZE
)
651 ms_setting
.distr
= (ms_distr_t
*)malloc(
652 sizeof(ms_distr_t
) * ms_setting
.win_size
);
653 if (ms_setting
.distr
== NULL
)
655 fprintf(stderr
, "Can't allocate distribution array.");
660 * character block is divided by how many different key
661 * size, each different key size has the same size character
664 for (int m
= 0; m
< units
; m
++)
666 for (int i
= 0; i
< UNIT_ITEMS_COUNT
; i
++)
668 ms_setting
.distr
[m
* UNIT_ITEMS_COUNT
+ i
].key_offset
=
669 ADDR_ALIGN(key_scope_size
* i
);
673 /* initialize key size distribution */
674 for (int m
= 0; m
< units
; m
++)
676 for (int j
= 0; j
< ms_setting
.key_rng_cnt
; j
++)
678 key_cnt
= (int)(UNIT_ITEMS_COUNT
* ms_setting
.key_distr
[j
].key_prop
);
679 start_len
= ms_setting
.key_distr
[j
].start_len
;
680 end_len
= ms_setting
.key_distr
[j
].end_len
;
681 if ((start_len
< MIN_KEY_SIZE
) || (end_len
< MIN_KEY_SIZE
))
683 fprintf(stderr
, "key length must be greater than 16 bytes.\n");
687 if (! ms_setting
.binary_prot
688 && ((start_len
> MAX_KEY_SIZE
) || (end_len
> MAX_KEY_SIZE
)))
690 fprintf(stderr
, "key length must be less than 250 bytes.\n");
694 average_len
= (start_len
+ end_len
) / 2;
695 diff_len
= (end_len
- start_len
) / 2;
696 for (int k
= 0; k
< key_cnt
; k
++)
698 if (offset
>= (m
+ 1) * UNIT_ITEMS_COUNT
)
705 ms_setting
.distr
[offset
].key_size
=
706 (diff_len
== 0) ? average_len
:
707 average_len
+ (size_t)rnd
712 ms_setting
.distr
[offset
].key_size
=
713 (diff_len
== 0) ? average_len
:
714 average_len
- (size_t)rnd
721 if (offset
< (m
+ 1) * UNIT_ITEMS_COUNT
)
723 end
= (m
+ 1) * UNIT_ITEMS_COUNT
- offset
;
724 for (int i
= 0; i
< end
; i
++)
726 ms_setting
.distr
[offset
].key_size
= ms_setting
.avg_key_size
;
733 /* initialize value distribution */
734 if (ms_setting
.fixed_value_size
!= 0)
736 for (int i
= 0; i
< units
* UNIT_ITEMS_COUNT
; i
++)
738 ms_setting
.distr
[i
].value_size
= ms_setting
.fixed_value_size
;
743 for (int m
= 0; m
< units
; m
++)
745 for (int j
= 0; j
< ms_setting
.val_rng_cnt
; j
++)
748 (int)(UNIT_ITEMS_COUNT
* ms_setting
.value_distr
[j
].value_prop
);
749 start_len
= ms_setting
.value_distr
[j
].start_len
;
750 end_len
= ms_setting
.value_distr
[j
].end_len
;
751 if ((start_len
<= 0) || (end_len
<= 0))
753 fprintf(stderr
, "value length must be greater than 0 bytes.\n");
757 if ((start_len
> MAX_VALUE_SIZE
) || (end_len
> MAX_VALUE_SIZE
))
759 fprintf(stderr
, "key length must be less than or equal to 1M.\n");
763 average_len
= (start_len
+ end_len
) / 2;
764 diff_len
= (end_len
- start_len
) / 2;
765 for (int k
= 0; k
< value_cnt
; k
++)
767 if (offset
>= (m
+ 1) * UNIT_ITEMS_COUNT
)
774 ms_setting
.distr
[offset
].value_size
=
775 (diff_len
== 0) ? average_len
:
777 + (size_t)rnd
% diff_len
;
781 ms_setting
.distr
[offset
].value_size
=
782 (diff_len
== 0) ? average_len
:
784 - (size_t)rnd
% diff_len
;
790 if (offset
< (m
+ 1) * UNIT_ITEMS_COUNT
)
792 end
= (m
+ 1) * UNIT_ITEMS_COUNT
- offset
;
793 for (int i
= 0; i
< end
; i
++)
795 ms_setting
.distr
[offset
++].value_size
= ms_setting
.avg_val_size
;
801 /* shuffle distribution */
802 for (int i
= 0; i
< units
; i
++)
804 distr
= &ms_setting
.distr
[i
* UNIT_ITEMS_COUNT
];
805 for (int j
= 0; j
< 4; j
++)
807 ms_shuffle_distr(distr
, UNIT_ITEMS_COUNT
);
810 } /* ms_build_distr */
814 * used to initialize the global character block. The character
815 * block is used to generate the suffix of the key and value. we
816 * only store a pointer in the character block for each key
817 * suffix or value string. It can save much memory to store key
820 static void ms_init_random_block()
824 assert(ms_setting
.char_blk_size
> 0);
826 ms_setting
.char_block
= (char *)malloc(ms_setting
.char_blk_size
);
827 if (ms_setting
.char_block
== NULL
)
829 fprintf(stderr
, "Can't allocate global char block.");
832 ptr
= ms_setting
.char_block
;
834 for (int i
= 0; (size_t)i
< ms_setting
.char_blk_size
; i
++)
836 *(ptr
++)= ALPHANUMBERICS
[random() % CHAR_COUNT
];
838 } /* ms_init_random_block */
842 * after initialization, call this function to output the main
843 * configuration user specified.
845 static void ms_print_setting()
847 fprintf(stdout
, "servers : %s\n", ms_setting
.srv_str
);
848 fprintf(stdout
, "threads count: %d\n", ms_setting
.nthreads
);
849 fprintf(stdout
, "concurrency: %d\n", ms_setting
.nconns
);
850 if (ms_setting
.run_time
> 0)
852 fprintf(stdout
, "run time: %ds\n", ms_setting
.run_time
);
856 fprintf(stdout
, "execute number: %" PRId64
"\n", ms_setting
.exec_num
);
858 fprintf(stdout
, "windows size: %" PRId64
"k\n",
859 (int64_t)(ms_setting
.win_size
/ 1024));
860 fprintf(stdout
, "set proportion: set_prop=%.2f\n",
861 ms_setting
.cmd_distr
[CMD_SET
].cmd_prop
);
862 fprintf(stdout
, "get proportion: get_prop=%.2f\n",
863 ms_setting
.cmd_distr
[CMD_GET
].cmd_prop
);
865 } /* ms_print_setting */
869 * previous part of slap mode initialization of setting structure
871 static void ms_setting_slapmode_init_pre()
873 ms_setting
.exec_num
= DEFAULT_EXE_NUM
;
874 ms_setting
.verify_percent
= DEFAULT_VERIFY_RATE
;
875 ms_setting
.exp_ver_per
= DEFAULT_VERIFY_RATE
;
876 ms_setting
.overwrite_percent
= DEFAULT_OVERWRITE_RATE
;
877 ms_setting
.mult_key_num
= DEFAULT_DIV
;
878 ms_setting
.fixed_value_size
= 0;
879 ms_setting
.win_size
= DEFAULT_WINDOW_SIZE
;
880 ms_setting
.udp
= false;
881 ms_setting
.reconnect
= false;
882 ms_setting
.verbose
= false;
883 ms_setting
.facebook_test
= false;
884 ms_setting
.binary_prot
= false;
885 ms_setting
.stat_freq
= 0;
886 ms_setting
.srv_str
= NULL
;
887 ms_setting
.cfg_file
= NULL
;
888 ms_setting
.sock_per_conn
= DEFAULT_SOCK_PER_CONN
;
889 ms_setting
.expected_tps
= 0;
890 ms_setting
.rep_write_srv
= 0;
891 } /* ms_setting_slapmode_init_pre */
895 * previous part of initialization of setting structure
897 void ms_setting_init_pre()
899 memset(&ms_setting
, 0, sizeof(ms_setting
));
901 /* common initialize */
902 ms_setting
.ncpu
= ms_get_cpu_count();
903 ms_setting
.nthreads
= DEFAULT_THREADS_NUM
;
904 ms_setting
.nconns
= DEFAULT_CONNS_NUM
;
905 ms_setting
.run_time
= DEFAULT_RUN_TIME
;
906 ms_setting
.total_srv_cnt
= MCD_SRVS_NUM_INIT
;
907 ms_setting
.servers
= (ms_mcd_server_t
*)malloc(
908 (size_t)ms_setting
.total_srv_cnt
909 * sizeof(ms_mcd_server_t
));
910 if (ms_setting
.servers
== NULL
)
912 fprintf(stderr
, "Can't allocate servers structure.\n");
916 ms_setting_slapmode_init_pre();
917 } /* ms_setting_init_pre */
921 * post part of slap mode initialization of setting structure
923 static void ms_setting_slapmode_init_post()
925 ms_setting
.total_key_rng_cnt
= KEY_RANGE_COUNT_INIT
;
926 ms_setting
.key_distr
=
927 (ms_key_distr_t
*)malloc((size_t)ms_setting
.total_key_rng_cnt
* sizeof(ms_key_distr_t
));
929 if (ms_setting
.key_distr
== NULL
)
931 fprintf(stderr
, "Can't allocate key distribution structure.\n");
935 ms_setting
.total_val_rng_cnt
= VALUE_RANGE_COUNT_INIT
;
937 ms_setting
.value_distr
=
938 (ms_value_distr_t
*)malloc((size_t)ms_setting
.total_val_rng_cnt
* sizeof( ms_value_distr_t
));
940 if (ms_setting
.value_distr
== NULL
)
942 fprintf(stderr
, "Can't allocate value distribution structure.\n");
946 ms_parse_cfg_file(ms_setting
.cfg_file
);
949 if ((ms_setting
.exec_num
== 0) && (ms_setting
.run_time
!= 0))
951 ms_setting
.exec_num
= (int64_t)MAX_EXEC_NUM
;
955 /* execute number mode */
956 ms_setting
.run_time
= 0;
959 if (ms_setting
.rep_write_srv
> 0)
961 /* for replication test, need enable reconnect feature */
962 ms_setting
.reconnect
= true;
965 if (ms_setting
.facebook_test
&& (ms_setting
.mult_key_num
< 2))
967 fprintf(stderr
, "facebook test must work with multi-get, "
968 "please specify multi-get key number "
969 "with '--division' option.\n");
973 if (ms_setting
.facebook_test
&& ms_setting
.udp
)
975 fprintf(stderr
, "facebook test couldn't work with UDP.\n");
979 if (ms_setting
.udp
&& (ms_setting
.sock_per_conn
> 1))
981 fprintf(stderr
, "UDP doesn't support multi-socks "
982 "in one connection structure.\n");
986 if ((ms_setting
.rep_write_srv
> 0) && (ms_setting
.srv_cnt
< 2))
988 fprintf(stderr
, "Please specify 2 servers at least for replication\n");
992 if ((ms_setting
.rep_write_srv
> 0)
993 && (ms_setting
.srv_cnt
< ms_setting
.rep_write_srv
))
995 fprintf(stderr
, "Servers to do replication writing "
996 "is larger than the total servers\n");
1000 if (ms_setting
.udp
&& (ms_setting
.rep_write_srv
> 0))
1002 fprintf(stderr
, "UDP doesn't support replication.\n");
1006 if (ms_setting
.facebook_test
&& (ms_setting
.rep_write_srv
> 0))
1008 fprintf(stderr
, "facebook test couldn't work with replication.\n");
1014 /* initialize global character block */
1015 ms_init_random_block();
1017 } /* ms_setting_slapmode_init_post */
1021 * post part of initialization of setting structure
1023 void ms_setting_init_post()
1025 ms_get_serverlist(ms_setting
.srv_str
);
1026 ms_setting_slapmode_init_post();
1031 * clean up the global setting structure
1033 void ms_setting_cleanup()
1035 if (ms_setting
.distr
!= NULL
)
1037 free(ms_setting
.distr
);
1040 if (ms_setting
.char_block
!= NULL
)
1042 free(ms_setting
.char_block
);
1045 if (ms_setting
.srv_str
!= NULL
)
1047 free(ms_setting
.srv_str
);
1050 if (ms_setting
.cfg_file
!= NULL
)
1052 free(ms_setting
.cfg_file
);
1055 if (ms_setting
.servers
!= NULL
)
1057 free(ms_setting
.servers
);
1060 if (ms_setting
.key_distr
!= NULL
)
1062 free(ms_setting
.key_distr
);
1065 if (ms_setting
.value_distr
!= NULL
)
1067 free(ms_setting
.value_distr
);
1069 } /* ms_setting_cleanup */