使用线程池管理线程,新增worker_threads参数

This commit is contained in:
Zihaoxu2008
2025-01-25 19:54:47 +08:00
parent 7021969b27
commit b170844fc4
3 changed files with 23 additions and 19 deletions

View File

@@ -3,6 +3,7 @@
"server_port": "25565",
"proxy_url": "",
"username_prefix": "test",
"worker_threads": 100,
"count": 300,
"reco_words": ["验证程序已启用","AntiAttack"],
"login_commands": ["reg helloa helloa"],

View File

@@ -14,6 +14,7 @@ pub struct Configuration {
spam_file: String,
spam_delay_ms: i32,
random_prefix: bool,
pub worker_threads: i32
}
impl Configuration {
@@ -56,6 +57,7 @@ impl Configuration {
spam_file: "".to_string(),
spam_delay_ms: 0,
random_prefix: false,
worker_threads: 100
}
}

View File

@@ -9,7 +9,7 @@ use reqwest;
use serde_json::Value;
// use tokio::task;
use std::sync::Arc;
use std::thread;
// use std::thread;
use tokio::sync::Mutex;
use crate::utils::generate_username;
use crate::configuration::Configuration;
@@ -43,12 +43,12 @@ async fn main() {
spam_cursor: Arc::new(Mutex::new(0))
});
// let rt = tokio::runtime::Builder::new_multi_thread()
// .enable_all()
// .thread_stack_size(8 * 1024 * 1024)
// .worker_threads((configuration_rc.count()-1) as usize)
// .build()
// .unwrap();
let rt = tokio::runtime::Builder::new_multi_thread()
.enable_all()
.thread_stack_size(8 * 1024 * 1024)
.worker_threads(configuration_rc.worker_threads as usize)
.build()
.unwrap();
for _ in 0..configuration_rc.count() -1 {
let lock_clone = thread_lock.clone();
@@ -59,18 +59,19 @@ async fn main() {
// println!("[MAIN] Thread {} created", i);
// });
// 生成一个线程
// let handle = rt.spawn(attack_thread(lock_clone,configuration_rc_clone,variables_clone));
let handle = thread::spawn(move || {
tokio::runtime::Builder::new_current_thread()
.enable_all()
.thread_stack_size(8 * 1024 * 1024)
.build()
.unwrap()
.block_on(async move {
attack_thread(lock_clone,configuration_rc_clone,variables_clone).await;
// println!("[MAIN] Thread {} created", i);
});
});
// let handle = tokio::task::spawn(attack_thread(lock_clone,configuration_rc_clone,variables_clone));
let handle = rt.spawn(attack_thread(lock_clone,configuration_rc_clone,variables_clone));
// let handle = thread::spawn(move || {
// tokio::runtime::Builder::new_current_thread()
// .enable_all()
// .thread_stack_size(8 * 1024 * 1024)
// .build()
// .unwrap()
// .block_on(async move {
// attack_thread(lock_clone,configuration_rc_clone,variables_clone).await;
// // println!("[MAIN] Thread {} created", i);
// });
//});
handles.push(handle);
// println!("[MAIN] Thread {} created", i) // 这个太吵了(
}