Skip to content

Commit 423880c

Browse files
authored
ntex: use released deps (#9269)
1 parent 90b1dd3 commit 423880c

File tree

2 files changed

+14
-24
lines changed

2 files changed

+14
-24
lines changed

frameworks/Rust/ntex/Cargo.toml

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,11 @@ default = []
3434
tokio = ["ntex/tokio"]
3535

3636
# compio runtime
37-
compio = ["ntex/compio"]
37+
compio = ["ntex/compio", ]
3838

3939
[dependencies]
4040
ntex = "2.4"
41+
ntex-compio = "0.1.2"
4142
ntex-bytes = { version = "0.1.21", features=["simd"] }
4243
mimalloc = { version = "0.1.25", default-features = false }
4344
snmalloc-rs = { version = "0.3.3", features = ["native-cpu"] }
@@ -52,6 +53,7 @@ futures = "0.3"
5253
serde = { version = "1.0", features = ["derive"] }
5354
serde_json = "1.0"
5455
log = { version = "0.4", features = ["release_max_level_off"] }
56+
compio-driver = { version = "0.4", features = ["io-uring", "io-uring-socket"]}
5557
tok_io = {version = "1", package = "tokio" }
5658
tokio-postgres = { git="https://github.com/fafhrd91/postgres.git", branch="ntex-2" }
5759

@@ -63,10 +65,3 @@ lto = "thin"
6365
debug = false
6466
incremental = false
6567
overflow-checks = false
66-
67-
[patch.crates-io]
68-
ntex = { git = "https://github.com/ntex-rs/ntex.git", branch = "compio" }
69-
ntex-io = { git = "https://github.com/ntex-rs/ntex.git", branch = "compio" }
70-
ntex-rt = { git = "https://github.com/ntex-rs/ntex.git", branch = "compio" }
71-
ntex-net = { git = "https://github.com/ntex-rs/ntex.git", branch = "compio" }
72-
ntex-compio = { git = "https://github.com/ntex-rs/ntex.git", branch = "compio" }

frameworks/Rust/ntex/src/db.rs

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ impl PgConnection {
6868
world,
6969
updates,
7070
rng: WyRand::new(),
71-
buf: RefCell::new(BytesMut::with_capacity(65535)),
71+
buf: RefCell::new(BytesMut::with_capacity(10 * 1024 * 1024)),
7272
}
7373
}
7474
}
@@ -80,7 +80,7 @@ impl PgConnection {
8080
let row = self.cl.query_one(&self.world, &[&random_id]).await.unwrap();
8181

8282
let mut body = self.buf.borrow_mut();
83-
utils::reserve(&mut body, 8 * 1024);
83+
utils::reserve(&mut body, 1024);
8484
World {
8585
id: row.get(0),
8686
randomnumber: row.get(1),
@@ -107,7 +107,7 @@ impl PgConnection {
107107
}
108108

109109
let mut body = self.buf.borrow_mut();
110-
utils::reserve(&mut body, 8 * 1024);
110+
utils::reserve(&mut body, 2 * 1024);
111111
body.put_u8(b'[');
112112
worlds.iter().for_each(|w| {
113113
w.to_bytes_mut(&mut *body);
@@ -119,7 +119,7 @@ impl PgConnection {
119119
}
120120

121121
pub async fn update(&self, num: usize) -> Bytes {
122-
let mut rng = self.rng.clone();
122+
let mut rng = nanorand::tls_rng();
123123
let mut queries = SmallVec::<[_; 32]>::new();
124124
(0..num).for_each(|_| {
125125
let w_id = (rng.generate::<u32>() % 10_000 + 1) as i32;
@@ -146,7 +146,7 @@ impl PgConnection {
146146
let _ = self.cl.query(&self.updates[num - 1], &params).await;
147147

148148
let mut body = self.buf.borrow_mut();
149-
utils::reserve(&mut body, 8 * 1024);
149+
utils::reserve(&mut body, 2 * 1024);
150150
body.put_u8(b'[');
151151
worlds.iter().for_each(|w| {
152152
w.to_bytes_mut(&mut *body);
@@ -158,25 +158,20 @@ impl PgConnection {
158158
}
159159

160160
pub async fn tell_fortune(&self) -> Bytes {
161-
let fut = self.cl.query_raw(&self.fortune, &[]);
161+
let rows = self.cl.query_raw(&self.fortune, &[]).await.unwrap();
162162

163-
let rows = fut.await.unwrap();
164163
let mut fortunes: SmallVec<[_; 32]> = smallvec::smallvec![Fortune {
165164
id: 0,
166165
message: Cow::Borrowed("Additional fortune added at request time."),
167166
}];
168-
169-
for row in rows {
170-
fortunes.push(Fortune {
171-
id: row.get(0),
172-
message: Cow::Owned(row.get(1)),
173-
});
174-
}
175-
167+
fortunes.extend(rows.iter().map(|row| Fortune {
168+
id: row.get(0),
169+
message: Cow::Owned(row.get(1)),
170+
}));
176171
fortunes.sort_by(|it, next| it.message.cmp(&next.message));
177172

178173
let mut body = std::mem::replace(&mut *self.buf.borrow_mut(), BytesMut::new());
179-
utils::reserve(&mut body, 8 * 1024);
174+
utils::reserve(&mut body, 4 * 1024);
180175
ywrite_html!(body, "{{> fortune }}");
181176
let result = body.split().freeze();
182177
let _ = std::mem::replace(&mut *self.buf.borrow_mut(), body);

0 commit comments

Comments
 (0)