3 * Author: Mingqiang Zhuang
5 * Created on February 10, 2009
7 * (c) Copyright 2009, Schooner Information Technology, Inc.
8 * http://www.schoonerinfotech.com/
18 #include "ms_setting.h"
21 #define MAX_EXEC_NUM 0x4000000000000000 /* 1 << 62 */
22 #define ADDR_ALIGN(addr) ((addr + 15) & ~(16 - 1)) /* 16 bytes aligned */
23 #define RAND_CHAR_SIZE (10 * 1024 * 1024) /* 10M character table */
24 #define RESERVED_RAND_CHAR_SIZE (2 * 1024 * 1024) /* reserved 2M to avoid pointer sloping over */
26 #define DEFAULT_THREADS_NUM 1 /* default start one thread */
27 #define DEFAULT_CONNS_NUM 16 /* default each thread with 16 connections */
28 #define DEFAULT_EXE_NUM 0 /* default execute number is 0 */
29 #define DEFAULT_VERIFY_RATE 0.0 /* default it doesn't do data verification */
30 #define DEFAULT_OVERWRITE_RATE 0.0 /* default it doesn't do overwrite */
31 #define DEFAULT_DIV 1 /* default it runs single get */
32 #define DEFAULT_RUN_TIME 600 /* default run time 10 minutes */
33 #define DEFAULT_WINDOW_SIZE (10 * UNIT_ITEMS_COUNT) /* default window size is 10k */
34 #define DEFAULT_SOCK_PER_CONN 1 /* default socks per connection is 1 */
36 /* Use this for string generation */
37 #define CHAR_COUNT 64 /* number of characters used to generate character table */
38 const char ALPHANUMBERICS
[]=
39 "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz.-";
41 ms_setting_st ms_setting
; /* store the settings specified by user */
44 /* read setting from configuration file */
45 static void ms_get_serverlist(char *str
);
46 static int ms_get_cpu_count(void);
47 ms_conf_type_t
ms_get_conf_type(char *line
);
48 static int ms_is_line_data(char *line
);
49 static int ms_read_is_data(char *line
, ssize_t nread
);
50 static void ms_no_config_file(void);
51 static void ms_parse_cfg_file(char *cfg_file
);
54 /* initialize setting structure */
55 static void ms_init_random_block(void);
56 static void ms_calc_avg_size(void);
57 static int ms_shuffle_distr(ms_distr_t
*distr
, int length
);
58 static void ms_build_distr(void);
59 static void ms_print_setting(void);
60 static void ms_setting_slapmode_init_pre(void);
61 static void ms_setting_slapmode_init_post(void);
63 #if !defined(HAVE_GETLINE)
65 static ssize_t
getline (char **line
, size_t *line_size
, FILE *fp
)
71 if (line
== NULL
|| line_size
== NULL
|| fp
== NULL
)
77 if (*line
== NULL
|| *line_size
== 0)
81 new_line
= (char *) realloc (*line
, *line_size
);
101 /* Make enough space for len+1 (for final NUL) bytes. */
102 if (cur_len
+ 1 >= *line_size
)
105 SSIZE_MAX
< SIZE_MAX
? (size_t) SSIZE_MAX
+ 1 : SIZE_MAX
;
106 size_t needed
= (2 * (*line_size
)) + 1;
109 if (needed_max
< needed
)
111 if (cur_len
+ 1 >= needed
)
118 new_line
= (char *)realloc(*line
, needed
);
119 if (new_line
== NULL
)
135 (*line
)[cur_len
] = '\0';
137 return (ssize_t
)cur_len
;
143 * parse the server list string, and build the servers
144 * information structure array. this function is used to parse
145 * the command line options specified by user.
147 * @param str, the string of server list
149 static void ms_get_serverlist(char *str
)
154 char *end_ptr
= str
+ strlen(str
);
155 ms_mcd_server_t
*srvs
= NULL
;
160 * Servers list format is like this. For example:
161 * "localhost:11108, localhost:11109"
163 for (begin_ptr
= str
, string
= index(str
, ',');
164 begin_ptr
!= end_ptr
;
165 string
= index(begin_ptr
, ','))
171 memcpy(buffer
, begin_ptr
, (size_t)(string
- begin_ptr
));
172 buffer
[(unsigned int)(string
- begin_ptr
)]= '\0';
173 begin_ptr
= string
+ 1;
177 size_t length
= strlen(begin_ptr
);
178 memcpy(buffer
, begin_ptr
, length
);
179 buffer
[length
]= '\0';
183 ptr
= index(buffer
, ':');
189 port
= strtol(ptr
, (char **)NULL
, 10);
192 assert(ms_setting
.srv_cnt
< ms_setting
.total_srv_cnt
);
193 strcpy(ms_setting
.servers
[ms_setting
.srv_cnt
].srv_host_name
, buffer
);
194 ms_setting
.servers
[ms_setting
.srv_cnt
].srv_port
= (int)port
;
195 ms_setting
.servers
[ms_setting
.srv_cnt
].disconn_cnt
= 0;
196 ms_setting
.servers
[ms_setting
.srv_cnt
].reconn_cnt
= 0;
197 ms_setting
.srv_cnt
++;
199 if (ms_setting
.srv_cnt
>= ms_setting
.total_srv_cnt
)
201 srvs
= (ms_mcd_server_t
*)realloc(
203 (uint64_t)ms_setting
.total_srv_cnt
204 * sizeof(ms_mcd_server_t
) * 2);
207 fprintf(stderr
, "Can't reallocate servers structure.\n");
210 ms_setting
.servers
= srvs
;
211 ms_setting
.total_srv_cnt
*= 2;
214 if (isspace(*begin_ptr
))
217 } /* ms_get_serverlist */
221 * used to get the CPU count of the current system
223 * @return return the cpu count if get, else return 1
225 static int ms_get_cpu_count()
227 #ifdef HAVE__SC_NPROCESSORS_ONLN
228 return sysconf(_SC_NPROCESSORS_CONF
);
231 # ifdef HAVE_CPU_SET_T
235 sched_getaffinity(0, sizeof(cpu_set_t
), &cpu_set
);
237 for (int i
= 0; i
< (sizeof(cpu_set_t
) * 8); i
++)
239 if (CPU_ISSET(i
, &cpu_set
))
250 /* the system with one cpu at least */
252 } /* ms_get_cpu_count */
256 * used to get the configure type based on the type string read
257 * from the configuration file.
259 * @param line, string of one line
261 * @return ms_conf_type_t
263 ms_conf_type_t
ms_get_conf_type(char *line
)
265 if (! memcmp(line
, "key", strlen("key")))
269 else if (! memcmp(line
, "value", strlen("value")))
273 else if (! memcmp(line
, "cmd", strlen("cmd")))
281 } /* ms_get_conf_type */
285 * judge whether the line is a line with useful data. used to
286 * parse the configuration file.
288 * @param line, string of one line
290 * @return if success, return 1, else return 0
292 static int ms_is_line_data(char *line
)
294 assert(line
!= NULL
);
296 char *begin_ptr
= line
;
298 while (isspace(*begin_ptr
))
302 if ((begin_ptr
[0] == '\0') || (begin_ptr
[0] == '#'))
306 } /* ms_is_line_data */
310 * function to bypass blank line and comments
312 * @param line, string of one line
313 * @param nread, length of the line
315 * @return if it's EOF or not line data, return 0, else return 1
317 static int ms_read_is_data(char *line
, ssize_t nread
)
319 if ((nread
== EOF
) || ! ms_is_line_data(line
))
323 } /* ms_read_is_data */
327 * if no configuration file, use this function to create the default
328 * configuration file.
330 static void ms_no_config_file()
332 FILE *fd
= fopen("config", "w+");
334 fprintf(fd
, "%s", DEFAULT_CONGIF_STR
);
337 ms_setting
.cfg_file
= strdup("config");
338 } /* ms_no_config_file */
342 * parse the configuration file
344 * @param cfg_file, the configuration file name
346 static void ms_parse_cfg_file(char *cfg_file
)
349 size_t start_len
, end_len
;
356 ms_conf_type_t conf_type
;
358 ms_key_distr_t
*key_distr
= NULL
;
359 ms_value_distr_t
*val_distr
= NULL
;
362 if (cfg_file
== NULL
)
365 cfg_file
= ms_setting
.cfg_file
;
369 /*read key value configure file*/
370 if ((f
= fopen(cfg_file
, "r")) == NULL
)
372 fprintf(stderr
, "Can not open file: '%s'.\n", cfg_file
);
378 if ((((nread
= getline(&line
, &read_len
, f
)) == 1)
379 || ! ms_read_is_data(line
, nread
)) && (nread
!= EOF
)) /* bypass blank line */
383 fprintf(stderr
, "Bad configuration file, no configuration find.\n");
386 conf_type
= ms_get_conf_type(line
);
390 while (! end_of_file
)
397 if ((((nread
= getline(&line
, &read_len
, f
)) == 1)
398 || ! ms_read_is_data(line
, nread
)) && (nread
!= EOF
)) /* bypass blank line */
403 if (sscanf(line
, "%lu %lu %lf ", &start_len
,
404 &end_len
, &proportion
) != 3)
406 conf_type
= ms_get_conf_type(line
);
409 ms_setting
.key_distr
[ms_setting
.key_rng_cnt
].start_len
= start_len
;
410 ms_setting
.key_distr
[ms_setting
.key_rng_cnt
].end_len
= end_len
;
411 ms_setting
.key_distr
[ms_setting
.key_rng_cnt
].key_prop
= proportion
;
412 ms_setting
.key_rng_cnt
++;
414 if (ms_setting
.key_rng_cnt
>= ms_setting
.total_key_rng_cnt
)
416 key_distr
= (ms_key_distr_t
*)realloc(
417 ms_setting
.key_distr
,
418 (uint64_t)ms_setting
.
419 total_key_rng_cnt
* sizeof(ms_key_distr_t
) * 2);
420 if (key_distr
== NULL
)
423 "Can't reallocate key distribution structure.\n");
426 ms_setting
.key_distr
= key_distr
;
427 ms_setting
.total_key_rng_cnt
*= 2;
439 if ((((nread
= getline(&line
, &read_len
, f
)) == 1)
440 || ! ms_read_is_data(line
, nread
)) && (nread
!= EOF
)) /* bypass blank line */
445 if (sscanf(line
, "%lu %lu %lf %lu", &start_len
, &end_len
,
446 &proportion
, &frequence
) != 3)
448 conf_type
= ms_get_conf_type(line
);
451 ms_setting
.value_distr
[ms_setting
.val_rng_cnt
].start_len
=
453 ms_setting
.value_distr
[ms_setting
.val_rng_cnt
].end_len
= end_len
;
454 ms_setting
.value_distr
[ms_setting
.val_rng_cnt
].value_prop
=
456 ms_setting
.val_rng_cnt
++;
458 if (ms_setting
.val_rng_cnt
>= ms_setting
.total_val_rng_cnt
)
460 val_distr
= (ms_value_distr_t
*)realloc(
461 ms_setting
.value_distr
,
462 (uint64_t)ms_setting
.
463 total_val_rng_cnt
* sizeof(ms_value_distr_t
) * 2);
464 if (val_distr
== NULL
)
467 "Can't reallocate key distribution structure.\n");
470 ms_setting
.value_distr
= val_distr
;
471 ms_setting
.total_val_rng_cnt
*= 2;
483 if ((((nread
= getline(&line
, &read_len
, f
)) == 1)
484 || ! ms_read_is_data(line
, nread
)) && (nread
!= EOF
)) /* bypass blank line */
489 if (sscanf(line
, "%d %lf\n", &cmd_type
, &proportion
) != 2)
491 conf_type
= ms_get_conf_type(line
);
494 ms_setting
.cmd_distr
[ms_setting
.cmd_used_count
].cmd_type
=
496 ms_setting
.cmd_distr
[ms_setting
.cmd_used_count
].cmd_prop
=
498 ms_setting
.cmd_used_count
++;
508 if ((((nread
= getline(&line
, &read_len
, f
)) == 1)
509 || ! ms_read_is_data(line
, nread
)) && (nread
!= EOF
)) /* bypass blank line */
514 if ((conf_type
= ms_get_conf_type(line
)) != CONF_NULL
)
535 remove(ms_setting
.cfg_file
);
540 } /* ms_parse_cfg_file */
543 /* calculate the average size of key and value */
544 static void ms_calc_avg_size()
546 double avg_val_size
= 0.0;
547 double avg_key_size
= 0.0;
550 double averge_len
= 0.0;
554 for (int j
= 0; j
< ms_setting
.val_rng_cnt
; j
++)
556 val_pro
= ms_setting
.value_distr
[j
].value_prop
;
557 start_len
= ms_setting
.value_distr
[j
].start_len
;
558 end_len
= ms_setting
.value_distr
[j
].end_len
;
560 averge_len
= val_pro
* ((double)(start_len
+ end_len
)) / 2;
561 avg_val_size
+= averge_len
;
564 for (int j
= 0; j
< ms_setting
.key_rng_cnt
; j
++)
566 key_pro
= ms_setting
.key_distr
[j
].key_prop
;
567 start_len
= ms_setting
.key_distr
[j
].start_len
;
568 end_len
= ms_setting
.key_distr
[j
].end_len
;
570 averge_len
= key_pro
* ((double)(start_len
+ end_len
)) / 2;
571 avg_key_size
+= averge_len
;
574 ms_setting
.avg_val_size
= (size_t)avg_val_size
;
575 ms_setting
.avg_key_size
= (size_t)avg_key_size
;
576 } /* ms_calc_avg_size */
580 * used to shuffle key and value distribution array to ensure
581 * (key, value) pair with different set.
583 * @param distr, pointer of distribution structure array
584 * @param length, length of the array
586 * @return always return 0
588 static int ms_shuffle_distr(ms_distr_t
*distr
, int length
)
595 for (i
= 0; i
< length
; i
++)
598 j
= (int)(rnd
% (length
- i
)) + i
;
603 tmp_size
= distr
[j
].key_size
;
604 distr
[j
].key_size
= distr
[i
].key_size
;
605 distr
[i
].key_size
= tmp_size
;
609 tmp_offset
= distr
[j
].key_offset
;
610 distr
[j
].key_offset
= distr
[i
].key_offset
;
611 distr
[i
].key_offset
= tmp_offset
;
615 tmp_size
= distr
[j
].value_size
;
616 distr
[j
].value_size
= distr
[i
].value_size
;
617 distr
[i
].value_size
= tmp_size
;
626 } /* ms_shuffle_distr */
630 * according to the key and value distribution, to build the
631 * (key, value) pair distribution. the (key, value) pair
632 * distribution array is global, each connection set or get
633 * object keeping this distribution, for the final result, we
634 * can reach the expected key and value distribution.
636 static void ms_build_distr()
642 size_t average_len
= 0;
647 ms_distr_t
*distr
= NULL
;
648 int units
= (int)ms_setting
.win_size
/ UNIT_ITEMS_COUNT
;
650 /* calculate average value size and key size */
653 ms_setting
.char_blk_size
= RAND_CHAR_SIZE
;
655 (int)((ms_setting
.char_blk_size
- RESERVED_RAND_CHAR_SIZE
)
658 ms_setting
.distr
= (ms_distr_t
*)malloc(
659 sizeof(ms_distr_t
) * ms_setting
.win_size
);
660 if (ms_setting
.distr
== NULL
)
662 fprintf(stderr
, "Can't allocate distribution array.");
667 * character block is divided by how many different key
668 * size, each different key size has the same size character
671 for (int m
= 0; m
< units
; m
++)
673 for (int i
= 0; i
< UNIT_ITEMS_COUNT
; i
++)
675 ms_setting
.distr
[m
* UNIT_ITEMS_COUNT
+ i
].key_offset
=
676 ADDR_ALIGN(key_scope_size
* i
);
680 /* initialize key size distribution */
681 for (int m
= 0; m
< units
; m
++)
683 for (int j
= 0; j
< ms_setting
.key_rng_cnt
; j
++)
685 key_cnt
= (int)(UNIT_ITEMS_COUNT
* ms_setting
.key_distr
[j
].key_prop
);
686 start_len
= ms_setting
.key_distr
[j
].start_len
;
687 end_len
= ms_setting
.key_distr
[j
].end_len
;
688 if ((start_len
< MIN_KEY_SIZE
) || (end_len
< MIN_KEY_SIZE
))
690 fprintf(stderr
, "key length must be greater than 16 bytes.\n");
694 if (! ms_setting
.binary_prot
695 && ((start_len
> MAX_KEY_SIZE
) || (end_len
> MAX_KEY_SIZE
)))
697 fprintf(stderr
, "key length must be less than 250 bytes.\n");
701 average_len
= (start_len
+ end_len
) / 2;
702 diff_len
= (end_len
- start_len
) / 2;
703 for (int k
= 0; k
< key_cnt
; k
++)
705 if (offset
>= (m
+ 1) * UNIT_ITEMS_COUNT
)
712 ms_setting
.distr
[offset
].key_size
=
713 (diff_len
== 0) ? average_len
:
714 average_len
+ (size_t)rnd
719 ms_setting
.distr
[offset
].key_size
=
720 (diff_len
== 0) ? average_len
:
721 average_len
- (size_t)rnd
728 if (offset
< (m
+ 1) * UNIT_ITEMS_COUNT
)
730 end
= (m
+ 1) * UNIT_ITEMS_COUNT
- offset
;
731 for (int i
= 0; i
< end
; i
++)
733 ms_setting
.distr
[offset
].key_size
= ms_setting
.avg_key_size
;
740 /* initialize value distribution */
741 if (ms_setting
.fixed_value_size
!= 0)
743 for (int i
= 0; i
< units
* UNIT_ITEMS_COUNT
; i
++)
745 ms_setting
.distr
[i
].value_size
= ms_setting
.fixed_value_size
;
750 for (int m
= 0; m
< units
; m
++)
752 for (int j
= 0; j
< ms_setting
.val_rng_cnt
; j
++)
755 (int)(UNIT_ITEMS_COUNT
* ms_setting
.value_distr
[j
].value_prop
);
756 start_len
= ms_setting
.value_distr
[j
].start_len
;
757 end_len
= ms_setting
.value_distr
[j
].end_len
;
758 if ((start_len
<= 0) || (end_len
<= 0))
760 fprintf(stderr
, "value length must be greater than 0 bytes.\n");
764 if ((start_len
> MAX_VALUE_SIZE
) || (end_len
> MAX_VALUE_SIZE
))
766 fprintf(stderr
, "key length must be less than or equal to 1M.\n");
770 average_len
= (start_len
+ end_len
) / 2;
771 diff_len
= (end_len
- start_len
) / 2;
772 for (int k
= 0; k
< value_cnt
; k
++)
774 if (offset
>= (m
+ 1) * UNIT_ITEMS_COUNT
)
781 ms_setting
.distr
[offset
].value_size
=
782 (diff_len
== 0) ? average_len
:
784 + (size_t)rnd
% diff_len
;
788 ms_setting
.distr
[offset
].value_size
=
789 (diff_len
== 0) ? average_len
:
791 - (size_t)rnd
% diff_len
;
797 if (offset
< (m
+ 1) * UNIT_ITEMS_COUNT
)
799 end
= (m
+ 1) * UNIT_ITEMS_COUNT
- offset
;
800 for (int i
= 0; i
< end
; i
++)
802 ms_setting
.distr
[offset
++].value_size
= ms_setting
.avg_val_size
;
808 /* shuffle distribution */
809 for (int i
= 0; i
< units
; i
++)
811 distr
= &ms_setting
.distr
[i
* UNIT_ITEMS_COUNT
];
812 for (int j
= 0; j
< 4; j
++)
814 ms_shuffle_distr(distr
, UNIT_ITEMS_COUNT
);
817 } /* ms_build_distr */
821 * used to initialize the global character block. The character
822 * block is used to generate the suffix of the key and value. we
823 * only store a pointer in the character block for each key
824 * suffix or value string. It can save much memory to store key
827 static void ms_init_random_block()
831 assert(ms_setting
.char_blk_size
> 0);
833 ms_setting
.char_block
= (char *)malloc(ms_setting
.char_blk_size
);
834 if (ms_setting
.char_block
== NULL
)
836 fprintf(stderr
, "Can't allocate global char block.");
839 ptr
= ms_setting
.char_block
;
841 for (int i
= 0; (size_t)i
< ms_setting
.char_blk_size
; i
++)
843 *(ptr
++)= ALPHANUMBERICS
[random() % CHAR_COUNT
];
845 } /* ms_init_random_block */
849 * after initialization, call this function to output the main
850 * configuration user specified.
852 static void ms_print_setting()
854 fprintf(stdout
, "threads count: %d\n", ms_setting
.nthreads
);
855 fprintf(stdout
, "concurrency: %d\n", ms_setting
.nconns
);
856 if (ms_setting
.run_time
> 0)
858 fprintf(stdout
, "run time: %ds\n", ms_setting
.run_time
);
862 fprintf(stdout
, "execute number: %" PRId64
"\n", ms_setting
.exec_num
);
864 fprintf(stdout
, "windows size: %" PRId64
"k\n",
865 (int64_t)(ms_setting
.win_size
/ 1024));
866 fprintf(stdout
, "set proportion: set_prop=%.2f\n",
867 ms_setting
.cmd_distr
[CMD_SET
].cmd_prop
);
868 fprintf(stdout
, "get proportion: get_prop=%.2f\n",
869 ms_setting
.cmd_distr
[CMD_GET
].cmd_prop
);
871 } /* ms_print_setting */
875 * previous part of slap mode initialization of setting structure
877 static void ms_setting_slapmode_init_pre()
879 ms_setting
.exec_num
= DEFAULT_EXE_NUM
;
880 ms_setting
.verify_percent
= DEFAULT_VERIFY_RATE
;
881 ms_setting
.exp_ver_per
= DEFAULT_VERIFY_RATE
;
882 ms_setting
.overwrite_percent
= DEFAULT_OVERWRITE_RATE
;
883 ms_setting
.mult_key_num
= DEFAULT_DIV
;
884 ms_setting
.fixed_value_size
= 0;
885 ms_setting
.win_size
= DEFAULT_WINDOW_SIZE
;
886 ms_setting
.udp
= false;
887 ms_setting
.reconnect
= false;
888 ms_setting
.verbose
= false;
889 ms_setting
.facebook_test
= false;
890 ms_setting
.binary_prot
= false;
891 ms_setting
.stat_freq
= 0;
892 ms_setting
.srv_str
= NULL
;
893 ms_setting
.cfg_file
= NULL
;
894 ms_setting
.sock_per_conn
= DEFAULT_SOCK_PER_CONN
;
895 ms_setting
.expected_tps
= 0;
896 ms_setting
.rep_write_srv
= 0;
897 } /* ms_setting_slapmode_init_pre */
901 * previous part of initialization of setting structure
903 void ms_setting_init_pre()
905 memset(&ms_setting
, 0, sizeof(ms_setting
));
907 /* common initialize */
908 ms_setting
.ncpu
= ms_get_cpu_count();
909 ms_setting
.nthreads
= DEFAULT_THREADS_NUM
;
910 ms_setting
.nconns
= DEFAULT_CONNS_NUM
;
911 ms_setting
.run_time
= DEFAULT_RUN_TIME
;
912 ms_setting
.total_srv_cnt
= MCD_SRVS_NUM_INIT
;
913 ms_setting
.servers
= (ms_mcd_server_t
*)malloc(
914 (uint64_t)ms_setting
.total_srv_cnt
915 * sizeof(ms_mcd_server_t
));
916 if (ms_setting
.servers
== NULL
)
918 fprintf(stderr
, "Can't allocate servers structure.\n");
922 ms_setting_slapmode_init_pre();
923 } /* ms_setting_init_pre */
927 * post part of slap mode initialization of setting structure
929 static void ms_setting_slapmode_init_post()
931 ms_setting
.total_key_rng_cnt
= KEY_RANGE_COUNT_INIT
;
932 ms_setting
.key_distr
= (ms_key_distr_t
*)malloc(
933 (uint64_t)ms_setting
.total_key_rng_cnt
934 * sizeof(ms_key_distr_t
));
935 if (ms_setting
.key_distr
== NULL
)
937 fprintf(stderr
, "Can't allocate key distribution structure.\n");
941 ms_setting
.total_val_rng_cnt
= VALUE_RANGE_COUNT_INIT
;
942 ms_setting
.value_distr
= (ms_value_distr_t
*)malloc(
943 (uint64_t)ms_setting
.total_val_rng_cnt
946 if (ms_setting
.value_distr
== NULL
)
948 fprintf(stderr
, "Can't allocate value distribution structure.\n");
952 ms_parse_cfg_file(ms_setting
.cfg_file
);
955 if ((ms_setting
.exec_num
== 0) && (ms_setting
.run_time
!= 0))
957 ms_setting
.exec_num
= (int64_t)MAX_EXEC_NUM
;
961 /* execute number mode */
962 ms_setting
.run_time
= 0;
965 if (ms_setting
.rep_write_srv
> 0)
967 /* for replication test, need enable reconnect feature */
968 ms_setting
.reconnect
= true;
971 if (ms_setting
.facebook_test
&& (ms_setting
.mult_key_num
< 2))
973 fprintf(stderr
, "facebook test must work with multi-get, "
974 "please specify multi-get key number "
975 "with '--division' option.\n");
979 if (ms_setting
.facebook_test
&& ms_setting
.udp
)
981 fprintf(stderr
, "facebook test couldn't work with UDP.\n");
985 if (ms_setting
.udp
&& (ms_setting
.sock_per_conn
> 1))
987 fprintf(stderr
, "UDP doesn't support multi-socks "
988 "in one connection structure.\n");
993 || ms_setting
.facebook_test
) && ms_setting
.binary_prot
)
995 fprintf(stderr
, "Binary protocol doesn't support UDP now.\n");
999 if ((ms_setting
.rep_write_srv
> 0) && (ms_setting
.srv_cnt
< 2))
1001 fprintf(stderr
, "Please specify 2 servers at least for replication\n");
1005 if ((ms_setting
.rep_write_srv
> 0)
1006 && (ms_setting
.srv_cnt
< ms_setting
.rep_write_srv
))
1008 fprintf(stderr
, "Servers to do replication writing "
1009 "is larger than the total servers\n");
1013 if (ms_setting
.udp
&& (ms_setting
.rep_write_srv
> 0))
1015 fprintf(stderr
, "UDP doesn't support replication.\n");
1019 if ((ms_setting
.rep_write_srv
> 0) && (ms_setting
.sock_per_conn
> 1))
1021 fprintf(stderr
, "Replication doesn't support multi-socks "
1022 "in one connection structure.\n");
1026 if (ms_setting
.facebook_test
&& (ms_setting
.rep_write_srv
> 0))
1028 fprintf(stderr
, "facebook test couldn't work with replication.\n");
1032 if (ms_setting
.reconnect
&& (ms_setting
.sock_per_conn
> 1))
1034 fprintf(stderr
, "Reconnection doesn't support multi-socks "
1035 "in one connection structure.\n");
1041 /* initialize global character block */
1042 ms_init_random_block();
1044 } /* ms_setting_slapmode_init_post */
1048 * post part of initialization of setting structure
1050 void ms_setting_init_post()
1052 ms_get_serverlist(ms_setting
.srv_str
);
1053 ms_setting_slapmode_init_post();
1058 * clean up the global setting structure
1060 void ms_setting_cleanup()
1062 if (ms_setting
.distr
!= NULL
)
1064 free(ms_setting
.distr
);
1067 if (ms_setting
.char_block
!= NULL
)
1069 free(ms_setting
.char_block
);
1072 if (ms_setting
.srv_str
!= NULL
)
1074 free(ms_setting
.srv_str
);
1077 if (ms_setting
.cfg_file
!= NULL
)
1079 free(ms_setting
.cfg_file
);
1082 if (ms_setting
.servers
!= NULL
)
1084 free(ms_setting
.servers
);
1087 if (ms_setting
.key_distr
!= NULL
)
1089 free(ms_setting
.key_distr
);
1092 if (ms_setting
.value_distr
!= NULL
)
1094 free(ms_setting
.value_distr
);
1096 } /* ms_setting_cleanup */