-
Notifications
You must be signed in to change notification settings - Fork 18
perf(chunkserver): Protect IO performance during massive delete LS #79 #739
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: dev
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -20,12 +20,17 @@ | |||||||||||||
|
|
||||||||||||||
| #include <sys/statvfs.h> | ||||||||||||||
| #include <algorithm> | ||||||||||||||
| #include <atomic> | ||||||||||||||
| #include <cstdint> | ||||||||||||||
| #include <ctime> | ||||||||||||||
| #include <utility> | ||||||||||||||
|
|
||||||||||||||
| #include "chunkserver-common/chunk_trash_manager_impl.h" | ||||||||||||||
| #include "config/cfg.h" | ||||||||||||||
| #include "errors/saunafs_error_codes.h" | ||||||||||||||
| #include "global_shared_resources.h" | ||||||||||||||
| #include "hdd_stats.h" | ||||||||||||||
| #include "hdd_utils.h" | ||||||||||||||
| #include "slogger/slogger.h" | ||||||||||||||
|
|
||||||||||||||
| namespace fs = std::filesystem; | ||||||||||||||
|
|
@@ -36,9 +41,21 @@ size_t ChunkTrashManagerImpl::trashGarbageCollectorBulkSize = kDefaultTrashGarba | |||||||||||||
| size_t ChunkTrashManagerImpl::garbageCollectorSpaceRecoveryStep = | ||||||||||||||
| kDefaultGarbageCollectorSpaceRecoveryStep; | ||||||||||||||
|
|
||||||||||||||
| uint64_t ChunkTrashManagerImpl::maxBytesReadPerDisk = 1024 * 1024; //1MiB | ||||||||||||||
| uint64_t ChunkTrashManagerImpl::maxBytesWritePerDisk = 1024 * 1024; //1MiB | ||||||||||||||
|
|
||||||||||||||
| uint64_t ChunkTrashManagerImpl::previousBytesReadPerDisk = 1024 * 1024; //1MiB | ||||||||||||||
| uint64_t ChunkTrashManagerImpl::previousBytesWritePerDisk = 1024 * 1024; //1MiB | ||||||||||||||
|
|
||||||||||||||
| const std::string ChunkTrashManagerImpl::kTrashGuardString = | ||||||||||||||
| std::string("/") + ChunkTrashManager::kTrashDirname + "/"; | ||||||||||||||
|
|
||||||||||||||
| std::vector<std::thread> ChunkTrashManagerImpl::removeFromTrashThreads{}; | ||||||||||||||
| std::unique_ptr<ProducerConsumerQueue> ChunkTrashManagerImpl::removeFromTrashJobQueue = | ||||||||||||||
| std::make_unique<ProducerConsumerQueue>(); | ||||||||||||||
|
|
||||||||||||||
| std::atomic<uint32_t> ChunkTrashManagerImpl::NotIdleThreadCount{0}; | ||||||||||||||
|
|
||||||||||||||
| void ChunkTrashManagerImpl::reloadConfig() { | ||||||||||||||
| availableThresholdGB = | ||||||||||||||
| cfg_get("CHUNK_TRASH_FREE_SPACE_THRESHOLD_GB", kDefaultAvailableThresholdGB); | ||||||||||||||
|
|
@@ -160,11 +177,49 @@ int ChunkTrashManagerImpl::moveToTrash(const fs::path &filePath, const fs::path | |||||||||||||
| void ChunkTrashManagerImpl::removeTrashFiles( | ||||||||||||||
| const ChunkTrashIndex::TrashIndexDiskEntries &filesToRemove) const { | ||||||||||||||
| for (const auto &[diskPath, fileEntries] : filesToRemove) { | ||||||||||||||
| for (const auto &fileEntry : fileEntries) { | ||||||||||||||
| removeFromTrashJobQueue->put( | ||||||||||||||
| 0, 1, | ||||||||||||||
| reinterpret_cast<uint8_t *>( | ||||||||||||||
| new std::pair<ChunkTrashIndex::TrashIndexFileEntries, std::string>(fileEntries, | ||||||||||||||
| diskPath)), | ||||||||||||||
|
Comment on lines
+182
to
+184
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Using Consider using smart pointers like For example, you could define a struct TrashRemovalJob {
ChunkTrashIndex::TrashIndexFileEntries files;
std::string diskPath;
};Then, you can use References
|
||||||||||||||
| 1); | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| while(NotIdleThreadCount && !removeFromTrashJobQueue->isEmpty()){ | ||||||||||||||
|
|
||||||||||||||
| } | ||||||||||||||
|
Comment on lines
+188
to
+190
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The
Suggested change
|
||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| void ChunkTrashManagerImpl::removeTrashFilesFromDiskThread(uint8_t workerId) { | ||||||||||||||
| std::string threadName ="removeTrashFilesFromDisk_worker_" + std::to_string(workerId); | ||||||||||||||
| pthread_setname_np(pthread_self(), threadName.c_str()); | ||||||||||||||
|
|
||||||||||||||
| uint32_t jobId; | ||||||||||||||
| uint32_t operation; | ||||||||||||||
| uint8_t *jobPtrArg; | ||||||||||||||
|
|
||||||||||||||
| while (true) { | ||||||||||||||
| removeFromTrashJobQueue->get(&jobId, &operation, &jobPtrArg, nullptr); | ||||||||||||||
|
|
||||||||||||||
| if(operation == 0){ | ||||||||||||||
| break; | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| NotIdleThreadCount ++; | ||||||||||||||
| auto tempTuple = reinterpret_cast<std::pair<ChunkTrashIndex::TrashIndexFileEntries, std::string> *>(jobPtrArg); | ||||||||||||||
|
|
||||||||||||||
| ChunkTrashIndex::TrashIndexFileEntries filesToRemove = tempTuple->first; | ||||||||||||||
| std::string diskPath = tempTuple->second; | ||||||||||||||
|
|
||||||||||||||
| for (const auto &fileEntry : filesToRemove) { | ||||||||||||||
| if (removeFileFromTrash(fileEntry.second) != SAUNAFS_STATUS_OK) { continue; } | ||||||||||||||
| HddStats::gStatsOperationsGCPurge++; | ||||||||||||||
| getTrashIndex().remove(fileEntry.first, fileEntry.second, diskPath); | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| delete tempTuple; | ||||||||||||||
|
|
||||||||||||||
| NotIdleThreadCount --; | ||||||||||||||
| } | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
|
|
@@ -210,9 +265,30 @@ int ChunkTrashManagerImpl::init(const std::string &diskPath) { | |||||||||||||
| } | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| if (ChunkTrashManagerImpl::removeFromTrashThreads.size() < 5) { | ||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The number of worker threads for removing trash files is hardcoded to 5. This should be a named constant to improve readability and maintainability. Consider making it configurable or basing it on static constexpr uint8_t kRemoveFromTrashThreadCount = 5;
if (ChunkTrashManagerImpl::removeFromTrashThreads.size() < kRemoveFromTrashThreadCount) { |
||||||||||||||
| ChunkTrashManagerImpl::removeFromTrashThreads.emplace_back( | ||||||||||||||
| &ChunkTrashManagerImpl::removeTrashFilesFromDiskThread, | ||||||||||||||
| uint8_t(ChunkTrashManagerImpl::removeFromTrashThreads.size())); | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| return SAUNAFS_STATUS_OK; | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| void ChunkTrashManagerImpl::terminate() { | ||||||||||||||
| for(uint8_t i=0; i < ChunkTrashManagerImpl::removeFromTrashThreads.size(); i++){ | ||||||||||||||
| ChunkTrashManagerImpl::removeFromTrashJobQueue->put(0, 0, nullptr, 1); | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
|
|
||||||||||||||
| for (auto &thread : ChunkTrashManagerImpl::removeFromTrashThreads) { | ||||||||||||||
| if (thread.joinable()) { thread.join(); } | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| ChunkTrashManagerImpl::removeFromTrashThreads.clear(); | ||||||||||||||
|
|
||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
|
|
||||||||||||||
| bool ChunkTrashManagerImpl::isValidTimestampFormat(const std::string ×tamp) { | ||||||||||||||
| return timestamp.size() == kTimeStampLength && std::ranges::all_of(timestamp, ::isdigit); | ||||||||||||||
| } | ||||||||||||||
|
|
@@ -256,8 +332,51 @@ void ChunkTrashManagerImpl::collectGarbage() { | |||||||||||||
| if (!ChunkTrashManager::isEnabled) { return; } | ||||||||||||||
| std::time_t const currentTime = std::time(nullptr); | ||||||||||||||
| std::time_t const expirationTime = currentTime - trashTimeLimitSeconds; | ||||||||||||||
| removeExpiredFiles(expirationTime, trashGarbageCollectorBulkSize); | ||||||||||||||
|
|
||||||||||||||
| uint64_t currentBytesWrite = HddStats::gBytesWrittenSinceLastGCSweep.exchange(0); | ||||||||||||||
| uint64_t currentBytesRead = HddStats::gBytesReadSinceLastGCSweep.exchange(0); | ||||||||||||||
| uint64_t currentDiskCount = 1; | ||||||||||||||
| { | ||||||||||||||
| std::lock_guard disksLockGuard(gDisksMutex); | ||||||||||||||
| currentDiskCount = std::max(currentDiskCount, gDisks.size()); | ||||||||||||||
| } | ||||||||||||||
| currentBytesRead /= currentDiskCount; | ||||||||||||||
| currentBytesWrite /= currentDiskCount; | ||||||||||||||
|
|
||||||||||||||
| // 0.99997 ^ (30 cycles/min * 60 minutes an hour * 72 hours a day) = 0.02 (2%) | ||||||||||||||
| maxBytesReadPerDisk = | ||||||||||||||
| std::max({uint64_t(maxBytesReadPerDisk * 0.99997), currentBytesRead, uint64_t(1'000'000)}); | ||||||||||||||
| maxBytesWritePerDisk = std::max( | ||||||||||||||
| {uint64_t(maxBytesWritePerDisk * 0.99997), currentBytesWrite, uint64_t(1'000'000)}); | ||||||||||||||
|
|
||||||||||||||
| double totalIOPercentage = | ||||||||||||||
| static_cast<double>(currentBytesRead) * 100.0 / maxBytesReadPerDisk + | ||||||||||||||
| static_cast<double>(currentBytesWrite) * 100.0 / maxBytesWritePerDisk; | ||||||||||||||
|
|
||||||||||||||
| auto invertedSigmoid = [](double val) -> double { | ||||||||||||||
| const double steepness = 10.0; // steepness | ||||||||||||||
| const double center = 0.15; // center in [0,1] | ||||||||||||||
|
Comment on lines
+357
to
+358
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The parameters for the Additionally, these magic numbers should be defined as named constants for better readability and maintainability. const double kSigmoidSteepness = 12.0; // As per PR description
const double kSigmoidCenter = 0.3; // As per PR description |
||||||||||||||
| const double valnorm = val / 100.0; // normalize so that 100% total I/O maps to 1.0 | ||||||||||||||
|
|
||||||||||||||
| const double res = 1.0 / (1.0 + std::exp(-steepness * (valnorm - center))); | ||||||||||||||
| return 1.0 - res; | ||||||||||||||
| }; | ||||||||||||||
|
|
||||||||||||||
| uint64_t bulksizeScaled = trashGarbageCollectorBulkSize * invertedSigmoid(totalIOPercentage); | ||||||||||||||
| if ((currentBytesRead + 1) / (previousBytesReadPerDisk + 1) + | ||||||||||||||
| (currentBytesWrite + 1) / (previousBytesWritePerDisk + 1) >= | ||||||||||||||
| 10) { | ||||||||||||||
| bulksizeScaled = 0; | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| static constexpr uint64_t kMinGCBulkSizeForActivation = 5; | ||||||||||||||
|
|
||||||||||||||
| if (bulksizeScaled >= kMinGCBulkSizeForActivation) { | ||||||||||||||
| removeExpiredFiles(expirationTime, bulksizeScaled); | ||||||||||||||
| } | ||||||||||||||
| makeSpace(availableThresholdGB, garbageCollectorSpaceRecoveryStep); | ||||||||||||||
| previousBytesReadPerDisk = currentBytesRead; | ||||||||||||||
| previousBytesWritePerDisk = currentBytesWrite; | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| bool ChunkTrashManagerImpl::isTrashPath(const std::string &filePath) { | ||||||||||||||
|
|
||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The default value for
CHUNK_TRASH_EXPIRATION_SECONDSappears to be outdated. It is set to "259200" here, but insrc/chunkserver/chunkserver-common/chunk_trash_manager_impl.h, the corresponding defaultkDefaultTrashTimeLimitSecondshas been changed to0. To ensure consistency across the system, this default value should be updated to match.{"CHUNK_TRASH_EXPIRATION_SECONDS", "0"},