Skip to content

Commit 23f18d3

Browse files
committed
curvefs/client: metric perf
1 parent 0c24f4f commit 23f18d3

File tree

5 files changed

+75
-13
lines changed

5 files changed

+75
-13
lines changed

curvefs/src/client/metric/client_metric.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,17 +75,18 @@ void AsyncContextCollectMetrics(
7575
std::shared_ptr<S3Metric> s3Metric,
7676
const std::shared_ptr<curve::common::GetObjectAsyncContext>& context) {
7777
if (s3Metric.get() != nullptr) {
78-
CollectMetrics(&s3Metric->adaptorReadS3, context->actualLen,
79-
context->timer.u_elapsed());
78+
79+
CollectMetrics(&s3Metric->adaptorAsyncReadS3, context->actualLen,
80+
butil::cpuwide_time_us() - context->start);
8081

8182
switch (context->type) {
8283
case curve::common::ContextType::Disk:
83-
CollectMetrics(&s3Metric->readFromDiskCache, context->actualLen,
84-
context->timer.u_elapsed());
84+
CollectMetrics(&s3Metric->asyncReadDiskCache, context->actualLen,
85+
butil::cpuwide_time_us() - context->start);
8586
break;
8687
case curve::common::ContextType::S3:
87-
CollectMetrics(&s3Metric->readFromS3, context->actualLen,
88-
context->timer.u_elapsed());
88+
CollectMetrics(&s3Metric->asyncReadFromS3, context->actualLen,
89+
butil::cpuwide_time_us() - context->start);
8990
break;
9091
default:
9192
break;

curvefs/src/client/metric/client_metric.h

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,17 @@ struct S3Metric {
251251
std::string fsName;
252252
InterfaceMetric adaptorWrite;
253253
InterfaceMetric adaptorRead;
254+
255+
InterfaceMetric adaptorDequeue;
256+
InterfaceMetric adaptorProcess;
257+
258+
InterfaceMetric adaptorAsyncReadS3;
259+
InterfaceMetric asyncReadDiskCache;
260+
InterfaceMetric asyncReadFromS3;
261+
262+
InterfaceMetric waitDownloading;
263+
264+
254265
InterfaceMetric adaptorWriteS3;
255266
InterfaceMetric adaptorWriteDiskCache;
256267
InterfaceMetric adaptorReadS3;
@@ -270,11 +281,21 @@ struct S3Metric {
270281
bvar::Status<uint32_t> readSize;
271282
bvar::Status<uint32_t> writeSize;
272283

284+
bvar::Adder<uint64_t> readAllHitsMemCounts;
285+
bvar::Adder<uint64_t> readRequestCounts;
286+
bvar::Adder<uint64_t> s3ReadRequestCounts;
287+
273288
explicit S3Metric(const std::string& name = "")
274289
: fsName(!name.empty() ? name
275290
: prefix + curve::common::ToHexString(this)),
276291
adaptorWrite(prefix, fsName + "_adaptor_write"),
277292
adaptorRead(prefix, fsName + "_adaptor_read"),
293+
adaptorDequeue(prefix, fsName + "_adaptor_dequeue"),
294+
adaptorProcess(prefix, fsName + "_adaptor_process"),
295+
adaptorAsyncReadS3(prefix, fsName + "_adaptor_async_read"),
296+
asyncReadDiskCache(prefix, fsName + "_async_read_from_disk"),
297+
asyncReadFromS3(prefix, fsName + "_async_read_from_s3"),
298+
waitDownloading(prefix, fsName + "_wait_download"),
278299
adaptorWriteS3(prefix, fsName + "_adaptor_write_s3"),
279300
adaptorWriteDiskCache(prefix, fsName + "_adaptor_write_disk_cache"),
280301
adaptorReadS3(prefix, fsName + "_adaptor_read_s3"),
@@ -286,7 +307,11 @@ struct S3Metric {
286307
writeToKVCache(prefix, fsName + "_write_to_kv_cache"),
287308
readFromKVCache(prefix, fsName + "_read_from_kv_cache"),
288309
readSize(prefix, fsName + "_adaptor_read_size", 0),
289-
writeSize(prefix, fsName + "_adaptor_write_size", 0) {}
310+
writeSize(prefix, fsName + "_adaptor_write_size", 0) {
311+
readAllHitsMemCounts.expose_as(prefix, "read_all_hits_mem");
312+
readRequestCounts.expose_as(prefix, "read_request_counts");
313+
s3ReadRequestCounts.expose_as(prefix, "s3_read_request_counts");
314+
}
290315
};
291316

292317
template <typename Tp>

curvefs/src/client/s3/client_s3_cache_manager.cpp

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -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

581588
FileCacheManager::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
}

curvefs/src/client/s3/client_s3_cache_manager.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ using WeakDataCachePtr = std::weak_ptr<DataCache>;
6161
using curve::common::GetObjectAsyncCallBack;
6262
using curve::common::PutObjectAsyncCallBack;
6363
using curve::common::S3Adapter;
64+
using curve::common::ContextType;
6465
using curvefs::metaserver::Inode;
6566
using curvefs::metaserver::S3ChunkInfo;
6667
using curvefs::metaserver::S3ChunkInfoList;
@@ -96,6 +97,9 @@ struct S3ReadRequest {
9697
uint64_t fsId;
9798
uint64_t inodeId;
9899
uint64_t compaction;
100+
uint64_t enqueue;
101+
uint64_t dequeue;
102+
uint64_t processed;
99103

100104
std::string DebugString() const {
101105
std::ostringstream os;
@@ -426,7 +430,7 @@ class FileCacheManager {
426430
}
427431

428432
// read kv request, need
429-
ReadStatus ReadKVRequest(const std::vector<S3ReadRequest> &kvRequests,
433+
ReadStatus ReadKVRequest(std::vector<S3ReadRequest> &kvRequests,
430434
char *dataBuf, uint64_t fileLen);
431435

432436
// thread function for ReadKVRequest

src/common/s3_adapter.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ struct GetObjectAsyncContext : public Aws::Client::AsyncCallerContext {
130130
GetObjectAsyncCallBack cb;
131131
butil::Timer timer;
132132
ContextType type = ContextType::Unkown;
133+
uint64_t start;
133134

134135
explicit GetObjectAsyncContext(
135136
std::string key, char* buf, off_t offset, size_t len,
@@ -143,7 +144,8 @@ struct GetObjectAsyncContext : public Aws::Client::AsyncCallerContext {
143144
len(len),
144145
cb(std::move(cb)),
145146
type(type),
146-
timer(butil::Timer::STARTED) {}
147+
timer(butil::Timer::STARTED),
148+
start(0) {}
147149
};
148150

149151
/*

0 commit comments

Comments
 (0)