in benchmarks/storage_bench/StorageBench.cc [93:264]
bool runBenchmarks() {
std::vector<std::string> dataPathStrs;
boost::split(dataPathStrs, FLAGS_dataPaths, boost::is_any_of(", "));
std::vector<hf3fs::Path> dataPaths;
dataPaths.reserve(dataPathStrs.size());
for (auto str : dataPathStrs) {
boost::trim(str);
if (str.empty()) continue;
dataPaths.emplace_back(str);
}
std::vector<std::string> endpointRawStrs;
boost::split(endpointRawStrs, FLAGS_storageEndpoints, boost::is_any_of(", "));
std::map<NodeId, net::Address> storageEndpoints;
for (auto str : endpointRawStrs) {
boost::trim(str);
if (str.empty()) continue;
std::vector<std::string> nodeEndpointStrs;
boost::split(nodeEndpointStrs, str, boost::is_any_of("@"));
if (nodeEndpointStrs.size() != 2) {
XLOGF(ERR, "Wrong node endpoint string: {}", str);
return false;
}
auto nodeIdStr = nodeEndpointStrs[0];
auto endpointStr = nodeEndpointStrs[1];
auto nodeId = (NodeId)std::stoul(nodeIdStr);
auto endpoint = net::Address::fromString(endpointStr);
storageEndpoints[nodeId] = endpoint;
XLOGF(WARN, "Add storage endpoint: {} @ {}", nodeId, endpoint);
}
if (FLAGS_clientMode && storageEndpoints.empty()) {
XLOGF(ERR, "No storage endpoint specified for client mode");
return false;
}
if (FLAGS_readSize > FLAGS_chunkSizeKB * 1024) {
XLOGF(ERR, "Read size {} is greater than chunk size {}", FLAGS_readSize, FLAGS_chunkSizeKB * 1024);
return false;
}
auto metaStoreType = static_cast<kv::KVStore::Type>(FLAGS_metaStoreType);
test::SystemSetupConfig setupConfig = {
FLAGS_chunkSizeKB * 1024 /*chunkSize*/,
FLAGS_numChains /*numChains*/,
FLAGS_numReplicas /*numReplicas*/,
FLAGS_numStorageNodes /*numStorageNodes*/,
dataPaths /*dataPaths*/,
FLAGS_clientConfig,
FLAGS_serverConfig,
storageEndpoints,
FLAGS_serviceLevel,
FLAGS_listenPort,
StorageClient::ImplementationType::RPC /*clientImplType*/,
metaStoreType,
true /*useFakeMgmtdClient*/,
!FLAGS_clientMode /*startStorageServer*/,
false,
};
std::vector<std::string> ibvDevices;
boost::split(ibvDevices, FLAGS_ibvDevices, boost::is_any_of(", "));
std::vector<std::string> ibnetZones;
boost::split(ibnetZones, FLAGS_ibnetZones, boost::is_any_of(", "));
endpointRawStrs.clear();
boost::split(endpointRawStrs, FLAGS_mgmtdEndpoints, boost::is_any_of(", "));
std::vector<net::Address> mgmtdEndpoints;
for (auto str : endpointRawStrs) {
boost::trim(str);
if (str.empty()) continue;
auto endpoint = net::Address::fromString(str);
mgmtdEndpoints.push_back(endpoint);
XLOGF(WARN, "Add mgmtd endpoint: {}", endpoint);
}
StorageBench::Options benchOptions{FLAGS_numChunks,
FLAGS_readSize,
FLAGS_writeSize,
FLAGS_batchSize,
FLAGS_numReadSecs,
FLAGS_numWriteSecs,
FLAGS_clientTimeoutMS,
FLAGS_numCoroutines,
FLAGS_numTestThreads,
FLAGS_randSeed,
(uint16_t)FLAGS_chunkIdPrefix,
FLAGS_benchmarkNetwork,
FLAGS_benchmarkStorage,
FLAGS_ignoreIOError,
FLAGS_injectRandomServerError,
FLAGS_injectRandomClientError,
FLAGS_retryPermanentError,
FLAGS_verifyReadData,
FLAGS_verifyReadChecksum,
FLAGS_verifyWriteChecksum,
FLAGS_randomShuffleChunkIds,
FLAGS_generateTestData,
FLAGS_sparseChunkIds,
FLAGS_statsFilePath,
ibvDevices,
ibnetZones,
mgmtdEndpoints,
FLAGS_clusterId,
FLAGS_chainTableId,
FLAGS_chainTableVersion,
stringToIntVec(FLAGS_chainIds),
stringToIntVec(FLAGS_storageNodeIds),
FLAGS_memoryAlignment,
FLAGS_readOffAlignment,
FLAGS_defaultPKeyIndex,
FLAGS_readBatchSize,
FLAGS_writeBatchSize,
FLAGS_removeBatchSize};
StorageBench bench(setupConfig, benchOptions);
if (FLAGS_clusterMode) {
if (!bench.connect()) {
XLOGF(WARN, "Failed to connect to cluster");
return false;
}
} else {
if (!bench.setup()) {
XLOGF(WARN, "Failed to set up benchmark");
return false;
}
}
bench.generateChunkIds();
if (FLAGS_cleanupChunksBeforeBench) {
bench.cleanup();
}
bool runOK = true;
if (FLAGS_serverMode) {
XLOGF(WARN, "Waiting...");
while (true) {
::sleep(1);
}
} else {
runOK = bench.run();
}
if (FLAGS_truncateChunks) {
bench.truncate();
}
if (FLAGS_cleanupChunks) {
bench.cleanup();
}
bench.teardown();
return runOK;
}