bneradt commented on code in PR #13538:
URL: https://github.com/apache/trafficserver/pull/13538#discussion_r3808296741
##########
src/records/unit_tests/test_RecRegister.cc:
##########
@@ -87,3 +92,43 @@ TEST_CASE("RecRegisterStat - Type Dispatch",
"[librecords][RecStat]")
REQUIRE(value == 500);
}
}
+
+TEST_CASE("RecLookupRecord - Concurrent metric registration",
"[librecords][RecLookup]")
+{
+ constexpr char record_name[] = "proxy.test.concurrent.string_value";
+ constexpr char record_value[] = "stable";
+
+ REQUIRE(RecRegisterConfigString(RECT_CONFIG, record_name, record_value,
RECU_DYNAMIC, RECC_NULL, nullptr, REC_SOURCE_NULL) ==
+ REC_ERR_OKAY);
+
+ std::atomic<bool> start{false};
+ std::atomic<bool> finished{false};
+ std::thread register_metrics([&]() {
+ while (!start.load(std::memory_order_acquire)) {
+ std::this_thread::yield();
+ }
+
+ for (int i = 0; i < 100000; ++i) {
+ auto metric_name =
std::string{"proxy.process.test.concurrent_metric_registration."} +
std::to_string(i);
+
+ ts::Metrics::Counter::create(metric_name);
+ }
+ finished.store(true, std::memory_order_release);
+ });
+
+ bool all_lookups_succeeded = true;
+ size_t lookup_count = 0;
+
+ start.store(true, std::memory_order_release);
+ while (!finished.load(std::memory_order_acquire)) {
+ if (RecGetRecordStringAlloc(record_name) != record_value) {
+ all_lookups_succeeded = false;
+ break;
+ }
+ ++lookup_count;
+ }
Review Comment:
Changed to a do/while loop so at least one lookup always occurs, and
switched to unnamed Counter::createSpan(1) allocations to avoid the start spin
and retaining 100,000 metric names.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]