diff --git a/optuna_dashboard/_app.py b/optuna_dashboard/_app.py index a72c60c2..48193688 100644 --- a/optuna_dashboard/_app.py +++ b/optuna_dashboard/_app.py @@ -158,9 +158,18 @@ def create_new_study( return study_id -def get_trials(storage: BaseStorage, study_id: int, ttl_seconds: int = 10) -> list[FrozenTrial]: +def get_trials(storage: BaseStorage, study_id: int) -> list[FrozenTrial]: with trials_cache_lock: trials = trials_cache.get(study_id, None) + + # Not a big fan of the heuristic, but I can't think of anything better. + if trials is None or len(trials) < 100: + ttl_seconds = 2 + elif len(trials) < 500: + ttl_seconds = 5 + else: + ttl_seconds = 10 + last_fetched_at = trials_last_fetched_at.get(study_id, None) if ( trials is not None diff --git a/optuna_dashboard/ts/components/StudyDetailBeta.tsx b/optuna_dashboard/ts/components/StudyDetailBeta.tsx index 400fa5cd..6a7ab839 100644 --- a/optuna_dashboard/ts/components/StudyDetailBeta.tsx +++ b/optuna_dashboard/ts/components/StudyDetailBeta.tsx @@ -60,12 +60,23 @@ export const StudyDetailBeta: FC<{ }, []) useEffect(() => { - if (reloadInterval < 0 || page === "trialTable") { + if (reloadInterval < 0) { return } + const nTrials = studyDetail ? studyDetail.trials.length : 0 + let interval = reloadInterval * 1000 + + // For Human-in-the-loop Optimization, the interval is set to 2 seconds + // when the number of trials is small and the page is "trialList". + if (page === "trialList" && nTrials < 100) { + interval = 2000 + } else if (page === "trialList" && nTrials < 500) { + interval = 5000 + } + const intervalId = setInterval(function () { action.updateStudyDetail(studyId) - }, reloadInterval * 1000) + }, interval) return () => clearInterval(intervalId) }, [reloadInterval, studyDetail, page])