Improve cpu performance for workload generation in server_bench

This commit is contained in:
2024-11-14 17:16:57 -08:00
parent f403c78410
commit bcf459304f

View File

@@ -138,13 +138,17 @@ void tupleAppend(std::string &output, int64_t value) {
void tupleAppend(std::string &output, std::string_view value) { void tupleAppend(std::string &output, std::string_view value) {
output.push_back('\x02'); output.push_back('\x02');
for (auto c : value) { if (memchr(value.data(), '\x00', value.size()) != nullptr) {
if (c == '\x00') { for (auto c : value) {
output.push_back('\x00'); if (c == '\x00') {
output.push_back('\xff'); output.push_back('\x00');
} else { output.push_back('\xff');
output.push_back(c); } else {
output.push_back(c);
}
} }
} else {
output.insert(output.end(), value.begin(), value.end());
} }
output.push_back('\x00'); output.push_back('\x00');
} }
@@ -412,19 +416,18 @@ int main(int argc, char **argv) {
} }
#endif #endif
TxQueue<std::unique_ptr<Transaction>> queue{10}; TxQueue<Transaction> queue{10};
auto workloadThread = std::thread{[&]() { auto workloadThread = std::thread{[&]() {
for (int64_t version = kWindowSize;; for (int64_t version = kWindowSize;;
++version, transactions.fetch_add(1, std::memory_order_relaxed)) { ++version, transactions.fetch_add(1, std::memory_order_relaxed)) {
auto tx = std::make_unique<Transaction>(version); queue.push(Transaction(version));
queue.push(std::move(tx));
} }
}}; }};
auto resolverThread = std::thread{[&]() { auto resolverThread = std::thread{[&]() {
for (;;) { for (;;) {
auto tx = queue.pop()->get(); auto tx = queue.pop();
resolver.resolve(tx->reads.data(), tx->reads.size(), tx->writes.data(), resolver.resolve(tx->reads.data(), tx->reads.size(), tx->writes.data(),
tx->writes.size(), tx->version, tx->oldestVersion); tx->writes.size(), tx->version, tx->oldestVersion);
} }