Refactor concurrency handling to introduce STALE_HEARTBEAT_THRESHOLD_MS constant and utilize SweepstoreWorkerTicketSnapshot for improved state management

This commit is contained in:
ImBenji
2025-11-23 20:27:08 +00:00
parent 580f07c483
commit f8e8636677
4 changed files with 98 additions and 85 deletions

View File

@@ -60,21 +60,25 @@ Future<void> main() async {
Sweepstore store = Sweepstore(filePath);
store.initialise(
concurrentWorkers: 18
concurrentWorkers: 32
);
initialiseMasterListener(file.openSync(mode: FileMode.append));
print(binaryDump(file.readAsBytesSync()));
int iteration = 100;
int iteration = 0;
for (int j = 0; j < iteration; j++) {
print("Concurrent Workers: ${store._concurrencyHeader.numberOfWorkers}");
print("Stale Ticket Threshold: ${STALE_HEARTBEAT_THRESHOLD_MS}ms");
while (true) {
int concurrencyTest = 128;
final receivePort = ReceivePort();
int completedJobs = 0;
final stopwatch = Stopwatch()..start();
print('\x1B[95mStarting iteration #$iteration with $concurrencyTest concurrent jobs...\x1B[0m');
for (int i = 0; i < concurrencyTest; i++) {
await Isolate.spawn((message) {
final index = message['index'] as int;
@@ -101,7 +105,9 @@ Future<void> main() async {
print('\x1B[95mAll jobs completed!\x1B[0m');
print('\x1B[95mTime taken: ${stopwatch.elapsedMilliseconds}ms (${stopwatch.elapsed.inSeconds}s)\x1B[0m');
print(" ");
// sleep(Duration(seconds: 2));
iteration++;
}
}