fix, feat: fix high cpu usage, add console-subscriber
This commit is contained in:
parent
f7fb81630d
commit
86910cb29a
3 changed files with 938 additions and 10 deletions
924
Cargo.lock
generated
924
Cargo.lock
generated
File diff suppressed because it is too large
Load diff
|
|
@ -9,3 +9,9 @@ async-trait = "0.1.89"
|
|||
clap = { version = "4.5.48", features = ["derive"] }
|
||||
once_cell = "1.21.3"
|
||||
tokio = { version = "1.47.1", features = ["full"] }
|
||||
console-subscriber = { version = "0.4.1", optional = true }
|
||||
tracing = "0.1.41"
|
||||
tracing-subscriber = "0.3.20"
|
||||
|
||||
[features]
|
||||
tokio-console = ["tokio/tracing", "console-subscriber"]
|
||||
|
|
|
|||
18
src/main.rs
18
src/main.rs
|
|
@ -2,7 +2,6 @@ use std::{
|
|||
collections::HashSet,
|
||||
net::{SocketAddr, TcpListener, TcpStream},
|
||||
str::FromStr,
|
||||
time::Duration,
|
||||
};
|
||||
|
||||
use anyhow::{Result, bail};
|
||||
|
|
@ -15,8 +14,8 @@ use tokio::{
|
|||
Mutex,
|
||||
broadcast::{self, Receiver, Sender},
|
||||
},
|
||||
time::sleep,
|
||||
};
|
||||
use tracing::instrument;
|
||||
|
||||
use crate::{
|
||||
channels::Channel,
|
||||
|
|
@ -40,7 +39,7 @@ pub static JOINED_CHANNELS: Lazy<Mutex<HashSet<Channel>>> =
|
|||
pub static SENDER: Lazy<Mutex<Option<Sender<Message>>>> = Lazy::new(|| Mutex::new(None));
|
||||
|
||||
#[allow(dead_code)]
|
||||
#[derive(Clone)]
|
||||
#[derive(Clone, Debug)]
|
||||
struct ServerInfo {
|
||||
ip: String,
|
||||
port: String,
|
||||
|
|
@ -51,6 +50,9 @@ struct ServerInfo {
|
|||
|
||||
#[tokio::main]
|
||||
async fn main() -> Result<()> {
|
||||
#[cfg(feature = "tokio-console")]
|
||||
console_subscriber::init();
|
||||
|
||||
let info = ServerInfo {
|
||||
ip: "0.0.0.0".into(),
|
||||
port: "6667".into(),
|
||||
|
|
@ -72,16 +74,15 @@ async fn main() -> Result<()> {
|
|||
let tx_thread = tx.clone();
|
||||
let info = info.clone();
|
||||
|
||||
spawn(async move {
|
||||
handle_connection(stream, info, /*&mut rx_thread,*/ tx_thread)
|
||||
.await
|
||||
.unwrap()
|
||||
});
|
||||
spawn(handle_connection(
|
||||
stream, info, /*&mut rx_thread,*/ tx_thread,
|
||||
));
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[instrument]
|
||||
async fn handle_connection(stream: TcpStream, info: ServerInfo, tx: Sender<Message>) -> Result<()> {
|
||||
let stream_tcp = stream.try_clone()?;
|
||||
let mut message_receiver = tx.clone().subscribe();
|
||||
|
|
@ -110,7 +111,6 @@ async fn handle_connection(stream: TcpStream, info: ServerInfo, tx: Sender<Messa
|
|||
}
|
||||
}
|
||||
},
|
||||
_ = sleep(Duration::from_millis(200)) => {},
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue