4791c479b9ba8a26507a63754dcf013aabc88526
3 * Author: Mingqiang Zhuang
5 * Created on February 10, 2009
7 * (c) Copyright 2009, Schooner Information Technology, Inc.
8 * http://www.schoonerinfotech.com/
17 #include "ms_setting.h"
20 #define MAX_EXEC_NUM 0x4000000000000000 /* 1 << 62 */
21 #define ADDR_ALIGN(addr) ((addr + 15) & ~(16 - 1)) /* 16 bytes aligned */
22 #define RAND_CHAR_SIZE (10 * 1024 * 1024) /* 10M character table */
23 #define RESERVED_RAND_CHAR_SIZE (2 * 1024 * 1024) /* reserved 2M to avoid pointer sloping over */
25 #define DEFAULT_THREADS_NUM 1 /* default start one thread */
26 #define DEFAULT_CONNS_NUM 16 /* default each thread with 16 connections */
27 #define DEFAULT_EXE_NUM 0 /* default execute number is 0 */
28 #define DEFAULT_VERIFY_RATE 0.0 /* default it doesn't do data verification */
29 #define DEFAULT_OVERWRITE_RATE 0.0 /* default it doesn't do overwrite */
30 #define DEFAULT_DIV 1 /* default it runs single get */
31 #define DEFAULT_RUN_TIME 600 /* default run time 10 minutes */
32 #define DEFAULT_WINDOW_SIZE (10 * UNIT_ITEMS_COUNT) /* default window size is 10k */
33 #define DEFAULT_SOCK_PER_CONN 1 /* default socks per connection is 1 */
35 /* Use this for string generation */
36 #define CHAR_COUNT 64 /* number of characters used to generate character table */
37 const char ALPHANUMBERICS
[]=
38 "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz.-";
40 ms_setting_st ms_setting
; /* store the settings specified by user */
43 /* read setting from configuration file */
44 static void ms_get_serverlist(char *str
);
45 static int ms_get_cpu_count(void);
46 ms_conf_type_t
ms_get_conf_type(char *line
);
47 static int ms_is_line_data(char *line
);
48 static int ms_read_is_data(char *line
, ssize_t nread
);
49 static void ms_no_config_file(void);
50 static void ms_parse_cfg_file(char *cfg_file
);
53 /* initialize setting structure */
54 static void ms_init_random_block(void);
55 static void ms_calc_avg_size(void);
56 static int ms_shuffle_distr(ms_distr_t
*distr
, int length
);
57 static void ms_build_distr(void);
58 static void ms_print_setting(void);
59 static void ms_setting_slapmode_init_pre(void);
60 static void ms_setting_slapmode_init_post(void);
62 #if defined(__SUNPRO_C)
64 static ssize_t
getline (char **line
, size_t *line_size
, FILE *fp
)
70 if (line
== NULL
|| line_size
== NULL
|| fp
== NULL
)
76 if (*line
== NULL
|| *line_size
== 0)
80 new_line
= (char *) realloc (*line
, *line_size
);
100 /* Make enough space for len+1 (for final NUL) bytes. */
101 if (cur_len
+ 1 >= *line_size
)
104 SSIZE_MAX
< SIZE_MAX
? (size_t) SSIZE_MAX
+ 1 : SIZE_MAX
;
105 size_t needed
= (2 * (*line_size
)) + 1;
108 if (needed_max
< needed
)
110 if (cur_len
+ 1 >= needed
)
117 new_line
= (char *)realloc(*line
, needed
);
118 if (new_line
== NULL
)
134 (*line
)[cur_len
] = '\0';
135 result
= cur_len
? cur_len
: result
;
142 * parse the server list string, and build the servers
143 * information structure array. this function is used to parse
144 * the command line options specified by user.
146 * @param str, the string of server list
148 static void ms_get_serverlist(char *str
)
153 char *end_ptr
= str
+ strlen(str
);
154 ms_mcd_server_t
*srvs
= NULL
;
159 * Servers list format is like this. For example:
160 * "localhost:11108, localhost:11109"
162 for (begin_ptr
= str
, string
= index(str
, ',');
163 begin_ptr
!= end_ptr
;
164 string
= index(begin_ptr
, ','))
170 memcpy(buffer
, begin_ptr
, (size_t)(string
- begin_ptr
));
171 buffer
[(unsigned int)(string
- begin_ptr
)]= '\0';
172 begin_ptr
= string
+ 1;
176 size_t length
= strlen(begin_ptr
);
177 memcpy(buffer
, begin_ptr
, length
);
178 buffer
[length
]= '\0';
182 ptr
= index(buffer
, ':');
188 port
= strtol(ptr
, (char **)NULL
, 10);
191 assert(ms_setting
.srv_cnt
< ms_setting
.total_srv_cnt
);
192 strcpy(ms_setting
.servers
[ms_setting
.srv_cnt
].srv_host_name
, buffer
);
193 ms_setting
.servers
[ms_setting
.srv_cnt
].srv_port
= (int)port
;
194 ms_setting
.servers
[ms_setting
.srv_cnt
].disconn_cnt
= 0;
195 ms_setting
.servers
[ms_setting
.srv_cnt
].reconn_cnt
= 0;
196 ms_setting
.srv_cnt
++;
198 if (ms_setting
.srv_cnt
>= ms_setting
.total_srv_cnt
)
200 srvs
= (ms_mcd_server_t
*)realloc(
202 (uint64_t)ms_setting
.total_srv_cnt
203 * sizeof(ms_mcd_server_t
) * 2);
206 fprintf(stderr
, "Can't reallocate servers structure.\n");
209 ms_setting
.servers
= srvs
;
210 ms_setting
.total_srv_cnt
*= 2;
213 if (isspace(*begin_ptr
))
216 } /* ms_get_serverlist */
220 * used to get the CPU count of the current system
222 * @return return the cpu count if get, else return 1
224 static int ms_get_cpu_count()
226 #ifdef HAVE__SC_NPROCESSORS_ONLN
227 return sysconf(_SC_NPROCESSORS_CONF
);
230 # ifdef HAVE_CPU_SET_T
234 sched_getaffinity(0, sizeof(cpu_set_t
), &cpu_set
);
236 for (int i
= 0; i
< (sizeof(cpu_set_t
) * 8); i
++)
238 if (CPU_ISSET(i
, &cpu_set
))
249 /* the system with one cpu at least */
251 } /* ms_get_cpu_count */
255 * used to get the configure type based on the type string read
256 * from the configuration file.
258 * @param line, string of one line
260 * @return ms_conf_type_t
262 ms_conf_type_t
ms_get_conf_type(char *line
)
264 if (! memcmp(line
, "key", strlen("key")))
268 else if (! memcmp(line
, "value", strlen("value")))
272 else if (! memcmp(line
, "cmd", strlen("cmd")))
280 } /* ms_get_conf_type */
284 * judge whether the line is a line with useful data. used to
285 * parse the configuration file.
287 * @param line, string of one line
289 * @return if success, return 1, else return 0
291 static int ms_is_line_data(char *line
)
293 assert(line
!= NULL
);
295 char *begin_ptr
= line
;
297 while (isspace(*begin_ptr
))
301 if ((begin_ptr
[0] == '\0') || (begin_ptr
[0] == '#'))
305 } /* ms_is_line_data */
309 * function to bypass blank line and comments
311 * @param line, string of one line
312 * @param nread, length of the line
314 * @return if it's EOF or not line data, return 0, else return 1
316 static int ms_read_is_data(char *line
, ssize_t nread
)
318 if ((nread
== EOF
) || ! ms_is_line_data(line
))
322 } /* ms_read_is_data */
326 * if no configuration file, use this function to create the default
327 * configuration file.
329 static void ms_no_config_file()
331 FILE *fd
= fopen("config", "w+");
333 fprintf(fd
, "%s", DEFAULT_CONGIF_STR
);
336 ms_setting
.cfg_file
= strdup("config");
337 } /* ms_no_config_file */
341 * parse the configuration file
343 * @param cfg_file, the configuration file name
345 static void ms_parse_cfg_file(char *cfg_file
)
348 size_t start_len
, end_len
;
355 ms_conf_type_t conf_type
;
357 ms_key_distr_t
*key_distr
= NULL
;
358 ms_value_distr_t
*val_distr
= NULL
;
361 if (cfg_file
== NULL
)
364 cfg_file
= ms_setting
.cfg_file
;
368 /*read key value configure file*/
369 if ((f
= fopen(cfg_file
, "r")) == NULL
)
371 fprintf(stderr
, "Can not open file: '%s'.\n", cfg_file
);
377 if ((((nread
= getline(&line
, &read_len
, f
)) == 1)
378 || ! ms_read_is_data(line
, nread
)) && (nread
!= EOF
)) /* bypass blank line */
382 fprintf(stderr
, "Bad configuration file, no configuration find.\n");
385 conf_type
= ms_get_conf_type(line
);
389 while (! end_of_file
)
396 if ((((nread
= getline(&line
, &read_len
, f
)) == 1)
397 || ! ms_read_is_data(line
, nread
)) && (nread
!= EOF
)) /* bypass blank line */
402 if (sscanf(line
, "%lu %lu %lf ", &start_len
,
403 &end_len
, &proportion
) != 3)
405 conf_type
= ms_get_conf_type(line
);
408 ms_setting
.key_distr
[ms_setting
.key_rng_cnt
].start_len
= start_len
;
409 ms_setting
.key_distr
[ms_setting
.key_rng_cnt
].end_len
= end_len
;
410 ms_setting
.key_distr
[ms_setting
.key_rng_cnt
].key_prop
= proportion
;
411 ms_setting
.key_rng_cnt
++;
413 if (ms_setting
.key_rng_cnt
>= ms_setting
.total_key_rng_cnt
)
415 key_distr
= (ms_key_distr_t
*)realloc(
416 ms_setting
.key_distr
,
417 (uint64_t)ms_setting
.
418 total_key_rng_cnt
* sizeof(ms_key_distr_t
) * 2);
419 if (key_distr
== NULL
)
422 "Can't reallocate key distribution structure.\n");
425 ms_setting
.key_distr
= key_distr
;
426 ms_setting
.total_key_rng_cnt
*= 2;
438 if ((((nread
= getline(&line
, &read_len
, f
)) == 1)
439 || ! ms_read_is_data(line
, nread
)) && (nread
!= EOF
)) /* bypass blank line */
444 if (sscanf(line
, "%lu %lu %lf %lu", &start_len
, &end_len
,
445 &proportion
, &frequence
) != 3)
447 conf_type
= ms_get_conf_type(line
);
450 ms_setting
.value_distr
[ms_setting
.val_rng_cnt
].start_len
=
452 ms_setting
.value_distr
[ms_setting
.val_rng_cnt
].end_len
= end_len
;
453 ms_setting
.value_distr
[ms_setting
.val_rng_cnt
].value_prop
=
455 ms_setting
.val_rng_cnt
++;
457 if (ms_setting
.val_rng_cnt
>= ms_setting
.total_val_rng_cnt
)
459 val_distr
= (ms_value_distr_t
*)realloc(
460 ms_setting
.value_distr
,
461 (uint64_t)ms_setting
.
462 total_val_rng_cnt
* sizeof(ms_value_distr_t
) * 2);
463 if (val_distr
== NULL
)
466 "Can't reallocate key distribution structure.\n");
469 ms_setting
.value_distr
= val_distr
;
470 ms_setting
.total_val_rng_cnt
*= 2;
482 if ((((nread
= getline(&line
, &read_len
, f
)) == 1)
483 || ! ms_read_is_data(line
, nread
)) && (nread
!= EOF
)) /* bypass blank line */
488 if (sscanf(line
, "%d %lf\n", &cmd_type
, &proportion
) != 2)
490 conf_type
= ms_get_conf_type(line
);
493 ms_setting
.cmd_distr
[ms_setting
.cmd_used_count
].cmd_type
=
495 ms_setting
.cmd_distr
[ms_setting
.cmd_used_count
].cmd_prop
=
497 ms_setting
.cmd_used_count
++;
507 if ((((nread
= getline(&line
, &read_len
, f
)) == 1)
508 || ! ms_read_is_data(line
, nread
)) && (nread
!= EOF
)) /* bypass blank line */
513 if ((conf_type
= ms_get_conf_type(line
)) != CONF_NULL
)
534 remove(ms_setting
.cfg_file
);
539 } /* ms_parse_cfg_file */
542 /* calculate the average size of key and value */
543 static void ms_calc_avg_size()
545 double avg_val_size
= 0.0;
546 double avg_key_size
= 0.0;
549 double averge_len
= 0.0;
553 for (int j
= 0; j
< ms_setting
.val_rng_cnt
; j
++)
555 val_pro
= ms_setting
.value_distr
[j
].value_prop
;
556 start_len
= ms_setting
.value_distr
[j
].start_len
;
557 end_len
= ms_setting
.value_distr
[j
].end_len
;
559 averge_len
= val_pro
* ((double)(start_len
+ end_len
)) / 2;
560 avg_val_size
+= averge_len
;
563 for (int j
= 0; j
< ms_setting
.key_rng_cnt
; j
++)
565 key_pro
= ms_setting
.key_distr
[j
].key_prop
;
566 start_len
= ms_setting
.key_distr
[j
].start_len
;
567 end_len
= ms_setting
.key_distr
[j
].end_len
;
569 averge_len
= key_pro
* ((double)(start_len
+ end_len
)) / 2;
570 avg_key_size
+= averge_len
;
573 ms_setting
.avg_val_size
= (size_t)avg_val_size
;
574 ms_setting
.avg_key_size
= (size_t)avg_key_size
;
575 } /* ms_calc_avg_size */
579 * used to shuffle key and value distribution array to ensure
580 * (key, value) pair with different set.
582 * @param distr, pointer of distribution structure array
583 * @param length, length of the array
585 * @return always return 0
587 static int ms_shuffle_distr(ms_distr_t
*distr
, int length
)
594 for (i
= 0; i
< length
; i
++)
597 j
= (int)(rnd
% (length
- i
)) + i
;
602 tmp_size
= distr
[j
].key_size
;
603 distr
[j
].key_size
= distr
[i
].key_size
;
604 distr
[i
].key_size
= tmp_size
;
608 tmp_offset
= distr
[j
].key_offset
;
609 distr
[j
].key_offset
= distr
[i
].key_offset
;
610 distr
[i
].key_offset
= tmp_offset
;
614 tmp_size
= distr
[j
].value_size
;
615 distr
[j
].value_size
= distr
[i
].value_size
;
616 distr
[i
].value_size
= tmp_size
;
625 } /* ms_shuffle_distr */
629 * according to the key and value distribution, to build the
630 * (key, value) pair distribution. the (key, value) pair
631 * distribution array is global, each connection set or get
632 * object keeping this distribution, for the final result, we
633 * can reach the expected key and value distribution.
635 static void ms_build_distr()
641 size_t average_len
= 0;
646 ms_distr_t
*distr
= NULL
;
647 int units
= (int)ms_setting
.win_size
/ UNIT_ITEMS_COUNT
;
649 /* calculate average value size and key size */
652 ms_setting
.char_blk_size
= RAND_CHAR_SIZE
;
654 (int)((ms_setting
.char_blk_size
- RESERVED_RAND_CHAR_SIZE
)
657 ms_setting
.distr
= (ms_distr_t
*)malloc(
658 sizeof(ms_distr_t
) * ms_setting
.win_size
);
659 if (ms_setting
.distr
== NULL
)
661 fprintf(stderr
, "Can't allocate distribution array.");
666 * character block is divided by how many different key
667 * size, each different key size has the same size character
670 for (int m
= 0; m
< units
; m
++)
672 for (int i
= 0; i
< UNIT_ITEMS_COUNT
; i
++)
674 ms_setting
.distr
[m
* UNIT_ITEMS_COUNT
+ i
].key_offset
=
675 ADDR_ALIGN(key_scope_size
* i
);
679 /* initialize key size distribution */
680 for (int m
= 0; m
< units
; m
++)
682 for (int j
= 0; j
< ms_setting
.key_rng_cnt
; j
++)
684 key_cnt
= (int)(UNIT_ITEMS_COUNT
* ms_setting
.key_distr
[j
].key_prop
);
685 start_len
= ms_setting
.key_distr
[j
].start_len
;
686 end_len
= ms_setting
.key_distr
[j
].end_len
;
687 if ((start_len
< MIN_KEY_SIZE
) || (end_len
< MIN_KEY_SIZE
))
689 fprintf(stderr
, "key length must be greater than 16 bytes.\n");
693 if (! ms_setting
.binary_prot
694 && ((start_len
> MAX_KEY_SIZE
) || (end_len
> MAX_KEY_SIZE
)))
696 fprintf(stderr
, "key length must be less than 250 bytes.\n");
700 average_len
= (start_len
+ end_len
) / 2;
701 diff_len
= (end_len
- start_len
) / 2;
702 for (int k
= 0; k
< key_cnt
; k
++)
704 if (offset
>= (m
+ 1) * UNIT_ITEMS_COUNT
)
711 ms_setting
.distr
[offset
].key_size
=
712 (diff_len
== 0) ? average_len
:
713 average_len
+ (size_t)rnd
718 ms_setting
.distr
[offset
].key_size
=
719 (diff_len
== 0) ? average_len
:
720 average_len
- (size_t)rnd
727 if (offset
< (m
+ 1) * UNIT_ITEMS_COUNT
)
729 end
= (m
+ 1) * UNIT_ITEMS_COUNT
- offset
;
730 for (int i
= 0; i
< end
; i
++)
732 ms_setting
.distr
[offset
].key_size
= ms_setting
.avg_key_size
;
739 /* initialize value distribution */
740 if (ms_setting
.fixed_value_size
!= 0)
742 for (int i
= 0; i
< units
* UNIT_ITEMS_COUNT
; i
++)
744 ms_setting
.distr
[i
].value_size
= ms_setting
.fixed_value_size
;
749 for (int m
= 0; m
< units
; m
++)
751 for (int j
= 0; j
< ms_setting
.val_rng_cnt
; j
++)
754 (int)(UNIT_ITEMS_COUNT
* ms_setting
.value_distr
[j
].value_prop
);
755 start_len
= ms_setting
.value_distr
[j
].start_len
;
756 end_len
= ms_setting
.value_distr
[j
].end_len
;
757 if ((start_len
<= 0) || (end_len
<= 0))
759 fprintf(stderr
, "value length must be greater than 0 bytes.\n");
763 if ((start_len
> MAX_VALUE_SIZE
) || (end_len
> MAX_VALUE_SIZE
))
765 fprintf(stderr
, "key length must be less than or equal to 1M.\n");
769 average_len
= (start_len
+ end_len
) / 2;
770 diff_len
= (end_len
- start_len
) / 2;
771 for (int k
= 0; k
< value_cnt
; k
++)
773 if (offset
>= (m
+ 1) * UNIT_ITEMS_COUNT
)
780 ms_setting
.distr
[offset
].value_size
=
781 (diff_len
== 0) ? average_len
:
783 + (size_t)rnd
% diff_len
;
787 ms_setting
.distr
[offset
].value_size
=
788 (diff_len
== 0) ? average_len
:
790 - (size_t)rnd
% diff_len
;
796 if (offset
< (m
+ 1) * UNIT_ITEMS_COUNT
)
798 end
= (m
+ 1) * UNIT_ITEMS_COUNT
- offset
;
799 for (int i
= 0; i
< end
; i
++)
801 ms_setting
.distr
[offset
++].value_size
= ms_setting
.avg_val_size
;
807 /* shuffle distribution */
808 for (int i
= 0; i
< units
; i
++)
810 distr
= &ms_setting
.distr
[i
* UNIT_ITEMS_COUNT
];
811 for (int j
= 0; j
< 4; j
++)
813 ms_shuffle_distr(distr
, UNIT_ITEMS_COUNT
);
816 } /* ms_build_distr */
820 * used to initialize the global character block. The character
821 * block is used to generate the suffix of the key and value. we
822 * only store a pointer in the character block for each key
823 * suffix or value string. It can save much memory to store key
826 static void ms_init_random_block()
830 assert(ms_setting
.char_blk_size
> 0);
832 ms_setting
.char_block
= (char *)malloc(ms_setting
.char_blk_size
);
833 if (ms_setting
.char_block
== NULL
)
835 fprintf(stderr
, "Can't allocate global char block.");
838 ptr
= ms_setting
.char_block
;
840 for (int i
= 0; (size_t)i
< ms_setting
.char_blk_size
; i
++)
842 *(ptr
++)= ALPHANUMBERICS
[random() % CHAR_COUNT
];
844 } /* ms_init_random_block */
848 * after initialization, call this function to output the main
849 * configuration user specified.
851 static void ms_print_setting()
853 fprintf(stdout
, "threads count: %d\n", ms_setting
.nthreads
);
854 fprintf(stdout
, "concurrency: %d\n", ms_setting
.nconns
);
855 if (ms_setting
.run_time
> 0)
857 fprintf(stdout
, "run time: %ds\n", ms_setting
.run_time
);
861 fprintf(stdout
, "execute number: %ld\n", ms_setting
.exec_num
);
863 fprintf(stdout
, "windows size: %ldk\n",
864 (int64_t)(ms_setting
.win_size
/ 1024));
865 fprintf(stdout
, "set proportion: set_prop=%.2f\n",
866 ms_setting
.cmd_distr
[CMD_SET
].cmd_prop
);
867 fprintf(stdout
, "get proportion: get_prop=%.2f\n",
868 ms_setting
.cmd_distr
[CMD_GET
].cmd_prop
);
870 } /* ms_print_setting */
874 * previous part of slap mode initialization of setting structure
876 static void ms_setting_slapmode_init_pre()
878 ms_setting
.exec_num
= DEFAULT_EXE_NUM
;
879 ms_setting
.verify_percent
= DEFAULT_VERIFY_RATE
;
880 ms_setting
.exp_ver_per
= DEFAULT_VERIFY_RATE
;
881 ms_setting
.overwrite_percent
= DEFAULT_OVERWRITE_RATE
;
882 ms_setting
.mult_key_num
= DEFAULT_DIV
;
883 ms_setting
.fixed_value_size
= 0;
884 ms_setting
.win_size
= DEFAULT_WINDOW_SIZE
;
885 ms_setting
.udp
= false;
886 ms_setting
.reconnect
= false;
887 ms_setting
.verbose
= false;
888 ms_setting
.facebook_test
= false;
889 ms_setting
.binary_prot
= false;
890 ms_setting
.stat_freq
= 0;
891 ms_setting
.srv_str
= NULL
;
892 ms_setting
.cfg_file
= NULL
;
893 ms_setting
.sock_per_conn
= DEFAULT_SOCK_PER_CONN
;
894 ms_setting
.expected_tps
= 0;
895 ms_setting
.rep_write_srv
= 0;
896 } /* ms_setting_slapmode_init_pre */
900 * previous part of initialization of setting structure
902 void ms_setting_init_pre()
904 memset(&ms_setting
, 0, sizeof(ms_setting
));
906 /* common initialize */
907 ms_setting
.ncpu
= ms_get_cpu_count();
908 ms_setting
.nthreads
= DEFAULT_THREADS_NUM
;
909 ms_setting
.nconns
= DEFAULT_CONNS_NUM
;
910 ms_setting
.run_time
= DEFAULT_RUN_TIME
;
911 ms_setting
.total_srv_cnt
= MCD_SRVS_NUM_INIT
;
912 ms_setting
.servers
= (ms_mcd_server_t
*)malloc(
913 (uint64_t)ms_setting
.total_srv_cnt
914 * sizeof(ms_mcd_server_t
));
915 if (ms_setting
.servers
== NULL
)
917 fprintf(stderr
, "Can't allocate servers structure.\n");
921 ms_setting_slapmode_init_pre();
922 } /* ms_setting_init_pre */
926 * post part of slap mode initialization of setting structure
928 static void ms_setting_slapmode_init_post()
930 ms_setting
.total_key_rng_cnt
= KEY_RANGE_COUNT_INIT
;
931 ms_setting
.key_distr
= (ms_key_distr_t
*)malloc(
932 (uint64_t)ms_setting
.total_key_rng_cnt
933 * sizeof(ms_key_distr_t
));
934 if (ms_setting
.key_distr
== NULL
)
936 fprintf(stderr
, "Can't allocate key distribution structure.\n");
940 ms_setting
.total_val_rng_cnt
= VALUE_RANGE_COUNT_INIT
;
941 ms_setting
.value_distr
= (ms_value_distr_t
*)malloc(
942 (uint64_t)ms_setting
.total_val_rng_cnt
945 if (ms_setting
.value_distr
== NULL
)
947 fprintf(stderr
, "Can't allocate value distribution structure.\n");
951 ms_parse_cfg_file(ms_setting
.cfg_file
);
954 if ((ms_setting
.exec_num
== 0) && (ms_setting
.run_time
!= 0))
956 ms_setting
.exec_num
= (int64_t)MAX_EXEC_NUM
;
960 /* execute number mode */
961 ms_setting
.run_time
= 0;
964 if (ms_setting
.rep_write_srv
> 0)
966 /* for replication test, need enable reconnect feature */
967 ms_setting
.reconnect
= true;
970 if (ms_setting
.facebook_test
&& (ms_setting
.mult_key_num
< 2))
972 fprintf(stderr
, "facebook test must work with multi-get, "
973 "please specify multi-get key number "
974 "with '--division' option.\n");
978 if (ms_setting
.facebook_test
&& ms_setting
.udp
)
980 fprintf(stderr
, "facebook test couldn't work with UDP.\n");
984 if (ms_setting
.udp
&& (ms_setting
.sock_per_conn
> 1))
986 fprintf(stderr
, "UDP doesn't support multi-socks "
987 "in one connection structure.\n");
992 || ms_setting
.facebook_test
) && ms_setting
.binary_prot
)
994 fprintf(stderr
, "Binary protocol doesn't support UDP now.\n");
998 if ((ms_setting
.rep_write_srv
> 0) && (ms_setting
.srv_cnt
< 2))
1000 fprintf(stderr
, "Please specify 2 servers at least for replication\n");
1004 if ((ms_setting
.rep_write_srv
> 0)
1005 && (ms_setting
.srv_cnt
< ms_setting
.rep_write_srv
))
1007 fprintf(stderr
, "Servers to do replication writing "
1008 "is larger than the total servers\n");
1012 if (ms_setting
.udp
&& (ms_setting
.rep_write_srv
> 0))
1014 fprintf(stderr
, "UDP doesn't support replication.\n");
1018 if ((ms_setting
.rep_write_srv
> 0) && (ms_setting
.sock_per_conn
> 1))
1020 fprintf(stderr
, "Replication doesn't support multi-socks "
1021 "in one connection structure.\n");
1025 if (ms_setting
.facebook_test
&& (ms_setting
.rep_write_srv
> 0))
1027 fprintf(stderr
, "facebook test couldn't work with replication.\n");
1031 if (ms_setting
.reconnect
&& (ms_setting
.sock_per_conn
> 1))
1033 fprintf(stderr
, "Reconnection doesn't support multi-socks "
1034 "in one connection structure.\n");
1040 /* initialize global character block */
1041 ms_init_random_block();
1043 } /* ms_setting_slapmode_init_post */
1047 * post part of initialization of setting structure
1049 void ms_setting_init_post()
1051 ms_get_serverlist(ms_setting
.srv_str
);
1052 ms_setting_slapmode_init_post();
1057 * clean up the global setting structure
1059 void ms_setting_cleanup()
1061 if (ms_setting
.distr
!= NULL
)
1063 free(ms_setting
.distr
);
1066 if (ms_setting
.char_block
!= NULL
)
1068 free(ms_setting
.char_block
);
1071 if (ms_setting
.srv_str
!= NULL
)
1073 free(ms_setting
.srv_str
);
1076 if (ms_setting
.cfg_file
!= NULL
)
1078 free(ms_setting
.cfg_file
);
1081 if (ms_setting
.servers
!= NULL
)
1083 free(ms_setting
.servers
);
1086 if (ms_setting
.key_distr
!= NULL
)
1088 free(ms_setting
.key_distr
);
1091 if (ms_setting
.value_distr
!= NULL
)
1093 free(ms_setting
.value_distr
);
1095 } /* ms_setting_cleanup */