Skip to content

Commit 3c42a4c

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

File tree

2 files changed

+23
-5
lines changed

2 files changed

+23
-5
lines changed

src/storage/mod.rs

Lines changed: 16 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,14 +146,17 @@ 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 {
159+
fetch_time.step("fetch from storage");
156160
// Add rustdoc prefix, name and version to the path for accessing the file stored in the database
157161
let remote_path = format!("rustdoc/{}/{}/{}", name, version, path);
158162
self.get(&remote_path, self.max_file_size_for(path))?
@@ -171,6 +175,7 @@ impl Storage {
171175
&source_archive_path(name, version),
172176
path,
173177
self.max_file_size_for(path),
178+
None,
174179
)?
175180
} else {
176181
let remote_path = format!("sources/{}/{}/{}", name, version, path);
@@ -270,10 +275,17 @@ impl Storage {
270275
archive_path: &str,
271276
path: &str,
272277
max_size: usize,
278+
mut fetch_time: Option<&mut RenderingTimesRecorder>,
273279
) -> Result<Blob> {
280+
if let Some(ref mut t) = fetch_time {
281+
t.step("find path in index");
282+
}
274283
let index = self.get_index_for(archive_path)?;
275284
let info = index.find_file(path)?;
276285

286+
if let Some(t) = fetch_time {
287+
t.step("range request");
288+
}
277289
let blob = self.get_range(
278290
archive_path,
279291
max_size,
@@ -790,12 +802,14 @@ mod backend_tests {
790802
assert!(local_index_location.exists());
791803
assert!(storage.exists_in_archive("folder/test.zip", "src/main.rs")?);
792804

793-
let file = storage.get_from_archive("folder/test.zip", "Cargo.toml", std::usize::MAX)?;
805+
let file =
806+
storage.get_from_archive("folder/test.zip", "Cargo.toml", std::usize::MAX, None)?;
794807
assert_eq!(file.content, b"data");
795808
assert_eq!(file.mime, "text/toml");
796809
assert_eq!(file.path, "folder/test.zip/Cargo.toml");
797810

798-
let file = storage.get_from_archive("folder/test.zip", "src/main.rs", std::usize::MAX)?;
811+
let file =
812+
storage.get_from_archive("folder/test.zip", "src/main.rs", std::usize::MAX, None)?;
799813
assert_eq!(file.content, b"data");
800814
assert_eq!(file.mime, "text/rust");
801815
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)