Skip to content

Commit e7fa037

Browse files
authored
Merge pull request #441 from weibocom/dev_mem
优化内存分配
2 parents 112930c + ac70060 commit e7fa037

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+1659
-1346
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,5 +44,5 @@ codegen-units = 256
4444

4545

4646
[workspace.dependencies]
47-
tokio = { version = "1.32", features = ["rt", "fs", "net", "rt-multi-thread", "time", "sync", "signal"], default-features = false }
47+
tokio = { version = "1.36", features = ["io-util", "rt", "fs", "net", "rt-multi-thread", "time", "sync", "signal"], default-features = false }
4848
serde = { version = "1.0.126", features = ["derive"], default-features = false }

agent/src/main.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use ds::{chan::Receiver, BrzMalloc};
1+
use ds::BrzMalloc;
22
#[global_allocator]
33
static GLOBAL: BrzMalloc = BrzMalloc {};
44

@@ -13,10 +13,7 @@ mod init;
1313
use ds::time::{sleep, Duration};
1414
use rt::spawn;
1515

16-
use protocol::{Parser, Result};
17-
use stream::{Backend, Request};
18-
type Endpoint = Backend<Request>;
19-
type Topology = endpoint::TopologyProtocol<Endpoint, Parser>;
16+
use protocol::Result;
2017

2118
// 默认支持
2219
fn main() -> Result<()> {
@@ -58,7 +55,7 @@ async fn run() -> Result<()> {
5855
}
5956
}
6057

61-
async fn discovery_init(ctx: &Context, rx: Receiver<TopologyWriteGuard<Topology>>) -> Result<()> {
58+
async fn discovery_init(ctx: &Context, rx: service::Receiver) -> Result<()> {
6259
// 将dns resolver的初始化放到外层,提前进行,避免并发场景下顺序错乱 fishermen
6360
let discovery = discovery::Discovery::from_url(&ctx.discovery);
6461
let snapshot = ctx.snapshot_path.to_string();

agent/src/prometheus.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,10 @@ pub(crate) fn register_target(ctx: &context::Context) {
5454
"target": "{local_ip}:{port}"
5555
}}"#
5656
);
57+
let body: &'static str = Box::leak(body.into_boxed_str());
5758
let client = Client::new();
5859
let mut interval = interval(Duration::from_secs(60));
5960
loop {
60-
let body = body.clone();
6161
let req = Request::builder()
6262
.method("PUT")
6363
.uri(&url)

agent/src/service.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ use rt::spawn;
55
use std::sync::Arc;
66

77
use discovery::{TopologyReadGuard, TopologyWriteGuard};
8-
use ds::chan::Sender;
98
use metrics::Path;
109
use protocol::{Parser, Result};
1110
use stream::pipeline::copy_bidirectional;
@@ -16,15 +15,18 @@ type Topology = endpoint::TopologyProtocol<Endpoint, Parser>;
1615
use metrics::Status;
1716
// 一直侦听,直到成功侦听或者取消侦听(当前尚未支持取消侦听)
1817
// 1. 尝试侦听之前,先确保服务配置信息已经更新完成
18+
type Sender = ds::chan::Sender<(String, TopologyWriteGuard<Topology>)>;
19+
pub(super) type Receiver = ds::chan::Receiver<(String, TopologyWriteGuard<Topology>)>;
1920
pub(super) async fn process_one(
2021
quard: &Quadruple,
21-
discovery: Sender<TopologyWriteGuard<Topology>>,
22+
discovery: Sender,
2223
) -> std::result::Result<(), Box<dyn std::error::Error>> {
2324
let p = Parser::try_from(&quard.protocol())?;
2425
let top = endpoint::TopologyProtocol::try_from(p.clone(), quard.endpoint())?;
2526
let (tx, rx) = discovery::topology(top, &quard.service());
2627
// 注册,定期更新配置
27-
discovery.send(tx).await.map_err(|e| e.to_string())?;
28+
let service = quard.service().to_string();
29+
discovery.send((service, tx)).await?;
2830

2931
let path = Path::new(vec![quard.protocol(), &quard.biz()]);
3032
let mut metrics = StreamMetrics::new(&path);

ci.sh

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,11 @@
22
brz_home="/data1/ci/breeze"
33
mkdir -p $brz_home
44

5-
docker ps -a | grep breeze_ci_mysql4623 && docker rm -f breeze_ci_mysql4623
6-
docker ps -a | grep breeze_ci_mysql4624 && docker rm -f breeze_ci_mysql4624
5+
docker stop breeze_ci_mysql4623 breeze_ci_mysql4624 breeze_github_ci 2>/dev/null
6+
77
docker run --rm --name breeze_ci_mysql4623 -p 4623:3306 -d parabala/mysqlci_with_schema:v0.0.2
88
docker run --rm --name breeze_ci_mysql4624 -p 4624:3306 -d parabala/mysqlci_with_schema:v0.0.2
9-
109
container_name=breeze_github_ci
11-
docker ps -a | grep "$container_name" && docker rm -f "$container_name"
12-
13-
1410
docker run --rm -d -v $brz_home:/data1/resource/breeze --net="host" --name "$container_name" parabala/breeze:githubci108
1511

1612
# rm -rf $brz_home/*
@@ -75,3 +71,4 @@ RUST_BACKTRACE=1 cargo test -p tests_integration --features github_workflow
7571

7672
kill -9 $pid
7773

74+
docker stop breeze_ci_mysql4623 breeze_ci_mysql4624 breeze_github_ci

context/src/lib.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,11 @@ pub struct ContextOption {
7373
)]
7474
pub service_path: String,
7575

76+
#[clap(
77+
long,
78+
help("clean path for unix domain socket ."),
79+
default_value("false")
80+
)]
7681
#[clap(short, long, help("starting in upgrade mode"))]
7782
upgrade: bool,
7883

discovery/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ serde_json = "1.0.65"
2828
rand = "0.8.4"
2929
md5 = "0.7"
3030
bs58 = "0.4"
31-
trust-dns-resolver = {version = "0.23.0"}
3231
once_cell = "1.14.0"
3332
noop-waker = "0.1.0"
3433
ctor = "*"
34+
dns-lookup = "*"
35+
libc = "*"

discovery/src/cache.rs

Lines changed: 0 additions & 98 deletions
This file was deleted.

discovery/src/cfg.rs

Lines changed: 0 additions & 139 deletions
This file was deleted.

0 commit comments

Comments
 (0)