Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
change
sglang
Commits
0b46b951
Unverified
Commit
0b46b951
authored
Nov 26, 2024
by
Byron Hsu
Committed by
GitHub
Nov 26, 2024
Browse files
Fix rust warning (#2208)
parent
2763c0a7
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
15 additions
and
14 deletions
+15
-14
rust/src/router.rs
rust/src/router.rs
+2
-4
rust/src/server.rs
rust/src/server.rs
+1
-1
rust/src/tree.rs
rust/src/tree.rs
+12
-9
No files found.
rust/src/router.rs
View file @
0b46b951
...
@@ -2,12 +2,10 @@ use crate::tree::Tree;
...
@@ -2,12 +2,10 @@ use crate::tree::Tree;
use
actix_web
::
http
::
header
::{
HeaderValue
,
CONTENT_TYPE
};
use
actix_web
::
http
::
header
::{
HeaderValue
,
CONTENT_TYPE
};
use
actix_web
::{
HttpRequest
,
HttpResponse
};
use
actix_web
::{
HttpRequest
,
HttpResponse
};
use
bytes
::
Bytes
;
use
bytes
::
Bytes
;
use
futures_util
::{
Stream
,
StreamExt
,
TryStreamExt
};
use
futures_util
::{
StreamExt
,
TryStreamExt
};
use
log
::{
debug
,
info
};
use
log
::{
debug
,
info
};
use
std
::
collections
::
HashMap
;
use
std
::
collections
::
HashMap
;
use
std
::
fmt
::
Debug
;
use
std
::
fmt
::
Debug
;
use
std
::
hash
::
Hash
;
use
std
::
pin
::
Pin
;
use
std
::
sync
::
atomic
::
AtomicUsize
;
use
std
::
sync
::
atomic
::
AtomicUsize
;
use
std
::
sync
::{
Arc
,
Mutex
};
use
std
::
sync
::{
Arc
,
Mutex
};
use
std
::
thread
;
use
std
::
thread
;
...
@@ -252,7 +250,7 @@ impl Router {
...
@@ -252,7 +250,7 @@ impl Router {
}
=>
{
}
=>
{
// TODO: delay scheduling if cache hit rate is high because it may cause imbalance. prioritize low hit rate ones
// TODO: delay scheduling if cache hit rate is high because it may cause imbalance. prioritize low hit rate ones
let
mut
tree
=
tree
.lock
()
.unwrap
();
let
tree
=
tree
.lock
()
.unwrap
();
let
mut
running_queue
=
running_queue
.lock
()
.unwrap
();
let
mut
running_queue
=
running_queue
.lock
()
.unwrap
();
// Get current load statistics
// Get current load statistics
...
...
rust/src/server.rs
View file @
0b46b951
...
@@ -3,7 +3,7 @@ use crate::router::Router;
...
@@ -3,7 +3,7 @@ use crate::router::Router;
use
actix_web
::{
get
,
post
,
web
,
App
,
HttpRequest
,
HttpResponse
,
HttpServer
,
Responder
};
use
actix_web
::{
get
,
post
,
web
,
App
,
HttpRequest
,
HttpResponse
,
HttpServer
,
Responder
};
use
bytes
::
Bytes
;
use
bytes
::
Bytes
;
use
env_logger
::
Builder
;
use
env_logger
::
Builder
;
use
log
::{
debug
,
info
,
LevelFilter
};
use
log
::{
info
,
LevelFilter
};
use
std
::
io
::
Write
;
use
std
::
io
::
Write
;
#[derive(Debug)]
#[derive(Debug)]
...
...
rust/src/tree.rs
View file @
0b46b951
use
dashmap
::
mapref
::
entry
::
Entry
;
use
dashmap
::
mapref
::
entry
::
Entry
;
use
dashmap
::
DashMap
;
use
dashmap
::
DashMap
;
use
log
::
info
;
use
log
::
info
;
use
rand
::
distributions
::{
Alphanumeric
,
DistString
};
use
rand
::
thread_rng
;
use
std
::
cmp
::
min
;
use
std
::
cmp
::
Reverse
;
use
std
::
cmp
::
Reverse
;
use
std
::
collections
::
BinaryHeap
;
use
std
::
collections
::
BinaryHeap
;
use
std
::
collections
::
HashMap
;
use
std
::
collections
::
HashMap
;
use
std
::
sync
::
Arc
;
use
std
::
sync
::
Arc
;
use
std
::
sync
::
RwLock
;
use
std
::
sync
::
RwLock
;
use
std
::
thread
;
use
std
::
time
::
Duration
;
use
std
::
time
::
Duration
;
use
std
::
time
::{
SystemTime
,
UNIX_EPOCH
};
use
std
::
time
::{
SystemTime
,
UNIX_EPOCH
};
...
@@ -248,6 +246,7 @@ impl Tree {
...
@@ -248,6 +246,7 @@ impl Tree {
}
}
}
}
#[allow(unused_assignments)]
pub
fn
prefix_match
(
&
self
,
text
:
&
str
)
->
(
String
,
String
)
{
pub
fn
prefix_match
(
&
self
,
text
:
&
str
)
->
(
String
,
String
)
{
let
mut
curr
=
Arc
::
clone
(
&
self
.root
);
let
mut
curr
=
Arc
::
clone
(
&
self
.root
);
let
mut
curr_idx
=
0
;
let
mut
curr_idx
=
0
;
...
@@ -317,6 +316,7 @@ impl Tree {
...
@@ -317,6 +316,7 @@ impl Tree {
(
ret_text
,
tenant
)
(
ret_text
,
tenant
)
}
}
#[allow(unused_assignments)]
pub
fn
prefix_match_tenant
(
&
self
,
text
:
&
str
,
tenant
:
&
str
)
->
String
{
pub
fn
prefix_match_tenant
(
&
self
,
text
:
&
str
,
tenant
:
&
str
)
->
String
{
let
mut
curr
=
Arc
::
clone
(
&
self
.root
);
let
mut
curr
=
Arc
::
clone
(
&
self
.root
);
let
mut
curr_idx
=
0
;
let
mut
curr_idx
=
0
;
...
@@ -632,9 +632,12 @@ impl Tree {
...
@@ -632,9 +632,12 @@ impl Tree {
// Unit tests
// Unit tests
#[cfg(test)]
#[cfg(test)]
mod
tests
{
mod
tests
{
use
std
::
time
::
Instant
;
use
rand
::
distributions
::
Alphanumeric
;
use
rand
::
distributions
::
DistString
;
use
rand
::
thread_rng
;
use
rand
::
Rng
;
use
rand
::
Rng
;
use
std
::
thread
;
use
std
::
time
::
Instant
;
use
super
::
*
;
use
super
::
*
;
...
@@ -1026,7 +1029,7 @@ mod tests {
...
@@ -1026,7 +1029,7 @@ mod tests {
let
text
=
prefix
[
i
];
let
text
=
prefix
[
i
];
let
handle
=
thread
::
spawn
(
move
||
{
let
handle
=
thread
::
spawn
(
move
||
{
let
(
matched_text
,
matched_tenant
)
=
tree_clone
.prefix_match
(
text
);
let
(
_
matched_text
,
_
matched_tenant
)
=
tree_clone
.prefix_match
(
text
);
});
});
handles
.push
(
handle
);
handles
.push
(
handle
);
...
@@ -1169,7 +1172,7 @@ mod tests {
...
@@ -1169,7 +1172,7 @@ mod tests {
let
prefixes
=
vec!
[
"aqwefcisdf"
,
"iajsdfkmade"
,
"kjnzxcvewqe"
,
"iejksduqasd"
];
let
prefixes
=
vec!
[
"aqwefcisdf"
,
"iajsdfkmade"
,
"kjnzxcvewqe"
,
"iejksduqasd"
];
// Insert strings with shared prefixes
// Insert strings with shared prefixes
for
i
in
0
..
100
{
for
_
i
in
0
..
100
{
for
(
j
,
prefix
)
in
prefixes
.iter
()
.enumerate
()
{
for
(
j
,
prefix
)
in
prefixes
.iter
()
.enumerate
()
{
let
random_suffix
=
random_string
(
10
);
let
random_suffix
=
random_string
(
10
);
let
text
=
format!
(
"{}{}"
,
prefix
,
random_suffix
);
let
text
=
format!
(
"{}{}"
,
prefix
,
random_suffix
);
...
@@ -1234,7 +1237,7 @@ mod tests {
...
@@ -1234,7 +1237,7 @@ mod tests {
// Perform match operation
// Perform match operation
let
random_len
=
rng
.gen_range
(
3
..
10
);
let
random_len
=
rng
.gen_range
(
3
..
10
);
let
search_str
=
format!
(
"{}{}"
,
prefix
,
random_string
(
random_len
));
let
search_str
=
format!
(
"{}{}"
,
prefix
,
random_string
(
random_len
));
let
(
matched
,
_
)
=
tree
.prefix_match
(
&
search_str
);
let
(
_
matched
,
_
)
=
tree
.prefix_match
(
&
search_str
);
}
else
{
}
else
{
// Perform insert operation
// Perform insert operation
let
random_len
=
rng
.gen_range
(
5
..
15
);
let
random_len
=
rng
.gen_range
(
5
..
15
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment