Skip to content

Commit 4998f79

Browse files
Merge pull request #1367 from rylev/ondemand-self-profile
Fetch self profile data from S3 rather than RDS database. This is intended to be more efficient in the long run, since we can stop storing data into RDS eventually.
2 parents 3c25313 + d667e59 commit 4998f79

File tree

9 files changed

+193
-642
lines changed

9 files changed

+193
-642
lines changed

Diff for: Cargo.lock

+20-13
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: database/src/lib.rs

+10-52
Original file line numberDiff line numberDiff line change
@@ -448,16 +448,6 @@ pub struct QueryDatum {
448448
pub invocation_count: u32,
449449
}
450450

451-
#[async_trait::async_trait]
452-
impl SeriesType for QueryDatum {
453-
async fn get(
454-
conn: &dyn pool::Connection,
455-
series: u32,
456-
artifact_row_id: ArtifactIdNumber,
457-
) -> Option<Self> {
458-
conn.get_self_profile_query(series, artifact_row_id).await
459-
}
460-
}
461451
#[derive(Hash, Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord)]
462452
pub struct LabelId(pub u8, pub u32);
463453

@@ -481,8 +471,6 @@ pub struct Index {
481471
/// Id lookup of stat description ids
482472
/// For legacy reasons called `pstat_series` in the database, and so the name is kept here.
483473
pstat_series: Indexed<(Benchmark, Profile, Scenario, Metric)>,
484-
/// Id lookup of a given process query label
485-
queries: Indexed<(Benchmark, Profile, Scenario, QueryLabel)>,
486474
}
487475

488476
/// An index lookup
@@ -605,12 +593,6 @@ pub enum DbLabel {
605593
scenario: Scenario,
606594
metric: Metric,
607595
},
608-
SelfProfileQuery {
609-
benchmark: Benchmark,
610-
profile: Profile,
611-
scenario: Scenario,
612-
query: QueryLabel,
613-
},
614596
}
615597

616598
pub trait Lookup {
@@ -631,14 +613,6 @@ impl Lookup for DbLabel {
631613
} => index
632614
.pstat_series
633615
.get(&(*benchmark, *profile, *scenario, *metric)),
634-
DbLabel::SelfProfileQuery {
635-
benchmark,
636-
profile,
637-
scenario,
638-
query,
639-
} => index
640-
.queries
641-
.get(&(*benchmark, *profile, *scenario, *query)),
642616
}
643617
}
644618
}
@@ -717,32 +691,16 @@ impl Index {
717691
self.pstat_series.map.keys()
718692
}
719693

720-
// FIXME: in theory this won't scale indefinitely as there's potentially
721-
// millions of queries and labels and iterating all of them is eventually
722-
// going to be impractical. But for now it performs quite well, so we'll go
723-
// for it as keeping indices around would be annoying.
724-
pub fn all_query_series(
725-
&self,
726-
) -> impl Iterator<Item = &'_ (Benchmark, Profile, Scenario, QueryLabel)> + '_ {
727-
self.queries.map.keys()
728-
}
729-
730-
// FIXME: in theory this won't scale indefinitely as there's potentially
731-
// millions of queries and labels and iterating all of them is eventually
732-
// going to be impractical. But for now it performs quite well, so we'll go
733-
// for it as keeping indices around would be annoying.
734-
pub fn filtered_queries(
735-
&self,
736-
benchmark: Benchmark,
737-
profile: Profile,
738-
scenario: Scenario,
739-
) -> impl Iterator<Item = QueryLabel> + '_ {
740-
self.queries
741-
.map
742-
.keys()
743-
.filter(move |&&(b, p, s, _)| b == benchmark && p == profile && s == scenario)
744-
.map(|&(_, _, _, q)| q)
745-
.filter(|q| !q.as_str().starts_with("codegen passes ["))
694+
pub fn artifact_id_for_commit(&self, commit: &str) -> Option<ArtifactId> {
695+
self.commits()
696+
.into_iter()
697+
.find(|c| c.sha == *commit)
698+
.map(|c| ArtifactId::Commit(c))
699+
.or_else(|| {
700+
self.artifacts()
701+
.find(|a| *a == commit)
702+
.map(|a| ArtifactId::Tag(a.to_owned()))
703+
})
746704
}
747705
}
748706

Diff for: database/src/pool.rs

