mononoke_api: don't hit all bookmarks in all repos at the same time

Summary:
Querying bookmarks in all repos at the exact same time results in us making a
bunch of concurrent queries to MySQL, which in turn results in MyRouter
allocating a bunch of connections.

This is for reporting the age of bookmarks: that stuff can wait... It doesn't
need to be super fast. Let's make it run on repos one at a time to avoid
allocating dozens of connections every 10 seconds (which is more often than
MyRouter seems to close them).

Reviewed By: ikostia

Differential Revision: D25057432

fbshipit-source-id: 8b65ef65752fc9762a26d835ac80f61573003dd7
This commit is contained in:
Thomas Orozco 2020-11-18 09:47:17 -08:00 committed by Facebook GitHub Bot
parent 0cc4d4f100
commit 31b9c58a0f
2 changed files with 11 additions and 14 deletions

View File

@ -19,7 +19,6 @@ use cached_config::ConfigStore;
use cloned::cloned;
use fbinit::FacebookInit;
use futures::future;
use futures::future::try_join_all;
use slog::{debug, info, o, Logger};
use sql_ext::facebook::MysqlOptions;
@ -163,12 +162,11 @@ impl Mononoke {
/// Report configured monitoring stats
pub async fn report_monitoring_stats(&self, ctx: &CoreContext) -> Result<(), MononokeError> {
let reporting_futs: Vec<_> = self
.repos
.iter()
.map(|(_, repo)| async move { repo.report_monitoring_stats(ctx).await })
.collect();
try_join_all(reporting_futs).await.map(|_| ())
for (_, repo) in self.repos.iter() {
repo.report_monitoring_stats(ctx).await?;
}
Ok(())
}
}

View File

@ -29,7 +29,6 @@ use derived_data::BonsaiDerived;
use fbinit::FacebookInit;
use filestore::{Alias, FetchKey};
use futures::compat::{Future01CompatExt, Stream01CompatExt};
use futures::future::try_join_all;
use futures::stream::{Stream, StreamExt, TryStreamExt};
use futures::try_join;
use hook_manager_factory::make_hook_manager;
@ -392,17 +391,17 @@ impl Repo {
pub async fn report_monitoring_stats(&self, ctx: &CoreContext) -> Result<(), MononokeError> {
match self.config.source_control_service_monitoring.as_ref() {
None => Ok(()),
None => {}
Some(monitoring_config) => {
let reporting_futs = monitoring_config
.bookmarks_to_report_age
.iter()
.map(move |bookmark| self.report_bookmark_age_difference(ctx, &bookmark));
try_join_all(reporting_futs).await.map(|_| ())
for bookmark in monitoring_config.bookmarks_to_report_age.iter() {
self.report_bookmark_age_difference(ctx, &bookmark).await?;
}
}
}
Ok(())
}
fn report_bookmark_missing_from_cache(&self, ctx: &CoreContext, bookmark: &BookmarkName) {
error!(
ctx.logger(),