import { Alert, AlertDescription } from "@/components/ui/alert"; import { Button } from "@/components/ui/button"; import { Input } from "@/components/ui/input"; import { getErrorMessage, useGetCoreConfigQuery, useUpdateCoreConfigMutation } from "@/lib/store"; import { CoreConfig, DefaultCoreConfig } from "@/lib/types/config"; import { RbacOperation, RbacResource, useRbac } from "@enterprise/lib"; import { AlertTriangle } from "lucide-react"; import { useCallback, useEffect, useMemo, useState } from "react"; import { toast } from "sonner"; export default function PerformanceTuningView() { const hasSettingsUpdateAccess = useRbac(RbacResource.Settings, RbacOperation.Update); const { data: bifrostConfig } = useGetCoreConfigQuery({ fromDB: true }); const config = bifrostConfig?.client_config; const [updateCoreConfig, { isLoading }] = useUpdateCoreConfigMutation(); const [localConfig, setLocalConfig] = useState(DefaultCoreConfig); const [needsRestart, setNeedsRestart] = useState(false); const [localValues, setLocalValues] = useState<{ initial_pool_size: string; max_request_body_size_mb: string; }>({ initial_pool_size: "1000", max_request_body_size_mb: "100", }); useEffect(() => { if (bifrostConfig && config) { setLocalConfig(config); setLocalValues({ initial_pool_size: config?.initial_pool_size?.toString() || "1000", max_request_body_size_mb: config?.max_request_body_size_mb?.toString() || "100", }); } }, [config, bifrostConfig]); const hasChanges = useMemo(() => { if (!config) return false; return ( localConfig.initial_pool_size !== config.initial_pool_size || localConfig.max_request_body_size_mb !== config.max_request_body_size_mb ); }, [config, localConfig]); const handlePoolSizeChange = useCallback((value: string) => { setLocalValues((prev) => ({ ...prev, initial_pool_size: value })); const numValue = Number.parseInt(value); if (!isNaN(numValue) && numValue > 0) { setLocalConfig((prev) => ({ ...prev, initial_pool_size: numValue })); } setNeedsRestart(true); }, []); const handleMaxRequestBodySizeMBChange = useCallback((value: string) => { setLocalValues((prev) => ({ ...prev, max_request_body_size_mb: value })); const numValue = Number.parseInt(value); if (!isNaN(numValue) && numValue > 0) { setLocalConfig((prev) => ({ ...prev, max_request_body_size_mb: numValue })); } setNeedsRestart(true); }, []); const handleSave = useCallback(async () => { try { const poolSize = Number.parseInt(localValues.initial_pool_size); const maxBodySize = Number.parseInt(localValues.max_request_body_size_mb); if (isNaN(poolSize) || poolSize <= 0) { toast.error("Initial pool size must be a positive number."); return; } if (isNaN(maxBodySize) || maxBodySize <= 0) { toast.error("Max request body size must be a positive number."); return; } if (!bifrostConfig) { toast.error("Configuration not loaded. Please refresh and try again."); return; } await updateCoreConfig({ ...bifrostConfig, client_config: localConfig }).unwrap(); toast.success("Performance settings updated successfully."); } catch (error) { toast.error(getErrorMessage(error)); } }, [bifrostConfig, localConfig, localValues, updateCoreConfig]); return (

Performance Tuning

Configure performance-related settings.

These settings require a Bifrost service restart to take effect. Current connections will continue with existing settings until restart.
{/* Initial Pool Size */}

The initial connection pool size.

handlePoolSizeChange(e.target.value)} min="1" />
{needsRestart && }
{/* Max Request Body Size */}

Maximum size of request body in megabytes.

handleMaxRequestBodySizeMBChange(e.target.value)} min="1" />
{needsRestart && }
); } const RestartWarning = () => { return
Need to restart Bifrost to apply changes.
; };