+2-14
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::{ArtifactId, ArtifactIdNumber, BenchmarkData};
2-
use crate::{CollectionId, Index, Profile, QueryDatum, QueuedCommit, Scenario, Step};
2+
use crate::{CollectionId, Index, Profile, QueuedCommit, Scenario, Step};
33
use chrono::{DateTime, Utc};
44
use hashbrown::HashMap;
55
use std::sync::{Arc, Mutex};
@@ -58,7 +58,7 @@ pub trait Connection: Send + Sync {
5858
profile: Profile,
5959
scenario: Scenario,
6060
query: &str,
61-
qd: QueryDatum,
61+
qd: crate::QueryDatum,
6262
);
6363
async fn record_error(&self, artifact: ArtifactIdNumber, krate: &str, error: &str);
6464
async fn record_rustc_crate(
@@ -92,18 +92,6 @@ pub trait Connection: Send + Sync {
9292
pstat_series_row_ids: &[u32],
9393
artifact_row_id: &[Option<ArtifactIdNumber>],
9494
) -> Vec<Vec<Option<f64>>>;
95-
async fn get_self_profile(
96-
&self,
97-
artifact_row_id: ArtifactIdNumber,
98-
crate_: &str,
99-
profile: &str,
100-
cache: &str,
101-
) -> HashMap<crate::QueryLabel, QueryDatum>;
102-
async fn get_self_profile_query(
103-
&self,
104-
series: u32,
105-
artifact_row_id: ArtifactIdNumber,
106-
) -> Option<QueryDatum>;
10795
async fn get_error(&self, artifact_row_id: ArtifactIdNumber) -> HashMap<String, String>;
10896

10997
async fn queue_pr(

Diff for: database/src/pool/postgres.rs

-108
Original file line numberDiff line numberDiff line change
@@ -276,8 +276,6 @@ pub struct CachedStatements {
276276
get_rustc_compilation_by_crate: Statement,
277277
insert_pstat: Statement,
278278
insert_rustc: Statement,
279-
get_self_profile_query: Statement,
280-
get_self_profile: Statement,
281279
insert_self_profile_query: Statement,
282280
select_self_query_series: Statement,
283281
insert_self_query_series: Statement,
@@ -393,27 +391,6 @@ impl PostgresConnection {
393391
.prepare("insert into rustc_compilation (aid, cid, crate, duration) VALUES ($1, $2, $3, $4)")
394392
.await
395393
.unwrap(),
396-
get_self_profile_query: conn
397-
.prepare(
398-
"select
399-
self_time, blocked_time, incremental_load_time, number_of_cache_hits, invocation_count
400-
from self_profile_query
401-
where series = $1 and aid = $2 order by self_time asc;
402-
",
403-
)
404-
.await
405-
.unwrap(),
406-
get_self_profile: conn.prepare("
407-
select
408-
query, self_time, blocked_time, incremental_load_time, number_of_cache_hits, invocation_count
409-
from self_profile_query_series
410-
join self_profile_query on self_profile_query_series.id = self_profile_query.series
411-
where
412-
crate = $1
413-
and profile = $2
414-
and cache = $3
415-
and aid = $4
416-
").await.unwrap(),
417394
insert_self_profile_query: conn
418395
.prepare(
419396
"insert into self_profile_query(
@@ -577,33 +554,6 @@ where
577554
)
578555
})
579556
.collect(),
580-
queries: self
581-
.conn()
582-
.query(
583-
"select id, crate, profile, cache, query from self_profile_query_series;",
584-
&[],
585-
)
586-
.await
587-
.unwrap()
588-
.into_iter()
589-
.map(|row| {
590-
(
591-
row.get::<_, i32>(0) as u32,
592-
(
593-
Benchmark::from(row.get::<_, String>(1).as_str()),
594-
match row.get::<_, String>(2).as_str() {
595-
"check" => Profile::Check,
596-
"opt" => Profile::Opt,
597-
"debug" => Profile::Debug,
598-
"doc" => Profile::Doc,
599-
o => unreachable!("{}: not a profile", o),
600-
},
601-
row.get::<_, String>(3).as_str().parse().unwrap(),
602-
row.get::<_, String>(4).as_str().into(),
603-
),
604-
)
605-
})
606-
.collect(),
607557
}
608558
}
609559
async fn get_benchmarks(&self) -> Vec<BenchmarkData> {
@@ -645,64 +595,6 @@ where
645595
.map(|row| row.get::<_, Vec<Option<f64>>>(0))
646596
.collect()
647597
}
648-
async fn get_self_profile_query(
649-
&self,
650-
pstat_series_row_id: u32,
651-
artifact_row_id: crate::ArtifactIdNumber,
652-
) -> Option<crate::QueryDatum> {
653-
let row = self
654-
.conn()
655-
.query_opt(
656-
&self.statements().get_self_profile_query,
657-
&[&(pstat_series_row_id as i32), &(artifact_row_id.0 as i32)],
658-
)
659-
.await
660-
.unwrap()?;
661-
let self_time: i64 = row.get(0);
662-
let blocked_time: i64 = row.get(1);
663-
let incremental_load_time: i64 = row.get(2);
664-
Some(crate::QueryDatum {
665-
self_time: Duration::from_nanos(self_time as u64),
666-
blocked_time: Duration::from_nanos(blocked_time as u64),
667-
incremental_load_time: Duration::from_nanos(incremental_load_time as u64),
668-
number_of_cache_hits: row.get::<_, i32>(3) as u32,
669-
invocation_count: row.get::<_, i32>(4) as u32,
670-
})
671-
}
672-
async fn get_self_profile(
673-
&self,
674-
artifact_row_id: ArtifactIdNumber,
675-
crate_: &str,
676-
profile: &str,
677-
scenario: &str,
678-
) -> HashMap<crate::QueryLabel, crate::QueryDatum> {
679-
let rows = self
680-
.conn()
681-
.query(
682-
&self.statements().get_self_profile,
683-
&[&crate_, &profile, &scenario, &(artifact_row_id.0 as i32)],
684-
)
685-
.await
686-
.unwrap();
687-
688-
rows.into_iter()
689-
.map(|r| {
690-
let self_time: i64 = r.get(1);
691-
let blocked_time: i64 = r.get(2);
692-
let incremental_load_time: i64 = r.get(3);
693-
(
694-
r.get::<_, &str>(0).into(),
695-
crate::QueryDatum {
696-
self_time: Duration::from_nanos(self_time as u64),
697-
blocked_time: Duration::from_nanos(blocked_time as u64),
698-
incremental_load_time: Duration::from_nanos(incremental_load_time as u64),
699-
number_of_cache_hits: r.get::<_, i32>(4) as u32,
700-
invocation_count: r.get::<_, i32>(5) as u32,
701-
},
702-
)
703-
})
704-
.collect()
705-
}
706598
async fn get_error(&self, artifact_row_id: crate::ArtifactIdNumber) -> HashMap<String, String> {
707599
let rows = self
708600
.conn()

0 commit comments

Comments
 (0)