Allows zero as a value for retry.
[m6w6/libmemcached] / clients / ms_setting.h
1 /*
2 * File: ms_setting.h
3 * Author: Mingqiang Zhuang
4 *
5 * Created on February 10, 2009
6 *
7 * (c) Copyright 2009, Schooner Information Technology, Inc.
8 * http://www.schoonerinfotech.com/
9 *
10 */
11 #ifndef MS_SETTING_H
12 #define MS_SETTING_H
13
14 #include "ms_memslap.h"
15
16 #ifdef __cplusplus
17 extern "C" {
18 #endif
19
20 #define MCD_SRVS_NUM_INIT 8
21 #define MCD_HOST_LENGTH 64
22 #define KEY_RANGE_COUNT_INIT 8
23 #define VALUE_RANGE_COUNT_INIT 8
24 #define PROP_ERROR 0.001
25
26 #define MIN_KEY_SIZE 16
27 #define MAX_KEY_SIZE 250
28 #define MAX_VALUE_SIZE (1024 * 1024)
29
30 /* the content of the configuration file for memslap running without configuration file */
31 #define DEFAULT_CONGIF_STR \
32 "key\n" \
33 "64 64 1\n" \
34 "value\n" \
35 "1024 1024 1\n" \
36 "cmd\n" \
37 "0 0.1\n" \
38 "1 0.9"
39
40 /* Used to parse the value length return by server and path string */
41 typedef struct token_s
42 {
43 char *value;
44 size_t length;
45 } token_t;
46
47 #define MAX_TOKENS 10
48
49 /* server information */
50 typedef struct mcd_server
51 {
52 char srv_host_name[MCD_HOST_LENGTH]; /* host name of server */
53 int srv_port; /* server port */
54
55 /* for calculating how long the server disconnects */
56 volatile uint32_t disconn_cnt; /* number of disconnections count */
57 volatile uint32_t reconn_cnt; /* number of reconnections count */
58 struct timeval disconn_time; /* start time of disconnection */
59 struct timeval reconn_time; /* end time of reconnection */
60 } ms_mcd_server_t;
61
62 /* information of an item distribution including key and value */
63 typedef struct distr
64 {
65 size_t key_size; /* size of key */
66 int key_offset; /* offset of one key in character block */
67 size_t value_size; /* size of value */
68 } ms_distr_t;
69
70 /* information of key distribution */
71 typedef struct key_distr
72 {
73 size_t start_len; /* start of the key length range */
74 size_t end_len; /* end of the key length range */
75 double key_prop; /* key proportion */
76 } ms_key_distr_t;
77
78 /* information of value distribution */
79 typedef struct value_distr
80 {
81 size_t start_len; /* start of the value length range */
82 size_t end_len; /* end of the value length range */
83 double value_prop; /* value proportion */
84 } ms_value_distr_t;
85
86 /* memcached command types */
87 typedef enum cmd_type
88 {
89 CMD_SET,
90 CMD_GET,
91 CMD_NULL
92 } ms_cmd_type_t;
93
94 /* types in the configuration file */
95 typedef enum conf_type
96 {
97 CONF_KEY,
98 CONF_VALUE,
99 CONF_CMD,
100 CONF_NULL
101 } ms_conf_type_t;
102
103 /* information of command distribution */
104 typedef struct cmd_distr
105 {
106 ms_cmd_type_t cmd_type; /* command type */
107 double cmd_prop; /* proportion of the command */
108 } ms_cmd_distr_t;
109
110 /* global setting structure */
111 typedef struct setting
112 {
113 uint32_t ncpu; /* cpu count of this system */
114 uint32_t nthreads; /* total thread count, must equal or less than cpu cores */
115 uint32_t nconns; /* total conn count, must multiply by total thread count */
116 int64_t exec_num; /* total execute number */
117 int run_time; /* total run time */
118
119 uint32_t char_blk_size; /* global character block size */
120 char *char_block; /* global character block with random character */
121 ms_distr_t *distr; /* distribution from configure file */
122
123 char *srv_str; /* string includes servers information */
124 char *cfg_file; /* configure file name */
125
126 ms_mcd_server_t *servers; /* servers array */
127 uint32_t total_srv_cnt; /* total servers count of the servers array */
128 uint32_t srv_cnt; /* servers count */
129
130 ms_key_distr_t *key_distr; /* array of key distribution */
131 int total_key_rng_cnt; /* total key range count of the array */
132 int key_rng_cnt; /* actual key range count */
133
134 ms_value_distr_t *value_distr; /* array of value distribution */
135 int total_val_rng_cnt; /* total value range count of the array */
136 int val_rng_cnt; /* actual value range count */
137
138 ms_cmd_distr_t cmd_distr[CMD_NULL]; /* total we have CMD_NULL commands */
139 int cmd_used_count; /* supported command count */
140
141 size_t fixed_value_size; /* fixed value size */
142 size_t avg_val_size; /* average value size */
143 size_t avg_key_size; /* average value size */
144
145 double verify_percent; /* percent of data verification */
146 double exp_ver_per; /* percent of data verification with expire time */
147 double overwrite_percent; /* percent of overwrite */
148 int mult_key_num; /* number of keys used by multi-get once */
149 size_t win_size; /* item window size per connection */
150 bool udp; /* whether or not use UDP */
151 int stat_freq; /* statistic frequency second */
152 bool reconnect; /* whether it reconnect when connection close */
153 bool verbose; /* whether it outputs detailed information when verification */
154 bool facebook_test; /* facebook test, TCP set and multi-get with UDP */
155 uint32_t sock_per_conn; /* number of socks per connection structure */
156 bool binary_prot_; /* whether it use binary protocol */
157 int expected_tps; /* expected throughput */
158 uint32_t rep_write_srv; /* which servers are used to do replication writing */
159 } ms_setting_st;
160
161 extern ms_setting_st ms_setting;
162
163 /* previous part of initialization of setting structure */
164 void ms_setting_init_pre(void);
165
166
167 /* post part of initialization of setting structure */
168 void ms_setting_init_post(void);
169
170
171 /* clean up the global setting structure */
172 void ms_setting_cleanup(void);
173
174
175 #define UNUSED_ARGUMENT(x) (void)x
176
177 #ifdef __cplusplus
178 }
179 #endif
180
181 #endif /* end of MS_SETTING_H */