Skip to content

Distinguish between time used to read the index and time used to fetch from s3 #1534

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions src/storage/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ pub use self::compression::{compress, decompress, CompressionAlgorithm, Compress
use self::database::DatabaseBackend;
use self::s3::S3Backend;
use crate::error::Result;
use crate::web::metrics::RenderingTimesRecorder;
use crate::{db::Pool, Config, Metrics};
use anyhow::{anyhow, ensure};
use chrono::{DateTime, Utc};
Expand Down Expand Up @@ -145,14 +146,17 @@ impl Storage {
version: &str,
path: &str,
archive_storage: bool,
fetch_time: &mut RenderingTimesRecorder,
) -> Result<Blob> {
Ok(if archive_storage {
self.get_from_archive(
&rustdoc_archive_path(name, version),
path,
self.max_file_size_for(path),
Some(fetch_time),
)?
} else {
fetch_time.step("fetch from storage");
// Add rustdoc prefix, name and version to the path for accessing the file stored in the database
let remote_path = format!("rustdoc/{}/{}/{}", name, version, path);
self.get(&remote_path, self.max_file_size_for(path))?
Expand All @@ -171,6 +175,7 @@ impl Storage {
&source_archive_path(name, version),
path,
self.max_file_size_for(path),
None,
)?
} else {
let remote_path = format!("sources/{}/{}/{}", name, version, path);
Expand Down Expand Up @@ -270,10 +275,17 @@ impl Storage {
archive_path: &str,
path: &str,
max_size: usize,
mut fetch_time: Option<&mut RenderingTimesRecorder>,
) -> Result<Blob> {
if let Some(ref mut t) = fetch_time {
t.step("find path in index");
}
let index = self.get_index_for(archive_path)?;
let info = index.find_file(path)?;

if let Some(t) = fetch_time {
t.step("range request");
}
let blob = self.get_range(
archive_path,
max_size,
Expand Down Expand Up @@ -790,12 +802,14 @@ mod backend_tests {
assert!(local_index_location.exists());
assert!(storage.exists_in_archive("folder/test.zip", "src/main.rs")?);

let file = storage.get_from_archive("folder/test.zip", "Cargo.toml", std::usize::MAX)?;
let file =
storage.get_from_archive("folder/test.zip", "Cargo.toml", std::usize::MAX, None)?;
assert_eq!(file.content, b"data");
assert_eq!(file.mime, "text/toml");
assert_eq!(file.path, "folder/test.zip/Cargo.toml");

let file = storage.get_from_archive("folder/test.zip", "src/main.rs", std::usize::MAX)?;
let file =
storage.get_from_archive("folder/test.zip", "src/main.rs", std::usize::MAX, None)?;
assert_eq!(file.content, b"data");
assert_eq!(file.mime, "text/rust");
assert_eq!(file.path, "folder/test.zip/src/main.rs");
Expand Down
10 changes: 7 additions & 3 deletions src/web/rustdoc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -336,8 +336,6 @@ pub fn rustdoc_html_server_handler(req: &mut Request) -> IronResult<Response> {
return redirect(&name, &version, &req_path[1..]);
}

rendering_time.step("fetch from storage");

// Create the path to access the file from
let mut path = req_path.join("/");
if path.ends_with('/') {
Expand All @@ -348,7 +346,13 @@ pub fn rustdoc_html_server_handler(req: &mut Request) -> IronResult<Response> {
let mut path = ctry!(req, percent_decode(path.as_bytes()).decode_utf8());

// Attempt to load the file from the database
let blob = match storage.fetch_rustdoc_file(&name, &version, &path, krate.archive_storage) {
let blob = match storage.fetch_rustdoc_file(
&name,
&version,
&path,
krate.archive_storage,
&mut rendering_time,
) {
Ok(file) => file,
Err(err) => {
if !matches!(err.downcast_ref(), Some(Nope::ResourceNotFound))
Expand Down