@@ -444,8 +444,15 @@ int FileCacheManager::Read(uint64_t inodeId, uint64_t offset, uint64_t length,
444444 ReadFromMemCache (offset, length, dataBuf, &actualReadLen,
445445 &memCacheMissRequest);
446446 if (memCacheMissRequest.empty ()) {
447+ if (s3ClientAdaptor_->s3Metric_ ) {
448+ s3ClientAdaptor_->s3Metric_ ->readAllHitsMemCounts << 1 ;
449+ }
447450 return actualReadLen;
448451 }
452+ if (s3ClientAdaptor_->s3Metric_ ) {
453+
454+ s3ClientAdaptor_->s3Metric_ ->readRequestCounts << memCacheMissRequest.size ();
455+ }
449456 VLOG (6 ) << " memcache miss request size: " << memCacheMissRequest.size ();
450457
451458 // 2. read from localcache and remote cluster
@@ -579,22 +586,34 @@ bool FileCacheManager::ReadKVRequestFromS3(const std::string &name,
579586}
580587
581588FileCacheManager::ReadStatus
582- FileCacheManager::ReadKVRequest (const std::vector<S3ReadRequest> &kvRequests,
589+ FileCacheManager::ReadKVRequest (std::vector<S3ReadRequest> &kvRequests,
583590 char *dataBuf, uint64_t fileLen) {
584591 absl::BlockingCounter counter (kvRequests.size ());
585592 std::once_flag cancelFlag;
586593 std::atomic<bool > isCanceled{false };
587594 std::atomic<int > retCode{0 };
588595
589- for (const auto &req : kvRequests) {
596+ for (auto &req : kvRequests) {
597+ req.enqueue = butil::cpuwide_time_us ();
590598 readTaskPool_->Enqueue ([&]() {
591599 auto defer = absl::MakeCleanup ([&]() { counter.DecrementCount (); });
592600 if (isCanceled) {
593601 LOG (WARNING) << " kv request is canceled " << req.DebugString ();
594602 return ;
595603 }
604+ req.dequeue = butil::cpuwide_time_us () - req.enqueue ;
596605 ProcessKVRequest (req, dataBuf, fileLen, cancelFlag, isCanceled,
597606 retCode);
607+ req.processed = butil::cpuwide_time_us () - req.enqueue ;
608+
609+ if (s3ClientAdaptor_->s3Metric_ ) {
610+ curve::client::CollectMetrics (
611+ &s3ClientAdaptor_->s3Metric_ ->adaptorDequeue , req.len , req.dequeue );
612+ curve::client::CollectMetrics (
613+ &s3ClientAdaptor_->s3Metric_ ->adaptorProcess , req.len , req.processed );
614+ s3ClientAdaptor_->s3Metric_ ->s3ReadRequestCounts << 1 ;
615+ }
616+
598617 });
599618 }
600619
@@ -620,7 +639,10 @@ void FileCacheManager::ProcessKVRequest(const S3ReadRequest &req, char *dataBuf,
620639 std::string prefetchName = curvefs::common::s3util::GenObjName (
621640 req.chunkId , blockIndex, req.compaction , req.fsId , req.inodeId ,
622641 objectPrefix);
642+
643+ uint64_t start = butil::cpuwide_time_us ();
623644 bool waitDownloading = false ;
645+
624646 // if obj is in downloading, wait for it.
625647 while (true ) {
626648 {
@@ -642,6 +664,12 @@ void FileCacheManager::ProcessKVRequest(const S3ReadRequest &req, char *dataBuf,
642664 }
643665 }
644666
667+ if (waitDownloading && s3ClientAdaptor_->s3Metric_ ) {
668+ curve::client::CollectMetrics (
669+ &s3ClientAdaptor_->s3Metric_ ->waitDownloading , req.len , butil::cpuwide_time_us () - start);
670+ }
671+
672+
645673 // prefetch
646674 if (s3ClientAdaptor_->HasDiskCache () && !waitDownloading &&
647675 !IsCachedInLocal (prefetchName)) {
@@ -852,15 +880,17 @@ void FileCacheManager::PrefetchS3Objs(
852880 if (fromS3) {
853881 auto context = std::make_shared<GetObjectAsyncContext>(
854882 name, dataCacheS3, 0 , readLen,
855- AsyncPrefetchCallback{inode_, s3ClientAdaptor_, true });
883+ AsyncPrefetchCallback{inode_, s3ClientAdaptor_, true }, ContextType::S3);
884+ context->start = butil::cpuwide_time_us ();
856885 auto task = [this , context]() {
857886 s3ClientAdaptor_->GetS3Client ()->DownloadAsync (context);
858887 };
859888 s3ClientAdaptor_->PushAsyncTask (task);
860889 } else {
861890 auto context = std::make_shared<GetObjectAsyncContext>(
862891 name, dataCacheS3, 0 , readLen,
863- AsyncPrefetchCallback{inode_, s3ClientAdaptor_, false });
892+ AsyncPrefetchCallback{inode_, s3ClientAdaptor_, false }, ContextType::Disk);
893+ context->start = butil::cpuwide_time_us ();
864894 kvClientManager_->Enqueue (context);
865895 }
866896 }
0 commit comments