@cryptotaxi247 / netdata-1 / commits / b52a98949

Optimizations Part 2 (#15267)

* make all pluginsd functions inline, instead of function pointers * dynamic MRG partitions based on the number of CPUs * report the right size of the MRG

Costa Tsaousis committed Jun 28, 2023 at 23:18 UTC b52a989497f68cddeeb0282f5fd650c4e373e477
9 files changed +272 -190
collectors/plugins.d/gperf-config.txt
+38 -29
@@ -1,43 +1,52 @@
1 +%struct-type
2 +%omit-struct-type
3 +%define hash-function-name gperf_keyword_hash_function
4 +%define lookup-function-name gperf_lookup_keyword
5 +%define word-array-name gperf_keywords
6 +%define constants-prefix GPERF_PARSER_
7 +%define slot-name keyword
8 +%global-table
9 +%null-strings
10 PARSER_KEYWORD;
11 %%
12 #
13 # Plugins Only Keywords
14 #
6 -FLUSH, pluginsd_flush, PARSER_INIT_PLUGINSD, WORKER_PARSER_FIRST_JOB + 1
7 -DISABLE, pluginsd_disable, PARSER_INIT_PLUGINSD, WORKER_PARSER_FIRST_JOB + 2
8 -EXIT, pluginsd_exit, PARSER_INIT_PLUGINSD, WORKER_PARSER_FIRST_JOB + 3
9 -HOST, pluginsd_host, PARSER_INIT_PLUGINSD, WORKER_PARSER_FIRST_JOB + 4
10 -HOST_DEFINE, pluginsd_host_define, PARSER_INIT_PLUGINSD, WORKER_PARSER_FIRST_JOB + 5
11 -HOST_DEFINE_END, pluginsd_host_define_end, PARSER_INIT_PLUGINSD, WORKER_PARSER_FIRST_JOB + 6
12 -HOST_LABEL, pluginsd_host_labels, PARSER_INIT_PLUGINSD, WORKER_PARSER_FIRST_JOB + 7
15 +FLUSH, 97, PARSER_INIT_PLUGINSD, WORKER_PARSER_FIRST_JOB + 1
16 +DISABLE, 98, PARSER_INIT_PLUGINSD, WORKER_PARSER_FIRST_JOB + 2
17 +EXIT, 99, PARSER_INIT_PLUGINSD, WORKER_PARSER_FIRST_JOB + 3
18 +HOST, 71, PARSER_INIT_PLUGINSD, WORKER_PARSER_FIRST_JOB + 4
19 +HOST_DEFINE, 72, PARSER_INIT_PLUGINSD, WORKER_PARSER_FIRST_JOB + 5
20 +HOST_DEFINE_END, 73, PARSER_INIT_PLUGINSD, WORKER_PARSER_FIRST_JOB + 6
21 +HOST_LABEL, 74, PARSER_INIT_PLUGINSD, WORKER_PARSER_FIRST_JOB + 7
22 #
23 # Common keywords
24 #
16 -BEGIN, pluginsd_begin, PARSER_INIT_PLUGINSD|PARSER_INIT_STREAMING, WORKER_PARSER_FIRST_JOB + 8
17 -CHART, pluginsd_chart, PARSER_INIT_PLUGINSD|PARSER_INIT_STREAMING, WORKER_PARSER_FIRST_JOB + 9
18 -CLABEL, pluginsd_clabel, PARSER_INIT_PLUGINSD|PARSER_INIT_STREAMING, WORKER_PARSER_FIRST_JOB + 10
19 -CLABEL_COMMIT, pluginsd_clabel_commit, PARSER_INIT_PLUGINSD|PARSER_INIT_STREAMING, WORKER_PARSER_FIRST_JOB + 11
20 -DIMENSION, pluginsd_dimension, PARSER_INIT_PLUGINSD|PARSER_INIT_STREAMING, WORKER_PARSER_FIRST_JOB + 12
21 -END, pluginsd_end, PARSER_INIT_PLUGINSD|PARSER_INIT_STREAMING, WORKER_PARSER_FIRST_JOB + 13
22 -FUNCTION, pluginsd_function, PARSER_INIT_PLUGINSD|PARSER_INIT_STREAMING, WORKER_PARSER_FIRST_JOB + 14
23 -FUNCTION_RESULT_BEGIN, pluginsd_function_result_begin, PARSER_INIT_PLUGINSD|PARSER_INIT_STREAMING, WORKER_PARSER_FIRST_JOB + 15
24 -LABEL, pluginsd_label, PARSER_INIT_PLUGINSD|PARSER_INIT_STREAMING, WORKER_PARSER_FIRST_JOB + 16
25 -OVERWRITE, pluginsd_overwrite, PARSER_INIT_PLUGINSD|PARSER_INIT_STREAMING, WORKER_PARSER_FIRST_JOB + 17
26 -SET, pluginsd_set, PARSER_INIT_PLUGINSD|PARSER_INIT_STREAMING, WORKER_PARSER_FIRST_JOB + 18
27 -VARIABLE, pluginsd_variable, PARSER_INIT_PLUGINSD|PARSER_INIT_STREAMING, WORKER_PARSER_FIRST_JOB + 19
25 +BEGIN, 12, PARSER_INIT_PLUGINSD|PARSER_INIT_STREAMING, WORKER_PARSER_FIRST_JOB + 8
26 +CHART, 32, PARSER_INIT_PLUGINSD|PARSER_INIT_STREAMING, WORKER_PARSER_FIRST_JOB + 9
27 +CLABEL, 34, PARSER_INIT_PLUGINSD|PARSER_INIT_STREAMING, WORKER_PARSER_FIRST_JOB + 10
28 +CLABEL_COMMIT, 35, PARSER_INIT_PLUGINSD|PARSER_INIT_STREAMING, WORKER_PARSER_FIRST_JOB + 11
29 +DIMENSION, 31, PARSER_INIT_PLUGINSD|PARSER_INIT_STREAMING, WORKER_PARSER_FIRST_JOB + 12
30 +END, 13, PARSER_INIT_PLUGINSD|PARSER_INIT_STREAMING, WORKER_PARSER_FIRST_JOB + 13
31 +FUNCTION, 41, PARSER_INIT_PLUGINSD|PARSER_INIT_STREAMING, WORKER_PARSER_FIRST_JOB + 14
32 +FUNCTION_RESULT_BEGIN, 42, PARSER_INIT_PLUGINSD|PARSER_INIT_STREAMING, WORKER_PARSER_FIRST_JOB + 15
33 +LABEL, 51, PARSER_INIT_PLUGINSD|PARSER_INIT_STREAMING, WORKER_PARSER_FIRST_JOB + 16
34 +OVERWRITE, 52, PARSER_INIT_PLUGINSD|PARSER_INIT_STREAMING, WORKER_PARSER_FIRST_JOB + 17
35 +SET, 11, PARSER_INIT_PLUGINSD|PARSER_INIT_STREAMING, WORKER_PARSER_FIRST_JOB + 18
36 +VARIABLE, 53, PARSER_INIT_PLUGINSD|PARSER_INIT_STREAMING, WORKER_PARSER_FIRST_JOB + 19
37 #
38 # Streaming only keywords
39 #
31 -CLAIMED_ID, streaming_claimed_id, PARSER_INIT_STREAMING, WORKER_PARSER_FIRST_JOB + 20
32 -BEGIN2, pluginsd_begin_v2, PARSER_INIT_STREAMING, WORKER_PARSER_FIRST_JOB + 21
33 -SET2, pluginsd_set_v2, PARSER_INIT_STREAMING, WORKER_PARSER_FIRST_JOB + 22
34 -END2, pluginsd_end_v2, PARSER_INIT_STREAMING, WORKER_PARSER_FIRST_JOB + 23
40 +CLAIMED_ID, 61, PARSER_INIT_STREAMING, WORKER_PARSER_FIRST_JOB + 20
41 +BEGIN2, 2, PARSER_INIT_STREAMING, WORKER_PARSER_FIRST_JOB + 21
42 +SET2, 1, PARSER_INIT_STREAMING, WORKER_PARSER_FIRST_JOB + 22
43 +END2, 3, PARSER_INIT_STREAMING, WORKER_PARSER_FIRST_JOB + 23
44 #
45 # Streaming Replication keywords
46 #
38 -CHART_DEFINITION_END, pluginsd_chart_definition_end, PARSER_INIT_STREAMING, WORKER_PARSER_FIRST_JOB + 24
39 -RBEGIN, pluginsd_replay_begin, PARSER_INIT_STREAMING, WORKER_PARSER_FIRST_JOB + 25
40 -RDSTATE, pluginsd_replay_rrddim_collection_state, PARSER_INIT_STREAMING, WORKER_PARSER_FIRST_JOB + 26
41 -REND, pluginsd_replay_end, PARSER_INIT_STREAMING, WORKER_PARSER_FIRST_JOB + 27
42 -RSET, pluginsd_replay_set, PARSER_INIT_STREAMING, WORKER_PARSER_FIRST_JOB + 28
43 -RSSTATE, pluginsd_replay_rrdset_collection_state, PARSER_INIT_STREAMING, WORKER_PARSER_FIRST_JOB + 29
47 +CHART_DEFINITION_END, 33, PARSER_INIT_STREAMING, WORKER_PARSER_FIRST_JOB + 24
48 +RBEGIN, 22, PARSER_INIT_STREAMING, WORKER_PARSER_FIRST_JOB + 25
49 +RDSTATE, 23, PARSER_INIT_STREAMING, WORKER_PARSER_FIRST_JOB + 26
50 +REND, 25, PARSER_INIT_STREAMING, WORKER_PARSER_FIRST_JOB + 27
51 +RSET, 21, PARSER_INIT_STREAMING, WORKER_PARSER_FIRST_JOB + 28
52 +RSSTATE, 24, PARSER_INIT_STREAMING, WORKER_PARSER_FIRST_JOB + 29
collectors/plugins.d/gperf-hashtable.h
+55 -56
@@ -1,6 +1,5 @@
1 -// SPDX-License-Identifier: GPL-3.0-or-later
1 /* ANSI-C code produced by gperf version 3.1 */
3 -/* Command-line: gperf --multiple-iterations=1000 --hash-function-name=gperf_keyword_hash_function --lookup-function-name=gperf_lookup_keyword --word-array-name=gperf_keywords --constants-prefix=GPERF_PARSER_ --struct-type --slot-name=keyword --global-table --null-strings --omit-struct-type --output-file=gperf-hashtable.h gperf-config.txt */
2 +/* Command-line: gperf --multiple-iterations=1000 --output-file=gperf-hashtable.h gperf-config.txt */
3 /* Computed positions: -k'1-2' */
4
5 #if !((' ' == 32) && ('!' == 33) && ('"' == 34) && ('#' == 35) \
@@ -83,66 +82,66 @@ gperf_keyword_hash_function (register const char *str, register size_t len)
82 static PARSER_KEYWORD gperf_keywords[] =
83 {
84 {(char*)0}, {(char*)0}, {(char*)0}, {(char*)0},
86 -#line 9 "gperf-config.txt"
87 - {"HOST", pluginsd_host, PARSER_INIT_PLUGINSD, WORKER_PARSER_FIRST_JOB + 4},
88 -#line 42 "gperf-config.txt"
89 - {"RSET", pluginsd_replay_set, PARSER_INIT_STREAMING, WORKER_PARSER_FIRST_JOB + 28},
90 -#line 17 "gperf-config.txt"
91 - {"CHART", pluginsd_chart, PARSER_INIT_PLUGINSD|PARSER_INIT_STREAMING, WORKER_PARSER_FIRST_JOB + 9},
92 - {(char*)0},
93 -#line 43 "gperf-config.txt"
94 - {"RSSTATE", pluginsd_replay_rrdset_collection_state, PARSER_INIT_STREAMING, WORKER_PARSER_FIRST_JOB + 29},
95 -#line 40 "gperf-config.txt"
96 - {"RDSTATE", pluginsd_replay_rrddim_collection_state, PARSER_INIT_STREAMING, WORKER_PARSER_FIRST_JOB + 26},
97 -#line 12 "gperf-config.txt"
98 - {"HOST_LABEL", pluginsd_host_labels, PARSER_INIT_PLUGINSD, WORKER_PARSER_FIRST_JOB + 7},
99 -#line 10 "gperf-config.txt"
100 - {"HOST_DEFINE", pluginsd_host_define, PARSER_INIT_PLUGINSD, WORKER_PARSER_FIRST_JOB + 5},
101 -#line 26 "gperf-config.txt"
102 - {"SET", pluginsd_set, PARSER_INIT_PLUGINSD|PARSER_INIT_STREAMING, WORKER_PARSER_FIRST_JOB + 18},
103 -#line 33 "gperf-config.txt"
104 - {"SET2", pluginsd_set_v2, PARSER_INIT_STREAMING, WORKER_PARSER_FIRST_JOB + 22},
105 -#line 41 "gperf-config.txt"
106 - {"REND", pluginsd_replay_end, PARSER_INIT_STREAMING, WORKER_PARSER_FIRST_JOB + 27},
107 -#line 11 "gperf-config.txt"
108 - {"HOST_DEFINE_END", pluginsd_host_define_end, PARSER_INIT_PLUGINSD, WORKER_PARSER_FIRST_JOB + 6},
85 #line 18 "gperf-config.txt"
110 - {"CLABEL", pluginsd_clabel, PARSER_INIT_PLUGINSD|PARSER_INIT_STREAMING, WORKER_PARSER_FIRST_JOB + 10},
111 -#line 39 "gperf-config.txt"
112 - {"RBEGIN", pluginsd_replay_begin, PARSER_INIT_STREAMING, WORKER_PARSER_FIRST_JOB + 25},
113 -#line 6 "gperf-config.txt"
114 - {"FLUSH", pluginsd_flush, PARSER_INIT_PLUGINSD, WORKER_PARSER_FIRST_JOB + 1},
115 -#line 22 "gperf-config.txt"
116 - {"FUNCTION", pluginsd_function, PARSER_INIT_PLUGINSD|PARSER_INIT_STREAMING, WORKER_PARSER_FIRST_JOB + 14},
86 + {"HOST", 71, PARSER_INIT_PLUGINSD, WORKER_PARSER_FIRST_JOB + 4},
87 +#line 51 "gperf-config.txt"
88 + {"RSET", 21, PARSER_INIT_STREAMING, WORKER_PARSER_FIRST_JOB + 28},
89 +#line 26 "gperf-config.txt"
90 + {"CHART", 32, PARSER_INIT_PLUGINSD|PARSER_INIT_STREAMING, WORKER_PARSER_FIRST_JOB + 9},
91 + {(char*)0},
92 +#line 52 "gperf-config.txt"
93 + {"RSSTATE", 24, PARSER_INIT_STREAMING, WORKER_PARSER_FIRST_JOB + 29},
94 +#line 49 "gperf-config.txt"
95 + {"RDSTATE", 23, PARSER_INIT_STREAMING, WORKER_PARSER_FIRST_JOB + 26},
96 +#line 21 "gperf-config.txt"
97 + {"HOST_LABEL", 74, PARSER_INIT_PLUGINSD, WORKER_PARSER_FIRST_JOB + 7},
98 +#line 19 "gperf-config.txt"
99 + {"HOST_DEFINE", 72, PARSER_INIT_PLUGINSD, WORKER_PARSER_FIRST_JOB + 5},
100 +#line 35 "gperf-config.txt"
101 + {"SET", 11, PARSER_INIT_PLUGINSD|PARSER_INIT_STREAMING, WORKER_PARSER_FIRST_JOB + 18},
102 +#line 42 "gperf-config.txt"
103 + {"SET2", 1, PARSER_INIT_STREAMING, WORKER_PARSER_FIRST_JOB + 22},
104 +#line 50 "gperf-config.txt"
105 + {"REND", 25, PARSER_INIT_STREAMING, WORKER_PARSER_FIRST_JOB + 27},
106 +#line 20 "gperf-config.txt"
107 + {"HOST_DEFINE_END", 73, PARSER_INIT_PLUGINSD, WORKER_PARSER_FIRST_JOB + 6},
108 +#line 27 "gperf-config.txt"
109 + {"CLABEL", 34, PARSER_INIT_PLUGINSD|PARSER_INIT_STREAMING, WORKER_PARSER_FIRST_JOB + 10},
110 +#line 48 "gperf-config.txt"
111 + {"RBEGIN", 22, PARSER_INIT_STREAMING, WORKER_PARSER_FIRST_JOB + 25},
112 +#line 15 "gperf-config.txt"
113 + {"FLUSH", 97, PARSER_INIT_PLUGINSD, WORKER_PARSER_FIRST_JOB + 1},
114 #line 31 "gperf-config.txt"
118 - {"CLAIMED_ID", streaming_claimed_id, PARSER_INIT_STREAMING, WORKER_PARSER_FIRST_JOB + 20},
119 -#line 38 "gperf-config.txt"
120 - {"CHART_DEFINITION_END", pluginsd_chart_definition_end, PARSER_INIT_STREAMING, WORKER_PARSER_FIRST_JOB + 24},
115 + {"FUNCTION", 41, PARSER_INIT_PLUGINSD|PARSER_INIT_STREAMING, WORKER_PARSER_FIRST_JOB + 14},
116 +#line 40 "gperf-config.txt"
117 + {"CLAIMED_ID", 61, PARSER_INIT_STREAMING, WORKER_PARSER_FIRST_JOB + 20},
118 +#line 47 "gperf-config.txt"
119 + {"CHART_DEFINITION_END", 33, PARSER_INIT_STREAMING, WORKER_PARSER_FIRST_JOB + 24},
120 +#line 34 "gperf-config.txt"
121 + {"OVERWRITE", 52, PARSER_INIT_PLUGINSD|PARSER_INIT_STREAMING, WORKER_PARSER_FIRST_JOB + 17},
122 +#line 28 "gperf-config.txt"
123 + {"CLABEL_COMMIT", 35, PARSER_INIT_PLUGINSD|PARSER_INIT_STREAMING, WORKER_PARSER_FIRST_JOB + 11},
124 #line 25 "gperf-config.txt"
122 - {"OVERWRITE", pluginsd_overwrite, PARSER_INIT_PLUGINSD|PARSER_INIT_STREAMING, WORKER_PARSER_FIRST_JOB + 17},
123 -#line 19 "gperf-config.txt"
124 - {"CLABEL_COMMIT", pluginsd_clabel_commit, PARSER_INIT_PLUGINSD|PARSER_INIT_STREAMING, WORKER_PARSER_FIRST_JOB + 11},
125 + {"BEGIN", 12, PARSER_INIT_PLUGINSD|PARSER_INIT_STREAMING, WORKER_PARSER_FIRST_JOB + 8},
126 +#line 41 "gperf-config.txt"
127 + {"BEGIN2", 2, PARSER_INIT_STREAMING, WORKER_PARSER_FIRST_JOB + 21},
128 +#line 30 "gperf-config.txt"
129 + {"END", 13, PARSER_INIT_PLUGINSD|PARSER_INIT_STREAMING, WORKER_PARSER_FIRST_JOB + 13},
130 +#line 43 "gperf-config.txt"
131 + {"END2", 3, PARSER_INIT_STREAMING, WORKER_PARSER_FIRST_JOB + 23},
132 #line 16 "gperf-config.txt"
126 - {"BEGIN", pluginsd_begin, PARSER_INIT_PLUGINSD|PARSER_INIT_STREAMING, WORKER_PARSER_FIRST_JOB + 8},
133 + {"DISABLE", 98, PARSER_INIT_PLUGINSD, WORKER_PARSER_FIRST_JOB + 2},
134 +#line 33 "gperf-config.txt"
135 + {"LABEL", 51, PARSER_INIT_PLUGINSD|PARSER_INIT_STREAMING, WORKER_PARSER_FIRST_JOB + 16},
136 +#line 29 "gperf-config.txt"
137 + {"DIMENSION", 31, PARSER_INIT_PLUGINSD|PARSER_INIT_STREAMING, WORKER_PARSER_FIRST_JOB + 12},
138 +#line 17 "gperf-config.txt"
139 + {"EXIT", 99, PARSER_INIT_PLUGINSD, WORKER_PARSER_FIRST_JOB + 3},
140 #line 32 "gperf-config.txt"
128 - {"BEGIN2", pluginsd_begin_v2, PARSER_INIT_STREAMING, WORKER_PARSER_FIRST_JOB + 21},
129 -#line 21 "gperf-config.txt"
130 - {"END", pluginsd_end, PARSER_INIT_PLUGINSD|PARSER_INIT_STREAMING, WORKER_PARSER_FIRST_JOB + 13},
131 -#line 34 "gperf-config.txt"
132 - {"END2", pluginsd_end_v2, PARSER_INIT_STREAMING, WORKER_PARSER_FIRST_JOB + 23},
133 -#line 7 "gperf-config.txt"
134 - {"DISABLE", pluginsd_disable, PARSER_INIT_PLUGINSD, WORKER_PARSER_FIRST_JOB + 2},
135 -#line 24 "gperf-config.txt"
136 - {"LABEL", pluginsd_label, PARSER_INIT_PLUGINSD|PARSER_INIT_STREAMING, WORKER_PARSER_FIRST_JOB + 16},
137 -#line 20 "gperf-config.txt"
138 - {"DIMENSION", pluginsd_dimension, PARSER_INIT_PLUGINSD|PARSER_INIT_STREAMING, WORKER_PARSER_FIRST_JOB + 12},
139 -#line 8 "gperf-config.txt"
140 - {"EXIT", pluginsd_exit, PARSER_INIT_PLUGINSD, WORKER_PARSER_FIRST_JOB + 3},
141 -#line 23 "gperf-config.txt"
142 - {"FUNCTION_RESULT_BEGIN", pluginsd_function_result_begin, PARSER_INIT_PLUGINSD|PARSER_INIT_STREAMING, WORKER_PARSER_FIRST_JOB + 15},
141 + {"FUNCTION_RESULT_BEGIN", 42, PARSER_INIT_PLUGINSD|PARSER_INIT_STREAMING, WORKER_PARSER_FIRST_JOB + 15},
142 {(char*)0}, {(char*)0}, {(char*)0},
144 -#line 27 "gperf-config.txt"
145 - {"VARIABLE", pluginsd_variable, PARSER_INIT_PLUGINSD|PARSER_INIT_STREAMING, WORKER_PARSER_FIRST_JOB + 19}
143 +#line 36 "gperf-config.txt"
144 + {"VARIABLE", 53, PARSER_INIT_PLUGINSD|PARSER_INIT_STREAMING, WORKER_PARSER_FIRST_JOB + 19}
145 };
146
147 PARSER_KEYWORD *
collectors/plugins.d/pluginsd_parser.c
+94
@@ -2026,6 +2026,100 @@ PARSER *parser_init(struct parser_user_object *user, FILE *fp_input, FILE *fp_ou
2026 return parser;
2027 }
2028
2029 +PARSER_RC parser_execute(PARSER *parser, PARSER_KEYWORD *keyword, char **words, size_t num_words) {
2030 + switch(keyword->id) {
2031 + case 1:
2032 + return pluginsd_set_v2(words, num_words, parser);
2033 +
2034 + case 2:
2035 + return pluginsd_begin_v2(words, num_words, parser);
2036 +
2037 + case 3:
2038 + return pluginsd_end_v2(words, num_words, parser);
2039 +
2040 + case 11:
2041 + return pluginsd_set(words, num_words, parser);
2042 +
2043 + case 12:
2044 + return pluginsd_begin(words, num_words, parser);
2045 +
2046 + case 13:
2047 + return pluginsd_end(words, num_words, parser);
2048 +
2049 + case 21:
2050 + return pluginsd_replay_set(words, num_words, parser);
2051 +
2052 + case 22:
2053 + return pluginsd_replay_begin(words, num_words, parser);
2054 +
2055 + case 23:
2056 + return pluginsd_replay_rrddim_collection_state(words, num_words, parser);
2057 +
2058 + case 24:
2059 + return pluginsd_replay_rrdset_collection_state(words, num_words, parser);
2060 +
2061 + case 25:
2062 + return pluginsd_replay_end(words, num_words, parser);
2063 +
2064 + case 31:
2065 + return pluginsd_dimension(words, num_words, parser);
2066 +
2067 + case 32:
2068 + return pluginsd_chart(words, num_words, parser);
2069 +
2070 + case 33:
2071 + return pluginsd_chart_definition_end(words, num_words, parser);
2072 +
2073 + case 34:
2074 + return pluginsd_clabel(words, num_words, parser);
2075 +
2076 + case 35:
2077 + return pluginsd_clabel_commit(words, num_words, parser);
2078 +
2079 + case 41:
2080 + return pluginsd_function(words, num_words, parser);
2081 +
2082 + case 42:
2083 + return pluginsd_function_result_begin(words, num_words, parser);
2084 +
2085 + case 51:
2086 + return pluginsd_label(words, num_words, parser);
2087 +
2088 + case 52:
2089 + return pluginsd_overwrite(words, num_words, parser);
2090 +
2091 + case 53:
2092 + return pluginsd_variable(words, num_words, parser);
2093 +
2094 + case 61:
2095 + return streaming_claimed_id(words, num_words, parser);
2096 +
2097 + case 71:
2098 + return pluginsd_host(words, num_words, parser);
2099 +
2100 + case 72:
2101 + return pluginsd_host_define(words, num_words, parser);
2102 +
2103 + case 73:
2104 + return pluginsd_host_define_end(words, num_words, parser);
2105 +
2106 + case 74:
2107 + return pluginsd_host_labels(words, num_words, parser);
2108 +
2109 + case 97:
2110 + return pluginsd_flush(words, num_words, parser);
2111 +
2112 + case 98:
2113 + return pluginsd_disable(words, num_words, parser);
2114 +
2115 + case 99:
2116 + return pluginsd_exit(words, num_words, parser);
2117 +
2118 + default:
2119 + fatal("Unknown keyword '%s' with id %zu", keyword->keyword, keyword->id);
2120 + }
2121 +}
2122 +
2123 #include "gperf-hashtable.h"
2124
2125 void parser_init_repertoire(PARSER *parser, PARSER_REPERTOIRE repertoire) {
collectors/plugins.d/pluginsd_parser.h
+11 -9
@@ -32,7 +32,7 @@ typedef PARSER_RC (*keyword_function)(char **words, size_t num_words, struct par
32
33 typedef struct parser_keyword {
34 char *keyword;
35 - keyword_function func;
35 + size_t id;
36 PARSER_REPERTOIRE repertoire;
37 size_t worker_job_id;
38 } PARSER_KEYWORD;
@@ -113,6 +113,14 @@ typedef struct parser {
113
114 } PARSER;
115
116 +PARSER *parser_init(struct parser_user_object *user, FILE *fp_input, FILE *fp_output, int fd, PARSER_INPUT_TYPE flags, void *ssl);
117 +void parser_init_repertoire(PARSER *parser, PARSER_REPERTOIRE repertoire);
118 +void parser_destroy(PARSER *working_parser);
119 +void pluginsd_cleanup_v2(PARSER *parser);
120 +void inflight_functions_init(PARSER *parser);
121 +void pluginsd_keywords_init(PARSER *parser, PARSER_REPERTOIRE repertoire);
122 +PARSER_RC parser_execute(PARSER *parser, PARSER_KEYWORD *keyword, char **words, size_t num_words);
123 +
124 static inline int find_first_keyword(const char *src, char *dst, int dst_size, bool *isspace_map) {
125 const char *s = src, *keyword_start;
126
@@ -181,7 +189,8 @@ static inline int parser_action(PARSER *parser, char *input) {
189 PARSER_KEYWORD *t = parser_find_keyword(parser, command);
190 if(likely(t)) {
191 worker_is_busy(t->worker_job_id);
184 - rc = (*t->func)(words, num_words, parser);
192 + rc = parser_execute(parser, t, words, num_words);
193 + // rc = (*t->func)(words, num_words, parser);
194 worker_is_idle();
195 }
196 else
@@ -207,11 +216,4 @@ static inline int parser_action(PARSER *parser, char *input) {
216 return (rc == PARSER_RC_ERROR || rc == PARSER_RC_STOP);
217 }
218
210 -PARSER *parser_init(struct parser_user_object *user, FILE *fp_input, FILE *fp_output, int fd, PARSER_INPUT_TYPE flags, void *ssl);
211 -void parser_init_repertoire(PARSER *parser, PARSER_REPERTOIRE repertoire);
212 -void parser_destroy(PARSER *working_parser);
213 -void pluginsd_cleanup_v2(PARSER *parser);
214 -void inflight_functions_init(PARSER *parser);
215 -void pluginsd_keywords_init(PARSER *parser, PARSER_REPERTOIRE repertoire);
216 -
219 #endif //NETDATA_PLUGINSD_PARSER_H
daemon/common.c
+3
@@ -58,6 +58,9 @@ long get_netdata_cpus(void) {
58
59 processors = cores_user_configured;
60
61 + if(processors < 1)
62 + processors = 1;
63 +
64 return processors;
65 }
66
database/engine/metric.c
+61 -86
@@ -28,27 +28,16 @@ struct metric {
28 static struct aral_statistics mrg_aral_statistics;
29
30 struct mrg {
31 - ARAL *aral[MRG_PARTITIONS];
31 + size_t partitions;
32
33 - struct pgc_index {
34 - MRG_CACHE_LINE_PADDING(0);
33 + struct mrg_partition {
34 + ARAL *aral; // not protected by our spinlock - it has its own
35
36 RW_SPINLOCK rw_spinlock;
37 -
38 - MRG_CACHE_LINE_PADDING(1);
39 -
40 - Pvoid_t uuid_judy; // each UUID has a JudyL of sections (tiers)
41 -
42 - MRG_CACHE_LINE_PADDING(2);
37 + Pvoid_t uuid_judy; // JudyHS: each UUID has a JudyL of sections (tiers)
38
39 struct mrg_statistics stats;
45 -
46 - MRG_CACHE_LINE_PADDING(3);
47 - } index[MRG_PARTITIONS];
48 -
49 -#ifdef NETDATA_INTERNAL_CHECKS
50 - size_t entries_per_partition[MRG_PARTITIONS];
51 -#endif
40 + } index[];
41 };
42
43 static inline void MRG_STATS_DUPLICATE_ADD(MRG *mrg, size_t partition) {
@@ -59,20 +48,12 @@ static inline void MRG_STATS_ADDED_METRIC(MRG *mrg, size_t partition) {
48 mrg->index[partition].stats.entries++;
49 mrg->index[partition].stats.additions++;
50 mrg->index[partition].stats.size += sizeof(METRIC);
62 -
63 -#ifdef NETDATA_INTERNAL_CHECKS
64 - __atomic_add_fetch(&mrg->entries_per_partition[partition], 1, __ATOMIC_RELAXED);
65 -#endif
51 }
52
53 static inline void MRG_STATS_DELETED_METRIC(MRG *mrg, size_t partition) {
54 mrg->index[partition].stats.entries--;
55 mrg->index[partition].stats.size -= sizeof(METRIC);
56 mrg->index[partition].stats.deletions++;
72 -
73 -#ifdef NETDATA_INTERNAL_CHECKS
74 - __atomic_sub_fetch(&mrg->entries_per_partition[partition], 1, __ATOMIC_RELAXED);
75 -#endif
57 }
58
59 static inline void MRG_STATS_SEARCH_HIT(MRG *mrg, size_t partition) {
@@ -87,18 +68,13 @@ static inline void MRG_STATS_DELETE_MISS(MRG *mrg, size_t partition) {
68 mrg->index[partition].stats.delete_misses++;
69 }
70
90 -static inline void mrg_index_read_lock(MRG *mrg, size_t partition) {
91 - rw_spinlock_read_lock(&mrg->index[partition].rw_spinlock);
92 -}
93 -static inline void mrg_index_read_unlock(MRG *mrg, size_t partition) {
94 - rw_spinlock_read_unlock(&mrg->index[partition].rw_spinlock);
95 -}
96 -static inline void mrg_index_write_lock(MRG *mrg, size_t partition) {
97 - rw_spinlock_write_lock(&mrg->index[partition].rw_spinlock);
98 -}
99 -static inline void mrg_index_write_unlock(MRG *mrg, size_t partition) {
100 - rw_spinlock_write_unlock(&mrg->index[partition].rw_spinlock);
101 -}
71 +#define mrg_index_read_lock(mrg, partition) rw_spinlock_read_lock(&(mrg)->index[partition].rw_spinlock)
72 +#define mrg_index_read_unlock(mrg, partition) rw_spinlock_read_unlock(&(mrg)->index[partition].rw_spinlock)
73 +#define mrg_index_write_lock(mrg, partition) rw_spinlock_write_lock(&(mrg)->index[partition].rw_spinlock)
74 +#define mrg_index_write_unlock(mrg, partition) rw_spinlock_write_unlock(&(mrg)->index[partition].rw_spinlock)
75 +
76 +#define metric_lock(metric) spinlock_lock(&(metric)->spinlock)
77 +#define metric_unlock(metric) spinlock_unlock(&(metric)->spinlock)
78
79 static inline void mrg_stats_size_judyl_change(MRG *mrg, size_t mem_before_judyl, size_t mem_after_judyl, size_t partition) {
80 if(mem_after_judyl > mem_before_judyl)
@@ -117,7 +93,8 @@ static inline void mrg_stats_size_judyhs_removed_uuid(MRG *mrg, size_t partition
93
94 static inline size_t uuid_partition(MRG *mrg __maybe_unused, uuid_t *uuid) {
95 uint8_t *u = (uint8_t *)uuid;
120 - return u[UUID_SZ - 1] % MRG_PARTITIONS;
96 + size_t *n = (size_t *)&u[UUID_SZ - sizeof(size_t)];
97 + return *n % mrg->partitions;
98 }
99
100 static inline bool metric_has_retention_unsafe(MRG *mrg __maybe_unused, METRIC *metric) {
@@ -142,7 +119,7 @@ static inline REFCOUNT metric_acquire(MRG *mrg __maybe_unused, METRIC *metric, b
119 REFCOUNT refcount;
120
121 if(!having_spinlock)
145 - spinlock_lock(&metric->spinlock);
122 + metric_lock(metric);
123
124 if(unlikely(metric->refcount < 0))
125 fatal("METRIC: refcount is %d (negative) during acquire", metric->refcount);
@@ -153,7 +130,7 @@ static inline REFCOUNT metric_acquire(MRG *mrg __maybe_unused, METRIC *metric, b
130 metric_has_retention_unsafe(mrg, metric);
131
132 if(!having_spinlock)
156 - spinlock_unlock(&metric->spinlock);
133 + metric_unlock(metric);
134
135 if(refcount == 1)
136 __atomic_add_fetch(&mrg->index[partition].stats.entries_referenced, 1, __ATOMIC_RELAXED);
@@ -168,7 +145,7 @@ static inline bool metric_release_and_can_be_deleted(MRG *mrg __maybe_unused, ME
145 size_t partition = metric->partition;
146 REFCOUNT refcount;
147
171 - spinlock_lock(&metric->spinlock);
148 + metric_lock(metric);
149
150 if(unlikely(metric->refcount <= 0))
151 fatal("METRIC: refcount is %d (zero or negative) during release", metric->refcount);
@@ -178,7 +155,7 @@ static inline bool metric_release_and_can_be_deleted(MRG *mrg __maybe_unused, ME
155 if(likely(metric_has_retention_unsafe(mrg, metric) || refcount != 0))
156 ret = false;
157
181 - spinlock_unlock(&metric->spinlock);
158 + metric_unlock(metric);
159
160 if(unlikely(!refcount))
161 __atomic_sub_fetch(&mrg->index[partition].stats.entries_referenced, 1, __ATOMIC_RELAXED);
@@ -191,7 +168,7 @@ static inline bool metric_release_and_can_be_deleted(MRG *mrg __maybe_unused, ME
168 static inline METRIC *metric_add_and_acquire(MRG *mrg, MRG_ENTRY *entry, bool *ret) {
169 size_t partition = uuid_partition(mrg, &entry->uuid);
170
194 - METRIC *allocation = aral_mallocz(mrg->aral[partition]);
171 + METRIC *allocation = aral_mallocz(mrg->index[partition].aral);
172
173 mrg_index_write_lock(mrg, partition);
174
@@ -224,7 +201,7 @@ static inline METRIC *metric_add_and_acquire(MRG *mrg, MRG_ENTRY *entry, bool *r
201 if(ret)
202 *ret = false;
203
227 - aral_freez(mrg->aral[partition], allocation);
204 + aral_freez(mrg->index[partition].aral, allocation);
205
206 return metric;
207 }
@@ -326,7 +303,7 @@ static inline bool acquired_metric_del(MRG *mrg, METRIC *metric) {
303
304 mrg_index_write_unlock(mrg, partition);
305
329 - aral_freez(mrg->aral[partition], metric);
306 + aral_freez(mrg->index[partition].aral, metric);
307
308 return true;
309 }
@@ -334,22 +311,20 @@ static inline bool acquired_metric_del(MRG *mrg, METRIC *metric) {
311 // ----------------------------------------------------------------------------
312 // public API
313
337 -inline MRG *mrg_create(void) {
338 - MRG *mrg = callocz(1, sizeof(MRG));
314 +inline MRG *mrg_create(size_t partitions) {
315 + if(partitions < 1)
316 + partitions = get_netdata_cpus();
317 +
318 + MRG *mrg = callocz(1, sizeof(MRG) + sizeof(struct mrg_partition) * partitions);
319 + mrg->partitions = partitions;
320
340 - for(size_t i = 0; i < MRG_PARTITIONS ; i++) {
321 + for(size_t i = 0; i < mrg->partitions ; i++) {
322 rw_spinlock_init(&mrg->index[i].rw_spinlock);
323
324 char buf[ARAL_MAX_NAME + 1];
325 snprintfz(buf, ARAL_MAX_NAME, "mrg[%zu]", i);
326
346 - mrg->aral[i] = aral_create(buf,
347 - sizeof(METRIC),
348 - 0,
349 - 16384,
350 - &mrg_aral_statistics,
351 - NULL, NULL, false,
352 - false);
327 + mrg->index[i].aral = aral_create(buf, sizeof(METRIC), 0, 16384, &mrg_aral_statistics, NULL, NULL, false, false);
328 }
329
330 return mrg;
@@ -415,10 +390,10 @@ inline bool mrg_metric_set_first_time_s(MRG *mrg __maybe_unused, METRIC *metric,
390 if(unlikely(first_time_s < 0))
391 return false;
392
418 - spinlock_lock(&metric->spinlock);
393 + metric_lock(metric);
394 metric->first_time_s = first_time_s;
395 metric_has_retention_unsafe(mrg, metric);
421 - spinlock_unlock(&metric->spinlock);
396 + metric_unlock(metric);
397
398 return true;
399 }
@@ -443,7 +418,7 @@ inline void mrg_metric_expand_retention(MRG *mrg __maybe_unused, METRIC *metric,
418 if(unlikely(!first_time_s && !last_time_s && !update_every_s))
419 return;
420
446 - spinlock_lock(&metric->spinlock);
421 + metric_lock(metric);
422
423 if(unlikely(first_time_s && (!metric->first_time_s || first_time_s < metric->first_time_s)))
424 metric->first_time_s = first_time_s;
@@ -458,7 +433,7 @@ inline void mrg_metric_expand_retention(MRG *mrg __maybe_unused, METRIC *metric,
433 metric->latest_update_every_s = (uint32_t) update_every_s;
434
435 metric_has_retention_unsafe(mrg, metric);
461 - spinlock_unlock(&metric->spinlock);
436 + metric_unlock(metric);
437 }
438
439 inline bool mrg_metric_set_first_time_s_if_bigger(MRG *mrg __maybe_unused, METRIC *metric, time_t first_time_s) {
@@ -466,13 +441,13 @@ inline bool mrg_metric_set_first_time_s_if_bigger(MRG *mrg __maybe_unused, METRI
441
442 bool ret = false;
443
469 - spinlock_lock(&metric->spinlock);
444 + metric_lock(metric);
445 if(first_time_s > metric->first_time_s) {
446 metric->first_time_s = first_time_s;
447 ret = true;
448 }
449 metric_has_retention_unsafe(mrg, metric);
475 - spinlock_unlock(&metric->spinlock);
450 + metric_unlock(metric);
451
452 return ret;
453 }
@@ -480,7 +455,7 @@ inline bool mrg_metric_set_first_time_s_if_bigger(MRG *mrg __maybe_unused, METRI
455 inline time_t mrg_metric_get_first_time_s(MRG *mrg __maybe_unused, METRIC *metric) {
456 time_t first_time_s;
457
483 - spinlock_lock(&metric->spinlock);
458 + metric_lock(metric);
459
460 if(unlikely(!metric->first_time_s)) {
461 if(metric->latest_time_s_clean)
@@ -492,13 +467,13 @@ inline time_t mrg_metric_get_first_time_s(MRG *mrg __maybe_unused, METRIC *metri
467
468 first_time_s = metric->first_time_s;
469
495 - spinlock_unlock(&metric->spinlock);
470 + metric_unlock(metric);
471
472 return first_time_s;
473 }
474
475 inline void mrg_metric_get_retention(MRG *mrg __maybe_unused, METRIC *metric, time_t *first_time_s, time_t *last_time_s, time_t *update_every_s) {
501 - spinlock_lock(&metric->spinlock);
476 + metric_lock(metric);
477
478 if(unlikely(!metric->first_time_s)) {
479 if(metric->latest_time_s_clean)
@@ -512,7 +487,7 @@ inline void mrg_metric_get_retention(MRG *mrg __maybe_unused, METRIC *metric, ti
487 *last_time_s = MAX(metric->latest_time_s_clean, metric->latest_time_s_hot);
488 *update_every_s = metric->latest_update_every_s;
489
515 - spinlock_unlock(&metric->spinlock);
490 + metric_unlock(metric);
491 }
492
493 inline bool mrg_metric_set_clean_latest_time_s(MRG *mrg __maybe_unused, METRIC *metric, time_t latest_time_s) {
@@ -521,7 +496,7 @@ inline bool mrg_metric_set_clean_latest_time_s(MRG *mrg __maybe_unused, METRIC *
496 if(unlikely(latest_time_s < 0))
497 return false;
498
524 - spinlock_lock(&metric->spinlock);
499 + metric_lock(metric);
500
501 // internal_fatal(latest_time_s > max_acceptable_collected_time(),
502 // "DBENGINE METRIC: metric latest time is in the future");
@@ -535,7 +510,7 @@ inline bool mrg_metric_set_clean_latest_time_s(MRG *mrg __maybe_unused, METRIC *
510 metric->first_time_s = latest_time_s;
511
512 metric_has_retention_unsafe(mrg, metric);
538 - spinlock_unlock(&metric->spinlock);
513 + metric_unlock(metric);
514 return true;
515 }
516
@@ -573,7 +548,7 @@ inline bool mrg_metric_zero_disk_retention(MRG *mrg __maybe_unused, METRIC *metr
548 if (min_first_time_s == LONG_MAX)
549 min_first_time_s = 0;
550
576 - spinlock_lock(&metric->spinlock);
551 + metric_lock(metric);
552 if (--countdown && !min_first_time_s && metric->latest_time_s_hot)
553 do_again = true;
554 else {
@@ -585,7 +560,7 @@ inline bool mrg_metric_zero_disk_retention(MRG *mrg __maybe_unused, METRIC *metr
560
561 ret = metric_has_retention_unsafe(mrg, metric);
562 }
588 - spinlock_unlock(&metric->spinlock);
563 + metric_unlock(metric);
564 } while(do_again);
565
566 return ret;
@@ -600,22 +575,22 @@ inline bool mrg_metric_set_hot_latest_time_s(MRG *mrg __maybe_unused, METRIC *me
575 if(unlikely(latest_time_s < 0))
576 return false;
577
603 - spinlock_lock(&metric->spinlock);
578 + metric_lock(metric);
579 metric->latest_time_s_hot = latest_time_s;
580
581 if(unlikely(!metric->first_time_s))
582 metric->first_time_s = latest_time_s;
583
584 metric_has_retention_unsafe(mrg, metric);
610 - spinlock_unlock(&metric->spinlock);
585 + metric_unlock(metric);
586 return true;
587 }
588
589 inline time_t mrg_metric_get_latest_time_s(MRG *mrg __maybe_unused, METRIC *metric) {
590 time_t max;
616 - spinlock_lock(&metric->spinlock);
591 + metric_lock(metric);
592 max = MAX(metric->latest_time_s_clean, metric->latest_time_s_hot);
618 - spinlock_unlock(&metric->spinlock);
593 + metric_unlock(metric);
594 return max;
595 }
596
@@ -625,9 +600,9 @@ inline bool mrg_metric_set_update_every(MRG *mrg __maybe_unused, METRIC *metric,
600 if(update_every_s <= 0)
601 return false;
602
628 - spinlock_lock(&metric->spinlock);
603 + metric_lock(metric);
604 metric->latest_update_every_s = (uint32_t) update_every_s;
630 - spinlock_unlock(&metric->spinlock);
605 + metric_unlock(metric);
606
607 return true;
608 }
@@ -638,10 +613,10 @@ inline bool mrg_metric_set_update_every_s_if_zero(MRG *mrg __maybe_unused, METRI
613 if(update_every_s <= 0)
614 return false;
615
641 - spinlock_lock(&metric->spinlock);
616 + metric_lock(metric);
617 if(!metric->latest_update_every_s)
618 metric->latest_update_every_s = (uint32_t) update_every_s;
644 - spinlock_unlock(&metric->spinlock);
619 + metric_unlock(metric);
620
621 return true;
622 }
@@ -649,16 +624,16 @@ inline bool mrg_metric_set_update_every_s_if_zero(MRG *mrg __maybe_unused, METRI
624 inline time_t mrg_metric_get_update_every_s(MRG *mrg __maybe_unused, METRIC *metric) {
625 time_t update_every_s;
626
652 - spinlock_lock(&metric->spinlock);
627 + metric_lock(metric);
628 update_every_s = metric->latest_update_every_s;
654 - spinlock_unlock(&metric->spinlock);
629 + metric_unlock(metric);
630
631 return update_every_s;
632 }
633
634 inline bool mrg_metric_set_writer(MRG *mrg, METRIC *metric) {
635 bool done = false;
661 - spinlock_lock(&metric->spinlock);
636 + metric_lock(metric);
637 if(!metric->writer) {
638 metric->writer = gettid();
639 __atomic_add_fetch(&mrg->index[metric->partition].stats.writers, 1, __ATOMIC_RELAXED);
@@ -666,19 +641,19 @@ inline bool mrg_metric_set_writer(MRG *mrg, METRIC *metric) {
641 }
642 else
643 __atomic_add_fetch(&mrg->index[metric->partition].stats.writers_conflicts, 1, __ATOMIC_RELAXED);
669 - spinlock_unlock(&metric->spinlock);
644 + metric_unlock(metric);
645 return done;
646 }
647
648 inline bool mrg_metric_clear_writer(MRG *mrg, METRIC *metric) {
649 bool done = false;
675 - spinlock_lock(&metric->spinlock);
650 + metric_lock(metric);
651 if(metric->writer) {
652 metric->writer = 0;
653 __atomic_sub_fetch(&mrg->index[metric->partition].stats.writers, 1, __ATOMIC_RELAXED);
654 done = true;
655 }
681 - spinlock_unlock(&metric->spinlock);
656 + metric_unlock(metric);
657 return done;
658 }
659
@@ -734,7 +709,7 @@ inline void mrg_update_metric_retention_and_granularity_by_uuid(
709 inline void mrg_get_statistics(MRG *mrg, struct mrg_statistics *s) {
710 memset(s, 0, sizeof(struct mrg_statistics));
711
737 - for(int i = 0; i < MRG_PARTITIONS ;i++) {
712 + for(size_t i = 0; i < mrg->partitions ;i++) {
713 s->entries += __atomic_load_n(&mrg->index[i].stats.entries, __ATOMIC_RELAXED);
714 s->entries_referenced += __atomic_load_n(&mrg->index[i].stats.entries_referenced, __ATOMIC_RELAXED);
715 s->entries_with_retention += __atomic_load_n(&mrg->index[i].stats.entries_with_retention, __ATOMIC_RELAXED);
@@ -751,7 +726,7 @@ inline void mrg_get_statistics(MRG *mrg, struct mrg_statistics *s) {
726 s->writers_conflicts += __atomic_load_n(&mrg->index[i].stats.writers_conflicts, __ATOMIC_RELAXED);
727 }
728
754 - s->size += sizeof(MRG);
729 + s->size += sizeof(MRG) + sizeof(struct mrg_partition) * mrg->partitions;
730 }
731
732 // ----------------------------------------------------------------------------
@@ -808,7 +783,7 @@ static void *mrg_stress(void *ptr) {
783 }
784
785 int mrg_unittest(void) {
811 - MRG *mrg = mrg_create();
786 + MRG *mrg = mrg_create(0);
787 METRIC *m1_t0, *m2_t0, *m3_t0, *m4_t0;
788 METRIC *m1_t1, *m2_t1, *m3_t1, *m4_t1;
789 bool ret;
@@ -889,7 +864,7 @@ int mrg_unittest(void) {
864 fatal("DBENGINE METRIC: invalid entries counter");
865
866 size_t entries = 1000000;
892 - size_t threads = MRG_PARTITIONS / 3 + 1;
867 + size_t threads = mrg->partitions / 3 + 1;
868 size_t tiers = 3;
869 size_t run_for_secs = 5;
870 info("preparing stress test of %zu entries...", entries);
database/engine/metric.h
+7 -7
@@ -3,8 +3,6 @@
3
4 #include "../rrd.h"
5
6 -#define MRG_PARTITIONS 10
7 -
6 #define MRG_CACHE_LINE_PADDING(x) uint8_t padding##x[64]
7
8 typedef struct metric METRIC;
@@ -19,9 +17,10 @@ typedef struct mrg_entry {
17 } MRG_ENTRY;
18
19 struct mrg_statistics {
22 - // non-atomic - under a write lock
20 + // --- non-atomic --- under a write lock
21 +
22 size_t entries;
24 - size_t size; // total memory used, with indexing
23 + size_t size; // total memory used, with indexing
24
25 size_t additions;
26 size_t additions_duplicate;
@@ -30,9 +29,10 @@ struct mrg_statistics {
29 size_t delete_having_retention_or_referenced;
30 size_t delete_misses;
31
33 - // atomic - multiple readers / writers
34 -
32 MRG_CACHE_LINE_PADDING(0);
33 +
34 + // --- atomic --- multiple readers / writers
35 +
36 size_t entries_referenced;
37
38 MRG_CACHE_LINE_PADDING(1);
@@ -50,7 +50,7 @@ struct mrg_statistics {
50 size_t writers_conflicts;
51 };
52
53 -MRG *mrg_create(void);
53 +MRG *mrg_create(size_t partitions);
54 void mrg_destroy(MRG *mrg);
55
56 METRIC *mrg_metric_dup(MRG *mrg, METRIC *metric);
database/engine/pagecache.c
+1 -1
@@ -1083,7 +1083,7 @@ size_t dynamic_extent_cache_size(void) {
1083
1084 void pgc_and_mrg_initialize(void)
1085 {
1086 - main_mrg = mrg_create();
1086 + main_mrg = mrg_create(0);
1087
1088 size_t target_cache_size = (size_t)default_rrdeng_page_cache_mb * 1024ULL * 1024ULL;
1089 size_t main_cache_size = (target_cache_size / 100) * 95;
database/engine/rrdengineapi.c
+2 -2
@@ -1079,8 +1079,8 @@ static void rrdeng_populate_mrg(struct rrdengine_instance *ctx) {
1079 if(cpus > (size_t)libuv_worker_threads)
1080 cpus = (size_t)libuv_worker_threads;
1081
1082 - if(cpus >= MRG_PARTITIONS / 2)
1083 - cpus = MRG_PARTITIONS / 2 - 1;
1082 + if(cpus >= (size_t)get_netdata_cpus() / 2)
1083 + cpus = get_netdata_cpus()/ 2 - 1;
1084
1085 if(cpus < 1)
1086 cpus = 1;