Skip to content

Commit 128446b

Browse files
committed
Distinguish between time used to read the index and time used to fetch from s3
1 parent f0f19a6 commit 128446b

File tree

2 files changed

+20
-5
lines changed

2 files changed

+20
-5
lines changed

src/storage/mod.rs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ pub use self::compression::{compress, decompress, CompressionAlgorithm, Compress
77
use self::database::DatabaseBackend;
88
use self::s3::S3Backend;
99
use crate::error::Result;
10+
use crate::web::metrics::RenderingTimesRecorder;
1011
use crate::{db::Pool, Config, Metrics};
1112
use anyhow::{anyhow, ensure};
1213
use chrono::{DateTime, Utc};
@@ -145,12 +146,14 @@ impl Storage {
145146
version: &str,
146147
path: &str,
147148
archive_storage: bool,
149+
fetch_time: &mut RenderingTimesRecorder,
148150
) -> Result<Blob> {
149151
Ok(if archive_storage {
150152
self.get_from_archive(
151153
&rustdoc_archive_path(name, version),
152154
path,
153155
self.max_file_size_for(path),
156+
Some(fetch_time),
154157
)?
155158
} else {
156159
// Add rustdoc prefix, name and version to the path for accessing the file stored in the database
@@ -171,6 +174,7 @@ impl Storage {
171174
&source_archive_path(name, version),
172175
path,
173176
self.max_file_size_for(path),
177+
None,
174178
)?
175179
} else {
176180
let remote_path = format!("sources/{}/{}/{}", name, version, path);
@@ -270,10 +274,17 @@ impl Storage {
270274
archive_path: &str,
271275
path: &str,
272276
max_size: usize,
277+
mut fetch_time: Option<&mut RenderingTimesRecorder>,
273278
) -> Result<Blob> {
279+
if let Some(ref mut t) = fetch_time {
280+
t.step("find path in index");
281+
}
274282
let index = self.get_index_for(archive_path)?;
275283
let info = index.find_file(path)?;
276284

285+
if let Some(t) = fetch_time {
286+
t.step("range request");
287+
}
277288
let blob = self.get_range(
278289
archive_path,
279290
max_size,
@@ -790,12 +801,12 @@ mod backend_tests {
790801
assert!(local_index_location.exists());
791802
assert!(storage.exists_in_archive("folder/test.zip", "src/main.rs")?);
792803

793-
let file = storage.get_from_archive("folder/test.zip", "Cargo.toml", std::usize::MAX)?;
804+
let file = storage.get_from_archive("folder/test.zip", "Cargo.toml", std::usize::MAX, None)?;
794805
assert_eq!(file.content, b"data");
795806
assert_eq!(file.mime, "text/toml");
796807
assert_eq!(file.path, "folder/test.zip/Cargo.toml");
797808

798-
let file = storage.get_from_archive("folder/test.zip", "src/main.rs", std::usize::MAX)?;
809+
let file = storage.get_from_archive("folder/test.zip", "src/main.rs", std::usize::MAX, None)?;
799810
assert_eq!(file.content, b"data");
800811
assert_eq!(file.mime, "text/rust");
801812
assert_eq!(file.path, "folder/test.zip/src/main.rs");

src/web/rustdoc.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -336,8 +336,6 @@ pub fn rustdoc_html_server_handler(req: &mut Request) -> IronResult<Response> {
336336
return redirect(&name, &version, &req_path[1..]);
337337
}
338338

339-
rendering_time.step("fetch from storage");
340-
341339
// Create the path to access the file from
342340
let mut path = req_path.join("/");
343341
if path.ends_with('/') {
@@ -348,7 +346,13 @@ pub fn rustdoc_html_server_handler(req: &mut Request) -> IronResult<Response> {
348346
let mut path = ctry!(req, percent_decode(path.as_bytes()).decode_utf8());
349347

350348
// Attempt to load the file from the database
351-
let blob = match storage.fetch_rustdoc_file(&name, &version, &path, krate.archive_storage) {
349+
let blob = match storage.fetch_rustdoc_file(
350+
&name,
351+
&version,
352+
&path,
353+
krate.archive_storage,
354+
&mut rendering_time,
355+
) {
352356
Ok(file) => file,
353357
Err(err) => {
354358
if !matches!(err.downcast_ref(), Some(Nope::ResourceNotFound))

0 commit comments

Comments
 (0)