MCPcopy Create free account
hub / github.com/MariaDB/server / lock_and_check_contention

Method lock_and_check_contention

sql/table_cache.cc:175–219  ·  view source on GitHub ↗

Lock table cache mutex and check contention. Instance is considered contested if more than 20% of mutex acquisitions can't be served immediately. Up to 100 000 probes may be performed to avoid instance activation on short sporadic peaks. 100 000 is estimated maximum number of queries one instance can serve in one second. These numbers work well on a 2 socket / 20 core / 40 th

Source from the content-addressed store, hash-verified

173 are considered out of hot path and are not instrumented either.
174 */
175 void lock_and_check_contention(uint32_t n_instances, uint32_t instance)
176 {
177 if (mysql_mutex_trylock(&LOCK_table_cache))
178 {
179 mysql_mutex_lock(&LOCK_table_cache);
180 if (++mutex_waits == 20000)
181 {
182 if (n_instances < tc_instances)
183 {
184 if (tc_active_instances.
185 compare_exchange_weak(n_instances, n_instances + 1,
186 std::memory_order_relaxed,
187 std::memory_order_relaxed))
188 {
189 sql_print_information("Detected table cache mutex contention at instance %d: "
190 "%d%% waits. Additional table cache instance "
191 "activated. Number of instances after "
192 "activation: %d.",
193 instance + 1,
194 mutex_waits * 100 / (mutex_nowaits + mutex_waits),
195 n_instances + 1);
196 }
197 }
198 else if (!tc_contention_warning_reported.exchange(true,
199 std::memory_order_relaxed))
200 {
201 sql_print_warning("Detected table cache mutex contention at instance %d: "
202 "%d%% waits. Additional table cache instance "
203 "cannot be activated: consider raising "
204 "table_open_cache_instances. Number of active "
205 "instances: %d.",
206 instance + 1,
207 mutex_waits * 100 / (mutex_nowaits + mutex_waits),
208 n_instances);
209 }
210 mutex_waits= 0;
211 mutex_nowaits= 0;
212 }
213 }
214 else if (++mutex_nowaits == 80000)
215 {
216 mutex_waits= 0;
217 mutex_nowaits= 0;
218 }
219 }
220};
221
222

Callers 1

tc_acquire_tableFunction · 0.80

Calls 3

exchangeMethod · 0.80
sql_print_informationFunction · 0.70
sql_print_warningFunction · 0.70

Tested by

no test coverage detected