使用线程池管理线程,新增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", "server_port": "25565",
"proxy_url": "", "proxy_url": "",
"username_prefix": "test", "username_prefix": "test",
"worker_threads": 100,
"count": 300, "count": 300,
"reco_words": ["验证程序已启用","AntiAttack"], "reco_words": ["验证程序已启用","AntiAttack"],
"login_commands": ["reg helloa helloa"], "login_commands": ["reg helloa helloa"],

View File

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

View File

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