Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement preemptive scheduling for Dart code #47014

Open
aam opened this issue Aug 26, 2021 · 0 comments
Open

Implement preemptive scheduling for Dart code #47014

aam opened this issue Aug 26, 2021 · 0 comments
Labels
area-vm Use area-vm for VM related issues, including code coverage, FFI, and the AOT and JIT backends.

Comments

@aam
Copy link
Contributor

aam commented Aug 26, 2021

With --enable-isolate-groups, when application creates more isolates than VM tlab allows(more than thread_pool capacity) contention between isolates increases:

import 'dart:async';
import 'dart:isolate';

longWork(List args) {
  DateTime startDateTime = args[0];
  SendPort sendPort = args[1];
  int i = 0;
  while(i < 10*1024*1024) {
   try {
     throw 1;
   } catch(e) {
     i++;
   }
  }
  sendPort.send(DateTime.now().difference(startDateTime).inMilliseconds);
}

quickUrgentWork(List args) {
  DateTime startDateTime = args[0];
  SendPort sendPort = args[1];
  sendPort.send(DateTime.now().difference(startDateTime).inMilliseconds);
}

main() async {
  final n = 19;
  final receivePorts = <ReceivePort>[];
  final isolates = <Future<Isolate>>[];
  for (int i = 0; i < n - 1; i++) {
    receivePorts.add(ReceivePort());
    Isolate.spawn(longWork, [DateTime.now(), receivePorts[i].sendPort]);
  }
  receivePorts.add(ReceivePort());
  Isolate.spawn(quickUrgentWork, [DateTime.now(), receivePorts[n-1].sendPort]);
  final msUrgentWorkResponse = await receivePorts[n-1].first;
  print("$msUrgentWorkResponse ms");
  for (int i = 0; i < n; i++) {
    receivePorts[i].close();
  }
}
─➤  $DH/out/ReleaseX64/dart many_isolates.dart
160ms
╰─➤  $DH/out/ReleaseX64/dart --enable-isolate-groups many_isolates.dart
19045ms
╰─➤  $DH/out/ReleaseX64/dart --disable-dart-dev --verbose 2&>1 | grep new_gen_semi_max
new_gen_semi_max_size: 16 (Max size of new gen semi space in MB)
@aam aam added the area-vm Use area-vm for VM related issues, including code coverage, FFI, and the AOT and JIT backends. label Aug 26, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-vm Use area-vm for VM related issues, including code coverage, FFI, and the AOT and JIT backends.
Projects
None yet
Development

No branches or pull requests

1 participant