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