这是indexloc提供的服务,不要输入任何密码
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
851 changes: 817 additions & 34 deletions Cargo.lock

Large diffs are not rendered by default.

12 changes: 7 additions & 5 deletions bayard-rest/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,18 @@ name = "bayard-rest"
path = "src/main.rs"

[dependencies]
actix = "0.9.0"
actix-rt = "1.1.1"
actix-server = "1.0.2"
actix-web = "2.0.0"
clap = "2.33.0"
crossbeam-channel = "0.4.2"
ctrlc = { version = "3.1.4", features = ["termination"] }
iron = "0.6.1"
log = "0.4.8"
logger = "0.4.0"
persistent = "0.4.0"
router = "0.6.0"
num_cpus = "1.13.0"
serde = { version = "1.0.106", features = ["derive"] }
serde_json = "1.0.51"
urlencoded = "0.6.0"
serde_qs = "0.5.2"

bayard-client = { version = "0.8.0", path = "../bayard-client" }
bayard-common = { version = "0.8.0", path = "../bayard-common" }
23 changes: 20 additions & 3 deletions bayard-rest/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,12 @@ use bayard_common::log::set_logger;
use bayard_common::signal::sigterm_channel;
use bayard_rest::rest::server::RestServer;

fn main() -> Result<(), std::io::Error> {
#[actix_rt::main]
async fn main() -> std::io::Result<()> {
set_logger();

let threads = format!("{}", num_cpus::get().to_owned());

let app = App::new(crate_name!())
.setting(AppSettings::DeriveDisplayOrder)
.version(crate_version!())
Expand Down Expand Up @@ -46,17 +49,31 @@ fn main() -> Result<(), std::io::Error> {
.value_name("IP:PORT")
.default_value("0.0.0.0:5000")
.takes_value(true),
)
.arg(
Arg::with_name("HTTP_WORKER_THREADS")
.help("Number of HTTP worker threads. By default http server uses number of available logical cpu as threads count.")
.short("w")
.long("http-worker-threads")
.value_name("HTTP_WORKER_THREADS")
.default_value(&threads)
.takes_value(true),
);

let matches = app.get_matches();

let host = matches.value_of("HOST").unwrap();
let port = matches.value_of("PORT").unwrap().parse::<u16>().unwrap();
let server = matches.value_of("SERVER").unwrap();
let http_worker_threads = matches
.value_of("HTTP_WORKER_THREADS")
.unwrap()
.parse::<usize>()
.unwrap();

let rest_address = format!("{}:{}", host, port);

let mut rest_server = RestServer::new(rest_address.as_str(), server);
let mut rest_server = RestServer::new(rest_address.as_str(), server, http_worker_threads);
info!("start rest service on {}", rest_address.as_str());

// Wait for signals for termination (SIGINT, SIGTERM).
Expand All @@ -70,7 +87,7 @@ fn main() -> Result<(), std::io::Error> {
}
}

match rest_server.shutdown() {
match rest_server.shutdown().await {
Ok(_) => {
info!("stop rest service on {}:{}", host, port);
Ok(())
Expand Down
Loading