Mudpie is a simple multi-threaded HTTP server for the amazingly awesome Rust language. It is inspired by Python’s WSGI specification.
Mudpie is written in 100% safe Rust code (no unsafe blocks) and has no dependencies. It is intended to be reliable and easy to audit for security, especially for embedded applications.
Note
|
The Mudpie master branch is for Rust nightly.
|
extern crate mudpie;
use mudpie::{WebServer, WebRequest, WebResponse};
fn hello(req: &WebRequest) -> WebResponse {
let page = "<h1>Hello World!</h1>".to_string();
return WebResponse::new_html(page);
}
fn main() {
let mut svr = WebServer::new();
svr.add_path("get", "/hello", hello);
svr.run("127.0.0.1", 8000);
}
Use cargo run to start the included demo server, which has some example pages you can visit at http://localhost:8000/.
$ cargo run 0.0.0.0 8000 Running `target/demo 0.0.0.0 8000` listening on 0.0.0.0:8000 starting 10 worker threads starting monitor loop
You can benchmark it using a program like "boom" or any other HTTP tester:
$ ./goprograms/bin/boom -n 100000 -c 10 -cpus 3 http://localhost:8000/bench Summary: Total: 3.2466 secs. Slowest: 0.0342 secs. Fastest: 0.0001 secs. Average: 0.0003 secs. Requests/sec: 30801.6515
Note
|
You should probably turn request logging off (export MUDPIE_LOGGING=0 )
or redirect it to /dev/null when benchmarking, and also use cargo run
--release to enable compiler optimizations.
|
-
The Demo Program shows example usage
-
The Internals has gory architecture and protocol details