This commit is contained in:
Jun Kurihara 2022-07-11 22:11:48 +09:00
commit 6f05da8620
No known key found for this signature in database
GPG key ID: 48ADFD173ED22B03
5 changed files with 46 additions and 10 deletions

View file

@ -16,14 +16,14 @@
echo "----------------------------"
echo "Benchmark on rpxy"
#wrk -t8 -c100 -d30s http://127.0.0.1:8080/index.html
rewrk -c 256 -t 8 -d 15s -h http://localhost:8080 --pct
rewrk -c 512 -t 4 -d 10s -h http://localhost:8080 --pct
echo "----------------------------"
echo "Benchmark on nginx"
# wrk -t8 -c100 -d30s http://127.0.0.1:8090/index.html
rewrk -c 256 -t 8 -d 15s -h http://localhost:8090 --pct
rewrk -c 512 -t 4 -d 10s -h http://localhost:8090 --pct
echo "----------------------------"
echo "Benchmark on caddy"
# wrk -t8 -c100 -d30s http://127.0.0.1:8100/index.html
rewrk -c 256 -t 8 -d 15s -h http://localhost:8100 --pct
rewrk -c 512 -t 4 -d 10s -h http://localhost:8100 --pct

View file

@ -26,7 +26,7 @@ services:
context: ../
restart: unless-stopped
environment:
- LOG_LEVEL=debug
- LOG_LEVEL=info
- LOG_TO_FILE=false
ports:
- 127.0.0.1:8080:8080

View file

@ -30,7 +30,7 @@ where
listen_addr: SocketAddr,
tls_enabled: bool,
) -> Result<Response<Body>> {
req.log(&client_addr, Some("(Request from Client)"));
req.log_debug(&client_addr, Some("(Request from Client)"));
// Here we start to handle with server_name
// Find backend application for given server_name, and drop if incoming request is invalid as request.
@ -98,7 +98,7 @@ where
return http_error(StatusCode::BAD_REQUEST);
}
};
res_backend.log(
res_backend.log_debug(
&backend.server_name,
&client_addr,
Some("(Response from Backend)"),

View file

@ -6,9 +6,17 @@ use std::fmt::Display;
// Functions of utils for request messages
pub trait ReqLog {
fn log<T: Display + ToCanonical>(self, src: &T, extra: Option<&str>);
fn log_debug<T: Display + ToCanonical>(self, src: &T, extra: Option<&str>);
fn build_message<T: Display + ToCanonical>(self, src: &T, extra: Option<&str>) -> String;
}
impl<B> ReqLog for &Request<B> {
fn log<T: Display + ToCanonical>(self, src: &T, extra: Option<&str>) {
info!("{}", &self.build_message(src, extra));
}
fn log_debug<T: Display + ToCanonical>(self, src: &T, extra: Option<&str>) {
debug!("{}", &self.build_message(src, extra));
}
fn build_message<T: Display + ToCanonical>(self, src: &T, extra: Option<&str>) -> String {
let canonical_src = src.to_canonical();
let server_name = self.headers().get(header::HOST).map_or_else(
@ -20,7 +28,7 @@ impl<B> ReqLog for &Request<B> {
},
|h| h.to_str().unwrap_or("<none>"),
);
info!(
format!(
"{} <- {} -- {} {:?} {:?} {:?} {}",
server_name,
canonical_src,
@ -32,7 +40,7 @@ impl<B> ReqLog for &Request<B> {
.map_or_else(|| "", |v| v.as_str()),
self.headers(),
extra.map_or_else(|| "", |v| v)
);
)
}
}

View file

@ -11,6 +11,18 @@ pub trait ResLog {
client_addr: &T2,
extra: Option<&str>,
);
fn log_debug<T1: Display, T2: Display + ToCanonical>(
self,
server_name: &T1,
client_addr: &T2,
extra: Option<&str>,
);
fn build_message<T1: Display, T2: Display + ToCanonical>(
self,
server_name: &T1,
client_addr: &T2,
extra: Option<&str>,
) -> String;
}
impl<B> ResLog for &Response<B> {
fn log<T1: Display, T2: Display + ToCanonical>(
@ -19,8 +31,24 @@ impl<B> ResLog for &Response<B> {
client_addr: &T2,
extra: Option<&str>,
) {
info!("{}", &self.build_message(server_name, client_addr, extra));
}
fn log_debug<T1: Display, T2: Display + ToCanonical>(
self,
server_name: &T1,
client_addr: &T2,
extra: Option<&str>,
) {
debug!("{}", &self.build_message(server_name, client_addr, extra));
}
fn build_message<T1: Display, T2: Display + ToCanonical>(
self,
server_name: &T1,
client_addr: &T2,
extra: Option<&str>,
) -> String {
let canonical_client_addr = client_addr.to_canonical();
info!(
format!(
"{} <- {} -- {} {:?} {:?} {}",
canonical_client_addr,
server_name,
@ -28,6 +56,6 @@ impl<B> ResLog for &Response<B> {
self.version(),
self.headers(),
extra.map_or_else(|| "", |v| v)
);
)
}
}