Skip to content

Commit

Permalink
Merge pull request #234 from dandi/gh-154
Browse files Browse the repository at this point in the history
Make memory-logging optional (off by default)
  • Loading branch information
jwodder authored Jan 27, 2025
2 parents f96f642 + d2c3103 commit 23e22a6
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 4 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ In Development
- Handling of incoming requests now times out after 25 seconds
- Increased MSRV to 1.81
- Outgoing requests to servers other than S3 now time out after 10 seconds
- Memory usage is now only logged if `--log-memory` was supplied on the command
line

v0.5.0 (2024-11-18)
-------------------
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,10 @@ Options
- `--ip-addr <IPADDR>` — Specify the IP address for the server to listen on
[default: 127.0.0.1]

- `--log-memory` — Log the process's memory usage at the start & end of each
incoming request. Note that this slows down the overall request-processing
time.

- `-p <PORT>`, `--port <PORT>` — Specify the port for the server to listen on
[default: 8080]

Expand Down
18 changes: 14 additions & 4 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,11 @@ struct Config {
#[arg(long, default_value = DEFAULT_API_URL, value_name = "URL")]
api_url: HttpUrl,

/// Log the process's memory usage at the start & end of each incoming
/// request
#[arg(long)]
log_memory: bool,

/// Redirect requests for blob assets directly to S3 instead of to Archive
/// URLs that redirect to signed S3 URLs
#[arg(long)]
Expand All @@ -99,6 +104,7 @@ impl Default for Config {
api_url: DEFAULT_API_URL
.parse::<HttpUrl>()
.expect("DEFAULT_API_URL should be a valid HttpUrl"),
log_memory: false,
prefer_s3_redirects: false,
title: env!("CARGO_PKG_NAME").into(),
zarrman_cache_mb: 100,
Expand Down Expand Up @@ -160,7 +166,7 @@ fn get_app(cfg: Config) -> anyhow::Result<Router> {
templater,
prefer_s3_redirects: cfg.prefer_s3_redirects,
});
Ok(Router::new()
let mut app = Router::new()
.route(
"/.static/styles.css",
get(|| async {
Expand All @@ -179,8 +185,11 @@ fn get_app(cfg: Config) -> anyhow::Result<Router> {
let dav = Arc::clone(&dav);
async move { dav.handle_request(req).await }
}))
.layer(middleware::from_fn(handle_head))
.layer(middleware::from_fn(log_memory))
.layer(middleware::from_fn(handle_head));
if cfg.log_memory {
app = app.layer(middleware::from_fn(log_memory));
}
app = app
.layer(SetResponseHeaderLayer::if_not_present(
SERVER,
HeaderValue::from_static(SERVER_VALUE),
Expand Down Expand Up @@ -218,7 +227,8 @@ fn get_app(cfg: Config) -> anyhow::Result<Router> {
"starting processing request",
);
}),
))
);
Ok(app)
}

/// Handle `HEAD` requests by converting them to `GET` requests and discarding
Expand Down

0 comments on commit 23e22a6

Please sign in to comment.