@@ -108,6 +108,7 @@ static void conn_free(conn *c);
108
108
109
109
/** exported globals **/
110
110
struct stats stats ;
111
+ struct stats_state stats_state ;
111
112
struct settings settings ;
112
113
time_t process_started ; /* when the process was started */
113
114
conn * * conns ;
@@ -178,20 +179,9 @@ static rel_time_t realtime(const time_t exptime) {
178
179
}
179
180
180
181
static void stats_init (void ) {
181
- stats .curr_items = stats .total_items = stats .curr_conns = stats .total_conns = stats .conn_structs = 0 ;
182
- stats .get_cmds = stats .set_cmds = stats .get_hits = stats .get_misses = stats .evictions = stats .reclaimed = 0 ;
183
- stats .touch_cmds = stats .touch_misses = stats .touch_hits = stats .rejected_conns = 0 ;
184
- stats .malloc_fails = 0 ;
185
- stats .curr_bytes = stats .listen_disabled_num = 0 ;
186
- stats .hash_power_level = stats .hash_bytes = stats .hash_is_expanding = 0 ;
187
- stats .expired_unfetched = stats .evicted_unfetched = 0 ;
188
- stats .slabs_moved = 0 ;
189
- stats .lru_maintainer_juggles = 0 ;
190
- stats .accepting_conns = true; /* assuming we start in this state. */
191
- stats .slab_reassign_running = false;
192
- stats .lru_crawler_running = false;
193
- stats .lru_crawler_starts = 0 ;
194
- stats .time_in_listen_disabled_us = 0 ;
182
+ memset (& stats , 0 , sizeof (struct stats ));
183
+ memset (& stats_state , 0 , sizeof (struct stats_state ));
184
+ stats_state .accepting_conns = true; /* assuming we start in this state. */
195
185
196
186
/* make the time we started always be 2 seconds before we really
197
187
did, so time(0) - time.started is never zero. if so, things
@@ -203,12 +193,7 @@ static void stats_init(void) {
203
193
204
194
static void stats_reset (void ) {
205
195
STATS_LOCK ();
206
- stats .total_items = stats .total_conns = 0 ;
207
- stats .rejected_conns = 0 ;
208
- stats .malloc_fails = 0 ;
209
- stats .evictions = 0 ;
210
- stats .reclaimed = 0 ;
211
- stats .listen_disabled_num = 0 ;
196
+ memset (& stats , 0 , sizeof (struct stats ));
212
197
stats_prefix_clear ();
213
198
STATS_UNLOCK ();
214
199
threadlocal_stats_reset ();
@@ -513,7 +498,7 @@ conn *conn_new(const int sfd, enum conn_states init_state,
513
498
}
514
499
515
500
STATS_LOCK ();
516
- stats .conn_structs ++ ;
501
+ stats_state .conn_structs ++ ;
517
502
STATS_UNLOCK ();
518
503
519
504
c -> sfd = sfd ;
@@ -593,7 +578,7 @@ conn *conn_new(const int sfd, enum conn_states init_state,
593
578
}
594
579
595
580
STATS_LOCK ();
596
- stats .curr_conns ++ ;
581
+ stats_state .curr_conns ++ ;
597
582
stats .total_conns ++ ;
598
583
STATS_UNLOCK ();
599
584
@@ -697,7 +682,7 @@ static void conn_close(conn *c) {
697
682
pthread_mutex_unlock (& conn_lock );
698
683
699
684
STATS_LOCK ();
700
- stats .curr_conns -- ;
685
+ stats_state .curr_conns -- ;
701
686
STATS_UNLOCK ();
702
687
703
688
return ;
@@ -2714,13 +2699,13 @@ static void server_stats(ADD_STAT add_stats, conn *c) {
2714
2699
(long )usage .ru_stime .tv_usec );
2715
2700
#endif /* !WIN32 */
2716
2701
2717
- APPEND_STAT ("curr_connections" , "%llu" , (unsigned long long )stats .curr_conns - 1 );
2702
+ APPEND_STAT ("curr_connections" , "%llu" , (unsigned long long )stats_state .curr_conns - 1 );
2718
2703
APPEND_STAT ("total_connections" , "%llu" , (unsigned long long )stats .total_conns );
2719
2704
if (settings .maxconns_fast ) {
2720
2705
APPEND_STAT ("rejected_connections" , "%llu" , (unsigned long long )stats .rejected_conns );
2721
2706
}
2722
- APPEND_STAT ("connection_structures" , "%u" , stats .conn_structs );
2723
- APPEND_STAT ("reserved_fds" , "%u" , stats .reserved_fds );
2707
+ APPEND_STAT ("connection_structures" , "%u" , stats_state .conn_structs );
2708
+ APPEND_STAT ("reserved_fds" , "%u" , stats_state .reserved_fds );
2724
2709
APPEND_STAT ("cmd_get" , "%llu" , (unsigned long long )thread_stats .get_cmds );
2725
2710
APPEND_STAT ("cmd_set" , "%llu" , (unsigned long long )slab_stats .set_cmds );
2726
2711
APPEND_STAT ("cmd_flush" , "%llu" , (unsigned long long )thread_stats .flush_cmds );
@@ -2748,24 +2733,24 @@ static void server_stats(ADD_STAT add_stats, conn *c) {
2748
2733
APPEND_STAT ("bytes_read" , "%llu" , (unsigned long long )thread_stats .bytes_read );
2749
2734
APPEND_STAT ("bytes_written" , "%llu" , (unsigned long long )thread_stats .bytes_written );
2750
2735
APPEND_STAT ("limit_maxbytes" , "%llu" , (unsigned long long )settings .maxbytes );
2751
- APPEND_STAT ("accepting_conns" , "%u" , stats .accepting_conns );
2736
+ APPEND_STAT ("accepting_conns" , "%u" , stats_state .accepting_conns );
2752
2737
APPEND_STAT ("listen_disabled_num" , "%llu" , (unsigned long long )stats .listen_disabled_num );
2753
2738
APPEND_STAT ("time_in_listen_disabled_us" , "%llu" , stats .time_in_listen_disabled_us );
2754
2739
APPEND_STAT ("threads" , "%d" , settings .num_threads );
2755
2740
APPEND_STAT ("conn_yields" , "%llu" , (unsigned long long )thread_stats .conn_yields );
2756
- APPEND_STAT ("hash_power_level" , "%u" , stats .hash_power_level );
2757
- APPEND_STAT ("hash_bytes" , "%llu" , (unsigned long long )stats .hash_bytes );
2758
- APPEND_STAT ("hash_is_expanding" , "%u" , stats .hash_is_expanding );
2741
+ APPEND_STAT ("hash_power_level" , "%u" , stats_state .hash_power_level );
2742
+ APPEND_STAT ("hash_bytes" , "%llu" , (unsigned long long )stats_state .hash_bytes );
2743
+ APPEND_STAT ("hash_is_expanding" , "%u" , stats_state .hash_is_expanding );
2759
2744
if (settings .slab_reassign ) {
2760
2745
APPEND_STAT ("slab_reassign_rescues" , "%llu" , stats .slab_reassign_rescues );
2761
2746
APPEND_STAT ("slab_reassign_evictions_nomem" , "%llu" , stats .slab_reassign_evictions_nomem );
2762
2747
APPEND_STAT ("slab_reassign_inline_reclaim" , "%llu" , stats .slab_reassign_inline_reclaim );
2763
2748
APPEND_STAT ("slab_reassign_busy_items" , "%llu" , stats .slab_reassign_busy_items );
2764
- APPEND_STAT ("slab_reassign_running" , "%u" , stats .slab_reassign_running );
2749
+ APPEND_STAT ("slab_reassign_running" , "%u" , stats_state .slab_reassign_running );
2765
2750
APPEND_STAT ("slabs_moved" , "%llu" , stats .slabs_moved );
2766
2751
}
2767
2752
if (settings .lru_crawler ) {
2768
- APPEND_STAT ("lru_crawler_running" , "%u" , stats .lru_crawler_running );
2753
+ APPEND_STAT ("lru_crawler_running" , "%u" , stats_state .lru_crawler_running );
2769
2754
APPEND_STAT ("lru_crawler_starts" , "%u" , stats .lru_crawler_starts );
2770
2755
}
2771
2756
if (settings .lru_maintainer_thread ) {
@@ -4180,11 +4165,11 @@ void do_accept_new_conns(const bool do_accept) {
4180
4165
(maxconns_exited .tv_sec - stats .maxconns_entered .tv_sec ) * 1000000
4181
4166
+ (maxconns_exited .tv_usec - stats .maxconns_entered .tv_usec );
4182
4167
stats .time_in_listen_disabled_us += elapsed_us ;
4183
- stats .accepting_conns = true;
4168
+ stats_state .accepting_conns = true;
4184
4169
STATS_UNLOCK ();
4185
4170
} else {
4186
4171
STATS_LOCK ();
4187
- stats .accepting_conns = false;
4172
+ stats_state .accepting_conns = false;
4188
4173
gettimeofday (& stats .maxconns_entered ,NULL );
4189
4174
stats .listen_disabled_num ++ ;
4190
4175
STATS_UNLOCK ();
@@ -4319,7 +4304,7 @@ static void drive_machine(conn *c) {
4319
4304
}
4320
4305
4321
4306
if (settings .maxconns_fast &&
4322
- stats .curr_conns + stats .reserved_fds >= settings .maxconns - 1 ) {
4307
+ stats_state .curr_conns + stats_state .reserved_fds >= settings .maxconns - 1 ) {
4323
4308
str = "ERROR Too many open connections\r\n" ;
4324
4309
res = write (sfd , str , strlen (str ));
4325
4310
close (sfd );
@@ -6093,7 +6078,7 @@ int main (int argc, char **argv) {
6093
6078
* is only an advisory.
6094
6079
*/
6095
6080
usleep (1000 );
6096
- if (stats .curr_conns + stats .reserved_fds >= settings .maxconns - 1 ) {
6081
+ if (stats_state .curr_conns + stats_state .reserved_fds >= settings .maxconns - 1 ) {
6097
6082
fprintf (stderr , "Maxconns setting is too low, use -c to increase.\n" );
6098
6083
exit (EXIT_FAILURE );
6099
6084
}
0 commit comments