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