mirror of
https://github.com/MindWorkAI/AI-Studio.git
synced 2026-10-18 19:38:00 +00:00
Fixed an incomplete plugin start with extensive enterprise configurations (#1033)
This commit is contained in:
1 parent
bdf828fa4f
commit
56215aa6dd
16 files changed
+493
-70
No files matched your search
@@ -1,4 +1,6 @@
|
||||
using System.Diagnostics;
|
||||
using System.Linq.Expressions;
|
||||
using System.Text;
|
||||
using System.Text.Json;
|
||||
|
||||
using AIStudio.Provider;
|
||||
@@ -30,6 +32,16 @@ public sealed class SettingsManager
|
||||
Converters = { new TolerantEnumConverter() },
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// From this duration on, storing the settings is reported as slow.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// The settings file is a few hundred kilobytes at most, so storing it usually takes some
|
||||
/// milliseconds. Far beyond that, something is blocking: on one machine, every store took 18
|
||||
/// seconds, and each one held up the start of AI Studio.
|
||||
/// </remarks>
|
||||
private static readonly TimeSpan SLOW_STORE_THRESHOLD = TimeSpan.FromSeconds(1);
|
||||
|
||||
private readonly ILogger<SettingsManager> logger;
|
||||
private readonly RustService rustService;
|
||||
|
||||
@@ -337,10 +349,24 @@ public sealed class SettingsManager
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
// Serializing and writing are measured on their own, because a slow store has two
|
||||
// different causes: a property which asks the file system or the network while it is
|
||||
// serialized, or a file system which is slow to write, e.g., because of a virus scanner
|
||||
// or a synchronized profile folder. Only the two durations tell them apart:
|
||||
//
|
||||
var serializingStartedAt = Stopwatch.GetTimestamp();
|
||||
var settingsJson = JsonSerializer.Serialize(this.ConfigurationData, JSON_OPTIONS);
|
||||
var serializingDuration = Stopwatch.GetElapsedTime(serializingStartedAt);
|
||||
|
||||
var writingStartedAt = Stopwatch.GetTimestamp();
|
||||
var settingsPath = Path.Combine(ConfigDirectory!, SETTINGS_FILENAME);
|
||||
await this.StoreSerializedSettings(settingsJson, settingsPath);
|
||||
await this.StoreSerializedVersionBackup(this.ConfigurationData.Version, settingsJson);
|
||||
var writingDuration = Stopwatch.GetElapsedTime(writingStartedAt);
|
||||
|
||||
if (serializingDuration + writingDuration >= SLOW_STORE_THRESHOLD)
|
||||
this.logger.LogWarning($"Storing the settings took {(serializingDuration + writingDuration).TotalMilliseconds:F0} ms, which is unusually long: serializing took {serializingDuration.TotalMilliseconds:F0} ms, writing took {writingDuration.TotalMilliseconds:F0} ms. The settings are {Encoding.UTF8.GetByteCount(settingsJson) / 1024} KB. A slow serialization points to a setting which reaches out to the file system or the network while it is serialized; slow writing points to the file system itself, e.g., a virus scanner or a synchronized profile folder.");
|
||||
}
|
||||
finally
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user