Refactor concurrency handling and file operations for improved performance and thread safety

This commit is contained in:
ImBenji
2025-12-04 20:15:44 +00:00
parent fa50810212
commit 55c69aebc2
10 changed files with 214 additions and 189 deletions

View File

@@ -67,22 +67,25 @@ Future<void> main() async {
print(binaryDump(file.readAsBytesSync()));
int iteration = 0;
int maxIterations = 16;
print("Concurrent Workers: ${store._concurrencyHeader.numberOfWorkers}");
print("Stale Ticket Threshold: ${STALE_HEARTBEAT_THRESHOLD_MS}ms");
int concurrencyTest = 1;
while (true) {
int concurrencyTest = 256;
final receivePort = ReceivePort();
int completedJobs = 0;
if (iteration > 0) {
if (iteration > maxIterations) {
break;
}
final stopwatch = Stopwatch()..start();
print('\x1B[95mStarting iteration #$iteration with $concurrencyTest concurrent jobs...\x1B[0m');
// 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;
@@ -107,11 +110,10 @@ Future<void> main() async {
stopwatch.stop();
print('\x1B[95mAll jobs completed!\x1B[0m');
print('\x1B[95mTime taken: ${stopwatch.elapsedMilliseconds}ms (${stopwatch.elapsed.inSeconds}s)\x1B[0m');
print(" ");
print("[$iteration/$maxIterations] Completed $concurrencyTest operation in ${stopwatch.elapsedMilliseconds} ms");
// sleep(Duration(seconds: 2));
iteration++;
concurrencyTest *= 2;
}
}