-
Notifications
You must be signed in to change notification settings - Fork 334
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
627a326
commit 46991de
Showing
24 changed files
with
1,712 additions
and
37 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
test_generate_dir | ||
priority_workload_cpu_usage.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# Run performance test for different priority & workload type | ||
|
||
``` | ||
cargo test --package common-runtime --lib -- test_metrics::test_all_cpu_usage --nocapture | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import numpy as np | ||
import matplotlib.pyplot as plt | ||
import json | ||
import os | ||
os.chdir(os.path.dirname(__file__)) | ||
|
||
# read json from ../priority_workload_cpu_usage.json | ||
with open('../priority_workload_cpu_usage.json', 'r') as f: | ||
data = json.load(f) | ||
|
||
|
||
# 解构数据 | ||
priorities = [0, 1, 2, 3, 4] | ||
load_types = [0, 1, 2, 3, 4] | ||
values = np.zeros((len(priorities), len(load_types))) | ||
|
||
for key, value in data.items(): | ||
p, l = map(int, key.split(',')) | ||
values[p, l] = value | ||
|
||
# 绘图配置 | ||
bar_width = 0.15 | ||
index = np.arange(len(load_types)) | ||
|
||
# 创建柱状图 | ||
fig, ax = plt.subplots() | ||
bars = [] | ||
colors = ['b', 'g', 'r', 'c', 'm'] | ||
|
||
for i in range(len(priorities)): | ||
bar = ax.bar(index + i * bar_width, values[i], bar_width, label=f'Priority {i}', color=colors[i]) | ||
bars.append(bar) | ||
|
||
# 添加值标签 | ||
def add_labels(rects): | ||
for rect in rects: | ||
height = rect.get_height() | ||
ax.annotate('{}'.format(height), | ||
xy=(rect.get_x() + rect.get_width() / 2, height), | ||
xytext=(0, 3), # 3 points vertical offset | ||
textcoords="offset points", | ||
rotation=90, | ||
ha='center', va='bottom') | ||
|
||
for bar_group in bars: | ||
add_labels(bar_group) | ||
|
||
# 设置图表标题和坐标轴标签 | ||
ax.set_title('CPU Usage by Priority and Load Type') | ||
ax.set_xlabel('Workload Type') | ||
ax.set_ylabel('CPU Usage') | ||
ax.set_xticks(index + bar_width * 2) | ||
ax.set_xticklabels(load_types) | ||
ax.legend() | ||
|
||
# 显示图表 | ||
plt.show() |
1 change: 1 addition & 0 deletions
1
src/common/runtime/scripts/priority_workload_cpu_usage_count.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{"0,0":262.3619,"0,1":256.2622,"0,2":516.4156,"0,3":522.557,"1,0":342.16656,"1,1":389.12814,"1,2":523.02625,"1,3":551.30365,"2,0":437.40067,"2,1":449.49277,"2,2":523.3377,"2,3":560.76587,"3,0":543.88837,"3,1":534.6068,"3,2":522.6544,"3,3":571.3978,"4,0":592.19385,"4,1":595.3774,"4,2":529.2562,"4,3":551.40424} |
22 changes: 22 additions & 0 deletions
22
src/common/runtime/scripts/priority_workload_cpu_usage_time.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
{ | ||
"0,0": 262.3619, | ||
"0,1": 256.2622, | ||
"0,2": 516.4156, | ||
"0,3": 522.557, | ||
"1,0": 342.16656, | ||
"1,1": 389.12814, | ||
"1,2": 523.02625, | ||
"1,3": 551.30365, | ||
"2,0": 437.40067, | ||
"2,1": 449.49277, | ||
"2,2": 523.3377, | ||
"2,3": 560.76587, | ||
"3,0": 543.88837, | ||
"3,1": 534.6068, | ||
"3,2": 522.6544, | ||
"3,3": 571.3978, | ||
"4,0": 592.19385, | ||
"4,1": 595.3774, | ||
"4,2": 529.2562, | ||
"4,3": 551.40424 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
// use core::panicking::panic; | ||
use std::any::TypeId; | ||
use std::collections::{BTreeMap, HashMap, VecDeque}; | ||
use std::future::Future; | ||
use std::pin::Pin; | ||
use std::sync::atomic::{AtomicU32, AtomicU64, Ordering}; | ||
use std::sync::Arc; | ||
use std::task::{Context, Poll, Waker}; | ||
use std::time::{Duration, Instant, SystemTime, UNIX_EPOCH}; | ||
|
||
use futures::FutureExt; | ||
use parking_lot::lock_api::RwLock; | ||
use parking_lot::Mutex; | ||
use prometheus::core::{Atomic, AtomicF64}; | ||
use rand::{thread_rng, Rng}; | ||
use tokio::time::Sleep; | ||
|
||
use crate::ratelimit::Ratelimiter; | ||
use crate::runtime_throttle_count_mode::RuntimeThrottleShareWithFuture; | ||
|
||
struct OneFutureRecord { | ||
total_micro: u64, | ||
cpu_micro: u64, | ||
} | ||
|
||
// static ref EACH_FUTURE_RECORD: parking_lot::RwLock<Option<std::sync::mpsc::Sender<(Priority,Waker)>>> = RwLock::new(None); | ||
|
||
enum State { | ||
Common, | ||
Backoff(Pin<Box<Sleep>>), | ||
} | ||
impl State { | ||
fn unwrap_backoff(&mut self) -> &mut Pin<Box<Sleep>> { | ||
match self { | ||
State::Backoff(sleep) => sleep, | ||
_ => panic!("unwrap_backoff failed"), | ||
} | ||
} | ||
} | ||
|
||
#[pin_project::pin_project] | ||
pub struct ThrottleFuture<F: Future + Send + 'static> { | ||
#[pin] | ||
future: F, | ||
/// priority of this future | ||
handle: Arc<RuntimeThrottleShareWithFuture>, | ||
/// count of pendings | ||
pub pend_cnt: u32, // track the pending count for test | ||
/// count of inserted pendings | ||
// pub inserted_pend_cnt: u32, | ||
// sche_time: u32, | ||
// poll_time: u32, | ||
state: State, | ||
} | ||
|
||
impl<F> ThrottleFuture<F> | ||
where | ||
F: Future + Send + 'static, | ||
F::Output: Send + 'static, | ||
{ | ||
pub fn new(handle: Arc<RuntimeThrottleShareWithFuture>, future: F) -> Self { | ||
Self { | ||
future, | ||
handle, | ||
pend_cnt: 0, | ||
// inserted_pend_cnt: 0, | ||
state: State::Common, | ||
// poll_time: 0, | ||
// sche_time: 0, | ||
} | ||
} | ||
} | ||
|
||
impl<F> Future for ThrottleFuture<F> | ||
where | ||
F: Future + Send + 'static, | ||
F::Output: Send + 'static, | ||
{ | ||
type Output = F::Output; | ||
|
||
fn poll(self: std::pin::Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> { | ||
let this = self.project(); | ||
// let sche_begin = Instant::now(); | ||
match this.state { | ||
State::Common => {} | ||
State::Backoff(ref mut sleep) => match sleep.poll_unpin(cx) { | ||
Poll::Ready(_) => { | ||
*this.state = State::Common; | ||
} | ||
Poll::Pending => return Poll::Pending, | ||
}, | ||
}; | ||
|
||
// let inter = 5; | ||
|
||
// if (*this.pend_cnt + 1) % inter == 0 { | ||
if let Some(ratelimiter) = &this.handle.ratelimiter { | ||
*this.pend_cnt += 1; | ||
// println!("try wait for {}", avg_poll_time); | ||
if let Err(wait) = ratelimiter.try_wait() { | ||
*this.state = State::Backoff(Box::pin(tokio::time::sleep(wait))); | ||
match this.state.unwrap_backoff().poll_unpin(cx) { | ||
Poll::Ready(_) => { | ||
*this.state = State::Common; | ||
cx.waker().clone().wake(); | ||
return Poll::Pending; | ||
} | ||
Poll::Pending => { | ||
return Poll::Pending; | ||
} | ||
} | ||
} | ||
} | ||
|
||
// } | ||
let poll_begin = Instant::now(); | ||
let poll_res = this.future.poll(cx); | ||
let poll_time = poll_begin.elapsed().as_micros() as u64; | ||
|
||
match poll_res { | ||
Poll::Ready(r) => Poll::Ready(r), | ||
Poll::Pending => { | ||
*this.pend_cnt += 1; | ||
Poll::Pending | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.