-
Notifications
You must be signed in to change notification settings - Fork 752
[TENT] Proxy manager performance optimization #2091
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: main
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 |
|---|---|---|
|
|
@@ -22,9 +22,13 @@ | |
| namespace mooncake { | ||
| namespace tent { | ||
| ProxyManager::ProxyManager(TransferEngineImpl* impl, size_t chunk_size, | ||
| size_t chunk_count) | ||
| : chunk_size_(chunk_size), chunk_count_(chunk_count), impl_(impl) { | ||
| size_t chunk_count, int max_retries) | ||
| : chunk_size_(chunk_size), | ||
| chunk_count_(chunk_count), | ||
| max_retries_(max_retries), | ||
| impl_(impl) { | ||
| running_ = true; | ||
|
|
||
| for (size_t i = 0; i < kShards; ++i) { | ||
| shards_[i].thread = std::thread(&ProxyManager::runner, this, i); | ||
| } | ||
|
|
@@ -241,6 +245,8 @@ Status ProxyManager::transferEventLoop(StagingTask& task, | |
| const static size_t kStageBuffers = 4; | ||
| uint64_t local_stage_buffer[kStageBuffers], | ||
| remote_stage_buffer[kStageBuffers]; | ||
|
|
||
| auto start_time = std::chrono::steady_clock::now(); | ||
| if (local_staging) { | ||
| for (size_t i = 0; i < kStageBuffers; ++i) { | ||
| local_stage_buffer[i] = | ||
|
|
@@ -278,6 +284,7 @@ Status ProxyManager::transferEventLoop(StagingTask& task, | |
| StageState prev_state; | ||
| StageState state; | ||
| BatchID batch; | ||
| int retry_count = 0; | ||
| }; | ||
|
|
||
| std::queue<size_t> event_queue; | ||
|
|
@@ -329,6 +336,8 @@ Status ProxyManager::transferEventLoop(StagingTask& task, | |
| remote_futures[id]); | ||
| chunk.prev_state = chunk.state; | ||
| chunk.state = StageState::INFLIGHT_REMOTE; | ||
| metrics_.remote_staging_count.fetch_add( | ||
| 1, std::memory_order_relaxed); | ||
| } else { | ||
| chunk.state = StageState::CROSS; | ||
| } | ||
|
|
@@ -366,6 +375,8 @@ Status ProxyManager::transferEventLoop(StagingTask& task, | |
| remote_futures[id]); | ||
| chunk.prev_state = chunk.state; | ||
| chunk.state = StageState::INFLIGHT_REMOTE; | ||
| metrics_.remote_staging_count.fetch_add( | ||
| 1, std::memory_order_relaxed); | ||
| } else if (request.opcode == Request::READ && local_staging) { | ||
| chunk.batch = submitLocalStage(request, chunk.local_buf, | ||
| chunk.length, chunk.offset); | ||
|
|
@@ -416,6 +427,13 @@ Status ProxyManager::transferEventLoop(StagingTask& task, | |
| } | ||
|
|
||
| case StageState::FAILED: { | ||
| // Free all in-flight batches before returning | ||
| for (auto& chunk : chunks) { | ||
| if (chunk.batch != 0) { | ||
| impl_->freeBatch(chunk.batch); | ||
| chunk.batch = 0; | ||
| } | ||
| } | ||
| return Status::InternalError( | ||
| "Proxy event loop in failed state"); | ||
| } | ||
|
|
@@ -424,14 +442,35 @@ Status ProxyManager::transferEventLoop(StagingTask& task, | |
| auto& fut = remote_futures[id]; | ||
| if (!fut.valid()) { | ||
| chunk.state = StageState::FAILED; | ||
| event_queue.push(id); | ||
|
Contributor
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. This call triggers the |
||
| break; | ||
| } | ||
| if (fut.wait_for(std::chrono::seconds(0)) == | ||
| std::future_status::ready) { | ||
| Status rs = fut.get(); | ||
| if (!rs.ok()) { | ||
| chunk.state = StageState::FAILED; | ||
| break; | ||
| if (chunk.retry_count < max_retries_) { | ||
| chunk.retry_count++; | ||
| metrics_.retry_count.fetch_add( | ||
| 1, std::memory_order_relaxed); | ||
| LOG(WARNING) | ||
| << "Remote staging failed for chunk " << id | ||
| << ", retrying (attempt " << chunk.retry_count | ||
| << "/" << max_retries_ | ||
| << "): " << rs.ToString(); | ||
| submitRemoteStage(server_addr, request, | ||
| chunk.remote_buf, chunk.length, | ||
| chunk.offset, remote_futures[id]); | ||
| event_queue.push(id); | ||
| break; | ||
| } else { | ||
| LOG(ERROR) << "Remote staging failed for chunk " | ||
| << id << " after " << max_retries_ | ||
| << " retries: " << rs.ToString(); | ||
| chunk.state = StageState::FAILED; | ||
| event_queue.push(id); | ||
| break; | ||
| } | ||
| } | ||
| if (chunk.prev_state == StageState::PRE) { | ||
| chunk.state = StageState::CROSS; | ||
|
|
@@ -451,6 +490,20 @@ Status ProxyManager::transferEventLoop(StagingTask& task, | |
| } | ||
| } | ||
|
|
||
| auto end_time = std::chrono::steady_clock::now(); | ||
| auto latency_us = std::chrono::duration_cast<std::chrono::microseconds>( | ||
| end_time - start_time) | ||
| .count(); | ||
|
|
||
| // Update metrics only after successful completion | ||
| metrics_.total_transfers.fetch_add(1, std::memory_order_relaxed); | ||
| metrics_.total_bytes_transferred.fetch_add(request.length, | ||
| std::memory_order_relaxed); | ||
| metrics_.total_latency_us.fetch_add(latency_us, std::memory_order_relaxed); | ||
| metrics_.pipeline_parallel_chunks.fetch_add(chunks.size(), | ||
| std::memory_order_relaxed); | ||
| metrics_.markEndTime(); | ||
|
|
||
| return Status::OK(); | ||
| } | ||
|
|
||
|
|
||
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 throughput calculation
(total_bytes_transferred.load() / 1e9) / (us / 1e6)is based on the sum of latencies of all transfers. In a parallel execution environment with multiple shards, this sum grows faster than wall-clock time, meaning the metric represents the average throughput per stream rather than the aggregate system throughput. To measure system-wide throughput, you should track the wall-clock time since the metrics were last reset.